@@ -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,
@@ -24,6 +26,7 @@ const {
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' ) ;
@@ -33,7 +36,7 @@ const {
3336 ERR_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' ) ;
@@ -298,7 +301,10 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
298301 subtest . addToReport ( ast ) ;
299302 } ) ;
300303
301- const { 0 : code , 1 : signal } = await once ( child , 'exit' , { signal : t . signal } ) ;
304+ const { 0 : { 0 : code , 1 : signal } } = await SafePromiseAll ( [
305+ once ( child , 'exit' , { signal : t . signal } ) ,
306+ finished ( parser , { signal : t . signal } ) ,
307+ ] ) ;
302308
303309 runningProcesses . delete ( path ) ;
304310 runningSubtests . delete ( path ) ;
@@ -347,14 +353,17 @@ function run(options) {
347353 if ( options === null || typeof options !== 'object' ) {
348354 options = kEmptyObject ;
349355 }
350- const { concurrency, timeout, signal, files, inspectPort, watch } = options ;
356+ const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
351357
352358 if ( files != null ) {
353359 validateArray ( files , 'options.files' ) ;
354360 }
355361 if ( watch != null ) {
356362 validateBoolean ( watch , 'options.watch' ) ;
357363 }
364+ if ( setup != null ) {
365+ validateFunction ( setup , 'options.setup' ) ;
366+ }
358367
359368 const root = createTestTree ( { concurrency, timeout, signal } ) ;
360369 const testFiles = files ?? createTestFileList ( ) ;
@@ -365,13 +374,13 @@ function run(options) {
365374 filesWatcher = watchFiles ( testFiles , root , inspectPort ) ;
366375 postRun = undefined ;
367376 }
368-
369- PromisePrototypeThen ( SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
377+ const runFiles = ( ) => SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
370378 const subtest = runTestFile ( path , root , inspectPort , filesWatcher ) ;
371379 runningSubtests . set ( path , subtest ) ;
372380 return subtest ;
373- } ) , postRun ) ;
381+ } ) ;
374382
383+ PromisePrototypeThen ( PromisePrototypeThen ( PromiseResolve ( setup ?. ( root . reporter ) ) , runFiles ) , postRun ) ;
375384
376385 return root . reporter ;
377386}
0 commit comments