forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdin.js
More file actions
64 lines (50 loc) · 1.4 KB
/
Copy pathstdin.js
File metadata and controls
64 lines (50 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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();
});