node/test/simple/test-pipe-head.js

25 lines
535 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
2010-12-05 06:45:52 +08:00
2010-12-05 08:11:57 +08:00
var exec = require('child_process').exec;
var join = require('path').join;
2010-12-05 08:11:57 +08:00
var nodePath = process.argv[0];
var script = join(common.fixturesDir, 'print-10-lines.js');
2010-12-05 08:11:57 +08:00
var cmd = nodePath + ' ' + script + ' | head -2';
2010-12-05 08:11:57 +08:00
var finished = false;
2010-12-05 06:45:52 +08:00
exec(cmd, function(err, stdout, stderr) {
if (err) throw err;
2010-12-05 08:11:57 +08:00
var lines = stdout.split('\n');
assert.equal(3, lines.length);
finished = true;
});
2010-12-05 06:45:52 +08:00
process.addListener('exit', function() {
assert.ok(finished);
});