Skip to content

Commit

Permalink
Clean-up in lib/fork.js
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Aug 16, 2020
1 parent ea66e64 commit 2cee0af
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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},
Expand Down Expand Up @@ -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);
}
});

Expand All @@ -106,6 +105,9 @@ module.exports = (file, options, execArgv = process.execArgv) => {
});

return {
file,
promise,

exit() {
forcedExit = true;
subprocess.kill();
Expand All @@ -117,9 +119,6 @@ module.exports = (file, options, execArgv = process.execArgv) => {

onStateChange(listener) {
return emitter.on('stateChange', listener);
},

file,
promise
}
};
};

0 comments on commit 2cee0af

Please sign in to comment.