Skip to content

Commit 60190cd

Browse files
authored
refactor(ses-ava): Remove use of ambient process from main (#3002)
2 parents 4a888b1 + b807a22 commit 60190cd

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
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: 10 additions & 10 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,8 @@ const passThroughArgOptions = new Set([
3938
'--port',
4039
]);
4140

42-
export const main = async () => {
41+
/** @type {(args: string[]) => Promise<number>} */
42+
export const main = async args => {
4343
// Parse configuration.
4444
const descriptorText = await fs.promises.readFile('package.json', 'utf8');
4545
const descriptor = JSON.parse(descriptorText);
@@ -54,7 +54,7 @@ export const main = async () => {
5454
const onlyConfigNames = new Set();
5555
let failFast = false;
5656
let firstArg = true;
57-
const argsIterator = process.argv.slice(2)[Symbol.iterator]();
57+
const argsIterator = args[Symbol.iterator]();
5858
for (const rawArg of argsIterator) {
5959
if (rawArg === '--') {
6060
passThroughArgs.push(...argsIterator);
@@ -137,6 +137,7 @@ export const main = async () => {
137137
}
138138

139139
// Execute configurations serially.
140+
let exitCode = 0;
140141
for (const config of configs) {
141142
console.warn(`[ses-ava] config:`, config);
142143
const avaArgs = [
@@ -146,17 +147,16 @@ export const main = async () => {
146147
const child = popen.spawn('ava', avaArgs, {
147148
stdio: ['inherit', 'inherit', 'inherit'],
148149
});
149-
await new Promise((resolve, reject) => {
150-
child.on('exit', code => {
151-
process.exitCode ||= typeof code === 'number' ? code : 1;
152-
if (failFast && process.exitCode !== 0) {
153-
process.exit();
154-
}
155-
resolve(undefined);
150+
const configExitCode = await new Promise((resolve, reject) => {
151+
child.on('exit', (code, _signal) => {
152+
resolve(typeof code === 'number' ? code : 1);
156153
});
157154
child.on('error', error => {
158155
reject(error);
159156
});
160157
});
158+
exitCode ||= configExitCode;
159+
if (failFast && exitCode !== 0) break;
161160
}
161+
return exitCode;
162162
};

0 commit comments

Comments
 (0)