
/**
 * Module dependencies.
 */

var path = require('path');
var spawn = require('child_process').spawn;

// node executable
var node = process.execPath || process.argv[0];
var gnode = path.resolve(__dirname, '..', 'bin', 'gnode');
var mocha = path.resolve(__dirname, '..', 'node_modules', '.bin', 'mocha');
var mochaOpts = [ '--reporter', 'spec' ];

run([
  [ mocha, path.resolve(__dirname, 'cli.js') ]
]);

function run (tests) {
  if (0 == tests.length) return;
  var argv = tests.shift();
  if (argv.indexOf(mocha) != -1) {
    // running mocha, append "mochaOpts"
    argv.push.apply(argv, mochaOpts);
  }
  var opts = {
    customFds: [ 0, 1, 2 ],
    stdio: 'inherit'
  };
  var child = spawn(node, argv, opts);
  child.on('exit', function (code) {
    if (0 == code) {
      run(tests);
    } else {
      process.exit(code);
    }
  });
}


/**
 * Module dependencies.
 */

var path = require('path');
var spawn = require('child_process').spawn;

// node executable
var node = process.execPath || process.argv[0];
var mocha = path.resolve(__dirname, '..', 'node_modules', 'mocha', 'bin', 'mocha');
var mochaOpts = [ '--reporter', 'spec' ];

run([
  [ mocha, path.resolve(__dirname, 'cli.js') ]
]);

function run (tests) {
  if (0 == tests.length) return;
  var argv = tests.shift();
  if (argv.indexOf(mocha) != -1) {
    // running mocha, append "mochaOpts"
    argv.push.apply(argv, mochaOpts);
  }
  var opts = {
    customFds: [ 0, 1, 2 ],
    stdio: 'inherit'
  };
  var child = spawn(node, argv, opts);
  child.on('exit', function (code) {
    if (0 == code) {
      run(tests);
    } else {
      process.exit(code);
    }
  });
}

Fix `npm test` failing to run
Fix `npm test` failing to run

Trying to run `npm test` fails because the mocha path was set to the
mocha shell script instead of the mocha init script (it tried to spawn
node with a shell script).
This commit fixes the issue and the tests run as expected.
