Skip to content

Commit ba4f426

Browse files
committed
Clean-up in lib/fork.js
1 parent 759c3fa commit ba4f426

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

lib/fork.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ if (fs.realpathSync(__filename) !== __filename) {
1212
// In case the test file imports a different AVA install,
1313
// the presence of this variable allows it to require this one instead
1414
const AVA_PATH = path.resolve(__dirname, '..');
15-
16-
const workerPath = require.resolve('./worker/subprocess');
15+
const WORKER_PATH = require.resolve('./worker/subprocess');
1716

1817
module.exports = (file, options, execArgv = process.execArgv) => {
1918
let finished = false;
@@ -26,12 +25,12 @@ module.exports = (file, options, execArgv = process.execArgv) => {
2625
};
2726

2827
options = {
29-
file,
3028
baseDir: process.cwd(),
29+
file,
3130
...options
3231
};
3332

34-
const subprocess = childProcess.fork(workerPath, options.workerArgv, {
33+
const subprocess = childProcess.fork(WORKER_PATH, options.workerArgv, {
3534
cwd: options.projectDir,
3635
silent: true,
3736
env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables, AVA_PATH},
@@ -66,15 +65,15 @@ module.exports = (file, options, execArgv = process.execArgv) => {
6665
return;
6766
}
6867

69-
if (message.ava.type === 'ready-for-options') {
70-
send({type: 'options', options});
71-
return;
72-
}
73-
74-
if (message.ava.type === 'ping') {
75-
send({type: 'pong'});
76-
} else {
77-
emitStateChange(message.ava);
68+
switch (message.ava.type) {
69+
case 'ready-for-options':
70+
send({type: 'options', options});
71+
break;
72+
case 'ping':
73+
send({type: 'pong'});
74+
break;
75+
default:
76+
emitStateChange(message.ava);
7877
}
7978
});
8079

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

101100
return {
101+
file,
102+
promise,
103+
102104
exit() {
103105
forcedExit = true;
104106
subprocess.kill();
@@ -110,9 +112,6 @@ module.exports = (file, options, execArgv = process.execArgv) => {
110112

111113
onStateChange(listener) {
112114
return emitter.on('stateChange', listener);
113-
},
114-
115-
file,
116-
promise
115+
}
117116
};
118117
};

0 commit comments

Comments
 (0)