diff --git a/lib/fork.js b/lib/fork.js index e847c0d2f..991385f3c 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -12,8 +12,7 @@ if (fs.realpathSync(__filename) !== __filename) { // In case the test file imports a different AVA install, // the presence of this variable allows it to require this one instead const AVA_PATH = path.resolve(__dirname, '..'); - -const workerPath = require.resolve('./worker/subprocess'); +const WORKER_PATH = require.resolve('./worker/subprocess'); module.exports = (file, options, execArgv = process.execArgv) => { let finished = false; @@ -26,12 +25,12 @@ module.exports = (file, options, execArgv = process.execArgv) => { }; options = { - file, baseDir: process.cwd(), + file, ...options }; - const subprocess = childProcess.fork(workerPath, options.workerArgv, { + const subprocess = childProcess.fork(WORKER_PATH, options.workerArgv, { cwd: options.projectDir, silent: true, env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables, AVA_PATH}, @@ -66,15 +65,15 @@ module.exports = (file, options, execArgv = process.execArgv) => { return; } - if (message.ava.type === 'ready-for-options') { - send({type: 'options', options}); - return; - } - - if (message.ava.type === 'ping') { - send({type: 'pong'}); - } else { - emitStateChange(message.ava); + switch (message.ava.type) { + case 'ready-for-options': + send({type: 'options', options}); + break; + case 'ping': + send({type: 'pong'}); + break; + default: + emitStateChange(message.ava); } }); @@ -99,6 +98,9 @@ module.exports = (file, options, execArgv = process.execArgv) => { }); return { + file, + promise, + exit() { forcedExit = true; subprocess.kill(); @@ -110,9 +112,6 @@ module.exports = (file, options, execArgv = process.execArgv) => { onStateChange(listener) { return emitter.on('stateChange', listener); - }, - - file, - promise + } }; };