react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / node_modules / uglify-js / node_modules / optimist / test / _.js
80742 viewsvar spawn = require('child_process').spawn;1var test = require('tap').test;23test('dotSlashEmpty', testCmd('./bin.js', []));45test('dotSlashArgs', testCmd('./bin.js', [ 'a', 'b', 'c' ]));67test('nodeEmpty', testCmd('node bin.js', []));89test('nodeArgs', testCmd('node bin.js', [ 'x', 'y', 'z' ]));1011test('whichNodeEmpty', function (t) {12var which = spawn('which', ['node']);1314which.stdout.on('data', function (buf) {15t.test(16testCmd(buf.toString().trim() + ' bin.js', [])17);18t.end();19});2021which.stderr.on('data', function (err) {22assert.error(err);23t.end();24});25});2627test('whichNodeArgs', function (t) {28var which = spawn('which', ['node']);2930which.stdout.on('data', function (buf) {31t.test(32testCmd(buf.toString().trim() + ' bin.js', [ 'q', 'r' ])33);34t.end();35});3637which.stderr.on('data', function (err) {38t.error(err);39t.end();40});41});4243function testCmd (cmd, args) {4445return function (t) {46var to = setTimeout(function () {47assert.fail('Never got stdout data.')48}, 5000);4950var oldDir = process.cwd();51process.chdir(__dirname + '/_');5253var cmds = cmd.split(' ');5455var bin = spawn(cmds[0], cmds.slice(1).concat(args.map(String)));56process.chdir(oldDir);5758bin.stderr.on('data', function (err) {59t.error(err);60t.end();61});6263bin.stdout.on('data', function (buf) {64clearTimeout(to);65var _ = JSON.parse(buf.toString());66t.same(_.map(String), args.map(String));67t.end();68});69};70}717273