diff --git a/lib/fork.js b/lib/fork.js index cf0717d9c..bf583c801 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'); const useAdvanced = process.versions.node >= '12.17.0'; // FIXME: Fix this in api.js or cli.js. @@ -32,12 +31,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}, @@ -73,15 +72,15 @@ module.exports = (file, options, execArgv = process.execArgv) => { return; } - if (message.ava.type === 'ready-for-options') { - send({type: 'options', options: serializeOptions(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: serializeOptions(options)}); + break; + case 'ping': + send({type: 'pong'}); + break; + default: + emitStateChange(message.ava); } }); @@ -106,6 +105,9 @@ module.exports = (file, options, execArgv = process.execArgv) => { }); return { + file, + promise, + exit() { forcedExit = true; subprocess.kill(); @@ -117,9 +119,6 @@ module.exports = (file, options, execArgv = process.execArgv) => { onStateChange(listener) { return emitter.on('stateChange', listener); - }, - - file, - promise + } }; };