@@ -110,14 +110,17 @@ function filterExecArgv(arg, i, arr) {
110
110
! ArrayPrototypeSome ( kFilterArgValues , ( p ) => arg === p || ( i > 0 && arr [ i - 1 ] === p ) || StringPrototypeStartsWith ( arg , `${ p } =` ) ) ;
111
111
}
112
112
113
- function getRunArgs ( { path, inspectPort, testNamePatterns } ) {
113
+ function getRunArgs ( path , { inspectPort, testNamePatterns, testOnly } ) {
114
114
const argv = ArrayPrototypeFilter ( process . execArgv , filterExecArgv ) ;
115
115
if ( isUsingInspector ( ) ) {
116
116
ArrayPrototypePush ( argv , `--inspect-port=${ getInspectPort ( inspectPort ) } ` ) ;
117
117
}
118
- if ( testNamePatterns ) {
118
+ if ( testNamePatterns != null ) {
119
119
ArrayPrototypeForEach ( testNamePatterns , ( pattern ) => ArrayPrototypePush ( argv , `--test-name-pattern=${ pattern } ` ) ) ;
120
120
}
121
+ if ( testOnly != null ) {
122
+ ArrayPrototypePush ( argv , '--test-only' ) ;
123
+ }
121
124
ArrayPrototypePush ( argv , path ) ;
122
125
123
126
return argv ;
@@ -301,17 +304,17 @@ class FileTest extends Test {
301
304
}
302
305
}
303
306
304
- function runTestFile ( path , root , inspectPort , filesWatcher , testNamePatterns ) {
307
+ function runTestFile ( path , filesWatcher , opts ) {
305
308
const watchMode = filesWatcher != null ;
306
- const subtest = root . createSubtest ( FileTest , path , async ( t ) => {
307
- const args = getRunArgs ( { __proto__ : null , path, inspectPort , testNamePatterns } ) ;
309
+ const subtest = opts . root . createSubtest ( FileTest , path , async ( t ) => {
310
+ const args = getRunArgs ( path , opts ) ;
308
311
const stdio = [ 'pipe' , 'pipe' , 'pipe' ] ;
309
312
const env = { __proto__ : null , ...process . env , NODE_TEST_CONTEXT : 'child-v8' } ;
310
313
if ( watchMode ) {
311
314
stdio . push ( 'ipc' ) ;
312
315
env . WATCH_REPORT_DEPENDENCIES = '1' ;
313
316
}
314
- if ( root . harness . shouldColorizeTestFiles ) {
317
+ if ( opts . root . harness . shouldColorizeTestFiles ) {
315
318
env . FORCE_COLOR = '1' ;
316
319
}
317
320
@@ -358,7 +361,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
358
361
filesWatcher . runningProcesses . delete ( path ) ;
359
362
filesWatcher . runningSubtests . delete ( path ) ;
360
363
if ( filesWatcher . runningSubtests . size === 0 ) {
361
- root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
364
+ opts . root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
362
365
}
363
366
}
364
367
@@ -381,10 +384,10 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
381
384
return subtest . start ( ) ;
382
385
}
383
386
384
- function watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) {
387
+ function watchFiles ( testFiles , opts ) {
385
388
const runningProcesses = new SafeMap ( ) ;
386
389
const runningSubtests = new SafeMap ( ) ;
387
- const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal } ) ;
390
+ const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal : opts . signal } ) ;
388
391
const filesWatcher = { __proto__ : null , watcher, runningProcesses, runningSubtests } ;
389
392
390
393
watcher . on ( 'changed' , ( { owners } ) => {
@@ -400,19 +403,19 @@ function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) {
400
403
}
401
404
if ( ! runningSubtests . size ) {
402
405
// Reset the topLevel counter
403
- root . harness . counters . topLevel = 0 ;
406
+ opts . root . harness . counters . topLevel = 0 ;
404
407
}
405
408
await runningSubtests . get ( file ) ;
406
- runningSubtests . set ( file , runTestFile ( file , root , inspectPort , filesWatcher , testNamePatterns ) ) ;
409
+ runningSubtests . set ( file , runTestFile ( file , filesWatcher , opts ) ) ;
407
410
} , undefined , ( error ) => {
408
411
triggerUncaughtException ( error , true /* fromPromise */ ) ;
409
412
} ) ) ;
410
413
} ) ;
411
- if ( signal ) {
414
+ if ( opts . signal ) {
412
415
kResistStopPropagation ??= require ( 'internal/event_target' ) . kResistStopPropagation ;
413
- signal . addEventListener (
416
+ opts . signal . addEventListener (
414
417
'abort' ,
415
- ( ) => root . postRun ( ) ,
418
+ ( ) => opts . root . postRun ( ) ,
416
419
{ __proto__ : null , once : true , [ kResistStopPropagation ] : true } ,
417
420
) ;
418
421
}
@@ -425,14 +428,17 @@ function run(options) {
425
428
options = kEmptyObject ;
426
429
}
427
430
let { testNamePatterns, shard } = options ;
428
- const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
431
+ const { concurrency, timeout, signal, files, inspectPort, watch, setup, testOnly } = options ;
429
432
430
433
if ( files != null ) {
431
434
validateArray ( files , 'options.files' ) ;
432
435
}
433
436
if ( watch != null ) {
434
437
validateBoolean ( watch , 'options.watch' ) ;
435
438
}
439
+ if ( testOnly != null ) {
440
+ validateBoolean ( testOnly , 'options.testOnly' ) ;
441
+ }
436
442
if ( shard != null ) {
437
443
validateObject ( shard , 'options.shard' ) ;
438
444
// Avoid re-evaluating the shard object in case it's a getter
@@ -478,14 +484,15 @@ function run(options) {
478
484
479
485
let postRun = ( ) => root . postRun ( ) ;
480
486
let filesWatcher ;
487
+ const opts = { __proto__ : null , root, signal, inspectPort, testNamePatterns, testOnly } ;
481
488
if ( watch ) {
482
- filesWatcher = watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) ;
489
+ filesWatcher = watchFiles ( testFiles , opts ) ;
483
490
postRun = undefined ;
484
491
}
485
492
const runFiles = ( ) => {
486
493
root . harness . bootstrapComplete = true ;
487
494
return SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
488
- const subtest = runTestFile ( path , root , inspectPort , filesWatcher , testNamePatterns ) ;
495
+ const subtest = runTestFile ( path , filesWatcher , opts ) ;
489
496
filesWatcher ?. runningSubtests . set ( path , subtest ) ;
490
497
return subtest ;
491
498
} ) ;
0 commit comments