Skip to content

Commit b807a22

Browse files
committed
refactor(ses-ava): Remove use of ambient process from main
1 parent 1ab1b8e commit b807a22

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

packages/ses-ava/bin/ses-ava.cjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/usr/bin/env node
22
(async () => {
33
const { main } = await import('../src/command.js');
4-
await main(process.argv.slice(2));
5-
})().catch(error => {
6-
console.error(error);
7-
process.exitCode = 1;
8-
});
4+
return main(process.argv.slice(2));
5+
})().then(
6+
exitCode => {
7+
process.exitCode ||= exitCode;
8+
},
9+
error => {
10+
console.error(error);
11+
process.exitCode ||= 1;
12+
},
13+
);

packages/ses-ava/src/command.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global process */
21
/* eslint-disable no-await-in-loop, no-continue, no-labels, no-unreachable-loop */
32

43
/* The ses-ava command allows a single package to run the same test suite with
@@ -39,7 +38,7 @@ const passThroughArgOptions = new Set([
3938
'--port',
4039
]);
4140

42-
/** @type {(args: string[]) => Promise<void>} */
41+
/** @type {(args: string[]) => Promise<number>} */
4342
export const main = async args => {
4443
// Parse configuration.
4544
const descriptorText = await fs.promises.readFile('package.json', 'utf8');
@@ -138,6 +137,7 @@ export const main = async args => {
138137
}
139138

140139
// Execute configurations serially.
140+
let exitCode = 0;
141141
for (const config of configs) {
142142
console.warn(`[ses-ava] config:`, config);
143143
const avaArgs = [
@@ -147,17 +147,16 @@ export const main = async args => {
147147
const child = popen.spawn('ava', avaArgs, {
148148
stdio: ['inherit', 'inherit', 'inherit'],
149149
});
150-
await new Promise((resolve, reject) => {
151-
child.on('exit', code => {
152-
process.exitCode ||= typeof code === 'number' ? code : 1;
153-
if (failFast && process.exitCode !== 0) {
154-
process.exit();
155-
}
156-
resolve(undefined);
150+
const configExitCode = await new Promise((resolve, reject) => {
151+
child.on('exit', (code, _signal) => {
152+
resolve(typeof code === 'number' ? code : 1);
157153
});
158154
child.on('error', error => {
159155
reject(error);
160156
});
161157
});
158+
exitCode ||= configExitCode;
159+
if (failFast && exitCode !== 0) break;
162160
}
161+
return exitCode;
163162
};

0 commit comments

Comments
 (0)