Name: js-handler/node_modules/optimist/test/_.js 
1:
var spawn = require('child_process').spawn;
2:
var test = require('tap').test;
3:
 
4:
test('dotSlashEmpty', testCmd('./bin.js', []));
5:
 
6:
test('dotSlashArgs', testCmd('./bin.js', [ 'a', 'b', 'c' ]));
7:
 
8:
test('nodeEmpty', testCmd('node bin.js', []));
9:
 
10:
test('nodeArgs', testCmd('node bin.js', [ 'x', 'y', 'z' ]));
11:
 
12:
test('whichNodeEmpty', function (t) {
13:
    var which = spawn('which', ['node']);
14:
    
15:
    which.stdout.on('data', function (buf) {
16:
        t.test(
17:
            testCmd(buf.toString().trim() + ' bin.js', [])
18:
        );
19:
        t.end();
20:
    });
21:
    
22:
    which.stderr.on('data', function (err) {
23:
        assert.error(err);
24:
        t.end();
25:
    });
26:
});
27:
 
28:
test('whichNodeArgs', function (t) {
29:
    var which = spawn('which', ['node']);
30:
 
31:
    which.stdout.on('data', function (buf) {
32:
        t.test(
33:
            testCmd(buf.toString().trim() + ' bin.js', [ 'q', 'r' ])
34:
        );
35:
        t.end();
36:
    });
37:
    
38:
    which.stderr.on('data', function (err) {
39:
        t.error(err);
40:
        t.end();
41:
    });
42:
});
43:
 
44:
function testCmd (cmd, args) {
45:
 
46:
    return function (t) {
47:
        var to = setTimeout(function () {
48:
            assert.fail('Never got stdout data.')
49:
        }, 5000);
50:
        
51:
        var oldDir = process.cwd();
52:
        process.chdir(__dirname + '/_');
53:
        
54:
        var cmds = cmd.split(' ');
55:
        
56:
        var bin = spawn(cmds[0], cmds.slice(1).concat(args.map(String)));
57:
        process.chdir(oldDir);
58:
        
59:
        bin.stderr.on('data', function (err) {
60:
            t.error(err);
61:
            t.end();
62:
        });
63:
        
64:
        bin.stdout.on('data', function (buf) {
65:
            clearTimeout(to);
66:
            var _ = JSON.parse(buf.toString());
67:
            t.same(_.map(String), args.map(String));
68:
            t.end();
69:
        });
70:
    };
71:
}