diff --git a/lib/fork.js b/lib/fork.js index baa972c4e..e07aead17 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -31,9 +31,35 @@ module.exports = function (file, opts) { } : false }, opts); - var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { - cwd: path.dirname(file), - silent: true, + // Workaround for breakage caused by https://github.com/nodejs/node/pull/5950 + // Those changes will be reverted in https://github.com/nodejs/node/pull/6537 + + // Revert #815 when these changes land in Node.js + var execArgv = process.execArgv; + var cwd = path.dirname(file); + + // This whole if statement is copied straight out of Nodes `child_process` + if (process._eval != null) { // eslint-disable-line + var index = execArgv.lastIndexOf(process._eval); + if (index > 0) { + // Remove the -e switch to avoid fork bombing ourselves. + execArgv = execArgv.slice(); + execArgv.splice(index - 1, 2); + } + } + + var testWorkerPath = path.join(__dirname, 'test-worker.js'); + + var args = execArgv.concat([ + '-e', + 'require(' + JSON.stringify(testWorkerPath) + ')', + testWorkerPath, + JSON.stringify(opts) + ]); + + var ps = childProcess.spawn(process.execPath, args, { + cwd: cwd, + stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: env });