-
Notifications
You must be signed in to change notification settings - Fork 0
/
_.js
66 lines (50 loc) · 1.56 KB
/
_.js
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
65
66
var spawn = require('child_process').spawn;
var assert = require('assert');
exports.dotSlashEmpty = function () {
testCmd('./bin.js', []);
};
exports.dotSlashArgs = function () {
testCmd('./bin.js', [ 'a', 'b', 'c' ]);
};
exports.nodeEmpty = function () {
testCmd('node bin.js', []);
};
exports.nodeArgs = function () {
testCmd('node bin.js', [ 'x', 'y', 'z' ]);
};
exports.whichNodeEmpty = function () {
var which = spawn('which', ['node']);
which.stdout.on('data', function (buf) {
testCmd(buf.toString().trim() + ' bin.js', []);
});
which.stderr.on('data', function (err) {
assert.fail(err.toString());
});
};
exports.whichNodeArgs = function () {
var which = spawn('which', ['node']);
which.stdout.on('data', function (buf) {
testCmd(buf.toString().trim() + ' bin.js', [ 'q', 'r' ]);
});
which.stderr.on('data', function (err) {
assert.fail(err.toString());
});
};
function testCmd (cmd, args) {
var to = setTimeout(function () {
assert.fail('Never got stdout data.')
}, 5000);
var oldDir = process.cwd();
process.chdir(__dirname + '/_');
var cmds = cmd.split(' ');
var bin = spawn(cmds[0], cmds.slice(1).concat(args.map(String)));
process.chdir(oldDir);
bin.stderr.on('data', function (err) {
assert.fail(err.toString());
});
bin.stdout.on('data', function (buf) {
clearTimeout(to);
var _ = JSON.parse(buf.toString());
assert.eql(_.map(String), args.map(String));
});
}