@@ -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' ) ;
@@ -298,7 +301,10 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
298
301
subtest . addToReport ( ast ) ;
299
302
} ) ;
300
303
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
+ ] ) ;
302
308
303
309
runningProcesses . delete ( path ) ;
304
310
runningSubtests . delete ( path ) ;
@@ -347,14 +353,17 @@ function run(options) {
347
353
if ( options === null || typeof options !== 'object' ) {
348
354
options = kEmptyObject ;
349
355
}
350
- const { concurrency, timeout, signal, files, inspectPort, watch } = options ;
356
+ const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
351
357
352
358
if ( files != null ) {
353
359
validateArray ( files , 'options.files' ) ;
354
360
}
355
361
if ( watch != null ) {
356
362
validateBoolean ( watch , 'options.watch' ) ;
357
363
}
364
+ if ( setup != null ) {
365
+ validateFunction ( setup , 'options.setup' ) ;
366
+ }
358
367
359
368
const root = createTestTree ( { concurrency, timeout, signal } ) ;
360
369
const testFiles = files ?? createTestFileList ( ) ;
@@ -365,13 +374,13 @@ function run(options) {
365
374
filesWatcher = watchFiles ( testFiles , root , inspectPort ) ;
366
375
postRun = undefined ;
367
376
}
368
-
369
- PromisePrototypeThen ( SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
377
+ const runFiles = ( ) => SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
370
378
const subtest = runTestFile ( path , root , inspectPort , filesWatcher ) ;
371
379
runningSubtests . set ( path , subtest ) ;
372
380
return subtest ;
373
- } ) , postRun ) ;
381
+ } ) ;
374
382
383
+ PromisePrototypeThen ( PromisePrototypeThen ( PromiseResolve ( setup ?. ( root . reporter ) ) , runFiles ) , postRun ) ;
375
384
376
385
return root . reporter ;
377
386
}
0 commit comments