@@ -13,8 +13,10 @@ const{
1313 ObjectAssign,
1414 ObjectKeys,
1515 PromisePrototypeThen,
16+ SafePromiseAll,
1617 SafePromiseAllReturnVoid,
1718 SafePromiseAllSettledReturnVoid,
19+ PromiseResolve,
1820 SafeMap,
1921 SafeSet,
2022 StringPrototypeIndexOf,
2426
2527const { spawn } = require ( 'child_process' ) ;
2628const { readdirSync, statSync } = require ( 'fs' ) ;
29+ const { finished } = require ( 'internal/streams/end-of-stream' ) ;
2730// TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern.
2831const { createInterface } = require ( 'readline' ) ;
2932const { FilesWatcher } = require ( 'internal/watch_mode/files_watcher' ) ;
3336ERR_TEST_FAILURE ,
3437} ,
3538} = require ( 'internal/errors' ) ;
36- const { validateArray, validateBoolean } = require ( 'internal/validators' ) ;
39+ const { validateArray, validateBoolean, validateFunction } = require ( 'internal/validators' ) ;
3740const { getInspectPort, isUsingInspector, isInspectorMessage } = require ( 'internal/util/inspector' ) ;
3841const { kEmptyObject } = require ( 'internal/util' ) ;
3942const { createTestTree } = require ( 'internal/test_runner/harness' ) ;
@@ -299,7 +302,10 @@ function runTestFile(path, root, inspectPort, filesWatcher){
299302subtest . addToReport ( ast ) ;
300303} ) ;
301304
302- const { 0 : code , 1 : signal } = await once ( child , 'exit' , { signal : t . signal } ) ;
305+ const { 0 : { 0 : code , 1 : signal } } = await SafePromiseAll ( [
306+ once ( child , 'exit' , { signal : t . signal } ) ,
307+ finished ( parser , { signal : t . signal } ) ,
308+ ] ) ;
303309
304310runningProcesses . delete ( path ) ;
305311runningSubtests . delete ( path ) ;
@@ -348,14 +354,17 @@ function run(options){
348354if ( options === null || typeof options !== 'object' ) {
349355options = kEmptyObject ;
350356}
351- const { concurrency, timeout, signal, files, inspectPort, watch } = options ;
357+ const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
352358
353359if ( files != null ) {
354360validateArray ( files , 'options.files' ) ;
355361}
356362if ( watch != null ) {
357363validateBoolean ( watch , 'options.watch' ) ;
358364}
365+ if ( setup != null ) {
366+ validateFunction ( setup , 'options.setup' ) ;
367+ }
359368
360369const root = createTestTree ( { concurrency, timeout, signal } ) ;
361370const testFiles = files ?? createTestFileList ( ) ;
@@ -366,13 +375,13 @@ function run(options){
366375filesWatcher = watchFiles ( testFiles , root , inspectPort ) ;
367376postRun = undefined ;
368377}
369-
370- PromisePrototypeThen ( SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
378+ const runFiles = ( ) => SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
371379const subtest = runTestFile ( path , root , inspectPort , filesWatcher ) ;
372380runningSubtests . set ( path , subtest ) ;
373381return subtest ;
374- } ) , postRun ) ;
382+ } ) ;
375383
384+ PromisePrototypeThen ( PromisePrototypeThen ( PromiseResolve ( setup ?. ( root . reporter ) ) , runFiles ) , postRun ) ;
376385
377386return root . reporter ;
378387}
0 commit comments