From 1db715d6857de3ac6ab5699d72dc13500d07c3d3 Mon Sep 17 00:00:00 2001 From: James Talmage Date: Fri, 6 May 2016 21:40:38 -0400 Subject: [PATCH 1/3] temp fix for npm link --- lib/fork.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/fork.js b/lib/fork.js index baa972c4e..5575311c1 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -31,9 +31,29 @@ 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, + var execArgv = process.execArgv; + var cwd = path.dirname(file); + + // This is straight out of node 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 args = execArgv.concat([ + '-e', + 'require("ava/lib/test-worker")', + path.join(__dirname, 'test-worker.js'), + JSON.stringify(opts) + ]); + + var ps = childProcess.spawn(process.execPath, args, { + cwd: cwd, + stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: env }); From 7ea196a7b17ed9f8c50592da104baeacef1f3be7 Mon Sep 17 00:00:00 2001 From: James Talmage Date: Fri, 6 May 2016 22:27:29 -0400 Subject: [PATCH 2/3] Make it work for AVA's test suite. We can't `require("ava/...")` from within AVA itself. --- lib/fork.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fork.js b/lib/fork.js index 5575311c1..8f00e8ed1 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -44,10 +44,12 @@ module.exports = function (file, opts) { } } + var testWorkerPath = path.join(__dirname, 'test-worker.js'); + var args = execArgv.concat([ '-e', - 'require("ava/lib/test-worker")', - path.join(__dirname, 'test-worker.js'), + 'require(' + JSON.stringify(testWorkerPath) + ')', + testWorkerPath, JSON.stringify(opts) ]); From 8ffb4c8339c264c4b61975af97fa080420c23127 Mon Sep 17 00:00:00 2001 From: James Talmage Date: Fri, 6 May 2016 22:34:04 -0400 Subject: [PATCH 3/3] Add some better comments that discuss when the change can be reverted. --- lib/fork.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/fork.js b/lib/fork.js index 8f00e8ed1..e07aead17 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -31,10 +31,14 @@ module.exports = function (file, opts) { } : false }, opts); + // 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 is straight out of node child_process + // 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) {