UNPKG

803 BJavaScriptView Raw
1var test = require('tap').test;
2var spawn = require('child_process').spawn;
3var concat = require('concat-stream');
4var path = require('path');
5var vm = require('vm');
6
7test('stdin', function (t) {
8 t.plan(2);
9
10 var cwd = process.cwd();
11 process.chdir(__dirname);
12
13 var ps = spawn(process.execPath, [
14 path.resolve(__dirname, '../bin/cmd.js'),
15 '-'
16 ]);
17
18 ps.stdout.pipe(concat(function (body) {
19 var c = { console: {
20 log: function (msg) {
21 t.equal(msg, 'hello');
22 }
23 } };
24 vm.runInNewContext(body, c);
25 }));
26 ps.stderr.pipe(process.stderr);
27
28 ps.on('exit', function (code) {
29 t.equal(code, 0);
30 });
31
32 ps.stdin.write("console.log('hello')");
33 ps.stdin.end();
34
35});