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 Sep 20, 2020
1 parent 759c3fa commit ba4f426
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');

module.exports = (file, options, execArgv = process.execArgv) => {
let finished = false;
Expand All @@ -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},
Expand Down Expand Up @@ -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);
}
});

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

return {
file,
promise,

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

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

file,
promise
}
};
};

0 comments on commit ba4f426

Please sign in to comment.