You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
7 years ago
|
var test = require('tap').test;
|
||
|
var spawn = require('child_process').spawn;
|
||
|
var concat = require('concat-stream');
|
||
|
var path = require('path');
|
||
|
var vm = require('vm');
|
||
|
|
||
|
test('stdin', function (t) {
|
||
|
t.plan(2);
|
||
|
|
||
|
var cwd = process.cwd();
|
||
|
process.chdir(__dirname);
|
||
|
|
||
|
var ps = spawn(process.execPath, [
|
||
|
path.resolve(__dirname, '../bin/cmd.js'),
|
||
|
'-'
|
||
|
]);
|
||
|
|
||
|
ps.stdout.pipe(concat(function (body) {
|
||
|
var c = { console: {
|
||
|
log: function (msg) {
|
||
|
t.equal(msg, 'hello');
|
||
|
}
|
||
|
} };
|
||
|
vm.runInNewContext(body, c);
|
||
|
}));
|
||
|
ps.stderr.pipe(process.stderr);
|
||
|
|
||
|
ps.on('exit', function (code) {
|
||
|
t.equal(code, 0);
|
||
|
});
|
||
|
|
||
|
ps.stdin.write("console.log('hello')");
|
||
|
ps.stdin.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('stdin !isTTY', function (t) {
|
||
|
t.plan(2);
|
||
|
|
||
|
var cwd = process.cwd();
|
||
|
process.chdir(__dirname);
|
||
|
|
||
|
var ps = spawn(process.execPath, [
|
||
|
path.resolve(__dirname, '../bin/cmd.js')
|
||
|
]);
|
||
|
|
||
|
ps.stdout.pipe(concat(function (body) {
|
||
|
var c = { console: {
|
||
|
log: function (msg) {
|
||
|
t.equal(msg, 'hello');
|
||
|
}
|
||
|
} };
|
||
|
vm.runInNewContext(body, c);
|
||
|
}));
|
||
|
ps.stderr.pipe(process.stderr);
|
||
|
|
||
|
ps.on('exit', function (code) {
|
||
|
t.equal(code, 0);
|
||
|
});
|
||
|
|
||
|
ps.stdin.write("console.log('hello')");
|
||
|
ps.stdin.end();
|
||
|
|
||
|
});
|