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