@@ -13,8 +13,10 @@ const {
13
13
ObjectAssign,
14
14
ObjectKeys,
15
15
PromisePrototypeThen,
16
+ SafePromiseAll,
16
17
SafePromiseAllReturnVoid,
17
18
SafePromiseAllSettledReturnVoid,
19
+ PromiseResolve,
18
20
SafeMap,
19
21
SafeSet,
20
22
StringPrototypeIndexOf,
@@ -24,6 +26,7 @@ const {
24
26
25
27
const { spawn } = require ( 'child_process' ) ;
26
28
const { readdirSync, statSync } = require ( 'fs' ) ;
29
+ const { finished } = require ( 'internal/streams/end-of-stream' ) ;
27
30
// TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern.
28
31
const { createInterface } = require ( 'readline' ) ;
29
32
const { FilesWatcher } = require ( 'internal/watch_mode/files_watcher' ) ;
@@ -33,7 +36,7 @@ const {
33
36
ERR_TEST_FAILURE ,
34
37
} ,
35
38
} = require ( 'internal/errors' ) ;
36
- const { validateArray, validateBoolean } = require ( 'internal/validators' ) ;
39
+ const { validateArray, validateBoolean, validateFunction } = require ( 'internal/validators' ) ;
37
40
const { getInspectPort, isUsingInspector, isInspectorMessage } = require ( 'internal/util/inspector' ) ;
38
41
const { kEmptyObject } = require ( 'internal/util' ) ;
39
42
const { createTestTree } = require ( 'internal/test_runner/harness' ) ;
@@ -299,7 +302,10 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
299
302
subtest . addToReport ( ast ) ;
300
303
} ) ;
301
304
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
+ ] ) ;
303
309
304
310
runningProcesses . delete ( path ) ;
305
311
runningSubtests . delete ( path ) ;
@@ -348,14 +354,17 @@ function run(options) {
348
354
if ( options === null || typeof options !== 'object' ) {
349
355
options = kEmptyObject ;
350
356
}
351
- const { concurrency, timeout, signal, files, inspectPort, watch } = options ;
357
+ const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
352
358
353
359
if ( files != null ) {
354
360
validateArray ( files , 'options.files' ) ;
355
361
}
356
362
if ( watch != null ) {
357
363
validateBoolean ( watch , 'options.watch' ) ;
358
364
}
365
+ if ( setup != null ) {
366
+ validateFunction ( setup , 'options.setup' ) ;
367
+ }
359
368
360
369
const root = createTestTree ( { concurrency, timeout, signal } ) ;
361
370
const testFiles = files ?? createTestFileList ( ) ;
@@ -366,13 +375,13 @@ function run(options) {
366
375
filesWatcher = watchFiles ( testFiles , root , inspectPort ) ;
367
376
postRun = undefined ;
368
377
}
369
-
370
- PromisePrototypeThen ( SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
378
+ const runFiles = ( ) => SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
371
379
const subtest = runTestFile ( path , root , inspectPort , filesWatcher ) ;
372
380
runningSubtests . set ( path , subtest ) ;
373
381
return subtest ;
374
- } ) , postRun ) ;
382
+ } ) ;
375
383
384
+ PromisePrototypeThen ( PromisePrototypeThen ( PromiseResolve ( setup ?. ( root . reporter ) ) , runFiles ) , postRun ) ;
376
385
377
386
return root . reporter ;
378
387
}
0 commit comments