@@ -156,14 +156,17 @@ function filterExecArgv(arg, i, arr) {
156
156
! ArrayPrototypeSome ( kFilterArgValues , ( p ) => arg === p || ( i > 0 && arr [ i - 1 ] === p ) || StringPrototypeStartsWith ( arg , `${ p } =` ) ) ;
157
157
}
158
158
159
- function getRunArgs ( { path, inspectPort, testNamePatterns } ) {
159
+ function getRunArgs ( path , { inspectPort, testNamePatterns, only } ) {
160
160
const argv = ArrayPrototypeFilter ( process . execArgv , filterExecArgv ) ;
161
161
if ( isUsingInspector ( ) ) {
162
162
ArrayPrototypePush ( argv , `--inspect-port=${ getInspectPort ( inspectPort ) } ` ) ;
163
163
}
164
- if ( testNamePatterns ) {
164
+ if ( testNamePatterns != null ) {
165
165
ArrayPrototypeForEach ( testNamePatterns , ( pattern ) => ArrayPrototypePush ( argv , `--test-name-pattern=${ pattern } ` ) ) ;
166
166
}
167
+ if ( only === true ) {
168
+ ArrayPrototypePush ( argv , '--test-only' ) ;
169
+ }
167
170
ArrayPrototypePush ( argv , path ) ;
168
171
169
172
return argv ;
@@ -347,17 +350,17 @@ class FileTest extends Test {
347
350
}
348
351
}
349
352
350
- function runTestFile ( path , root , inspectPort , filesWatcher , testNamePatterns ) {
353
+ function runTestFile ( path , filesWatcher , opts ) {
351
354
const watchMode = filesWatcher != null ;
352
- const subtest = root . createSubtest ( FileTest , path , async ( t ) => {
353
- const args = getRunArgs ( { __proto__ : null , path, inspectPort , testNamePatterns } ) ;
355
+ const subtest = opts . root . createSubtest ( FileTest , path , async ( t ) => {
356
+ const args = getRunArgs ( path , opts ) ;
354
357
const stdio = [ 'pipe' , 'pipe' , 'pipe' ] ;
355
358
const env = { __proto__ : null , ...process . env , NODE_TEST_CONTEXT : 'child-v8' } ;
356
359
if ( watchMode ) {
357
360
stdio . push ( 'ipc' ) ;
358
361
env . WATCH_REPORT_DEPENDENCIES = '1' ;
359
362
}
360
- if ( root . harness . shouldColorizeTestFiles ) {
363
+ if ( opts . root . harness . shouldColorizeTestFiles ) {
361
364
env . FORCE_COLOR = '1' ;
362
365
}
363
366
@@ -404,7 +407,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
404
407
filesWatcher . runningProcesses . delete ( path ) ;
405
408
filesWatcher . runningSubtests . delete ( path ) ;
406
409
if ( filesWatcher . runningSubtests . size === 0 ) {
407
- root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
410
+ opts . root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
408
411
}
409
412
}
410
413
@@ -427,10 +430,10 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
427
430
return subtest . start ( ) ;
428
431
}
429
432
430
- function watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) {
433
+ function watchFiles ( testFiles , opts ) {
431
434
const runningProcesses = new SafeMap ( ) ;
432
435
const runningSubtests = new SafeMap ( ) ;
433
- const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal } ) ;
436
+ const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal : opts . signal } ) ;
434
437
const filesWatcher = { __proto__ : null , watcher, runningProcesses, runningSubtests } ;
435
438
436
439
watcher . on ( 'changed' , ( { owners } ) => {
@@ -446,19 +449,19 @@ function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) {
446
449
}
447
450
if ( ! runningSubtests . size ) {
448
451
// Reset the topLevel counter
449
- root . harness . counters . topLevel = 0 ;
452
+ opts . root . harness . counters . topLevel = 0 ;
450
453
}
451
454
await runningSubtests . get ( file ) ;
452
- runningSubtests . set ( file , runTestFile ( file , root , inspectPort , filesWatcher , testNamePatterns ) ) ;
455
+ runningSubtests . set ( file , runTestFile ( file , filesWatcher , opts ) ) ;
453
456
} , undefined , ( error ) => {
454
457
triggerUncaughtException ( error , true /* fromPromise */ ) ;
455
458
} ) ) ;
456
459
} ) ;
457
- if ( signal ) {
460
+ if ( opts . signal ) {
458
461
kResistStopPropagation ??= require ( 'internal/event_target' ) . kResistStopPropagation ;
459
- signal . addEventListener (
462
+ opts . signal . addEventListener (
460
463
'abort' ,
461
- ( ) => root . postRun ( ) ,
464
+ ( ) => opts . root . postRun ( ) ,
462
465
{ __proto__ : null , once : true , [ kResistStopPropagation ] : true } ,
463
466
) ;
464
467
}
@@ -471,14 +474,17 @@ function run(options) {
471
474
options = kEmptyObject ;
472
475
}
473
476
let { testNamePatterns, shard } = options ;
474
- const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
477
+ const { concurrency, timeout, signal, files, inspectPort, watch, setup, only } = options ;
475
478
476
479
if ( files != null ) {
477
480
validateArray ( files , 'options.files' ) ;
478
481
}
479
482
if ( watch != null ) {
480
483
validateBoolean ( watch , 'options.watch' ) ;
481
484
}
485
+ if ( only != null ) {
486
+ validateBoolean ( only , 'options.only' ) ;
487
+ }
482
488
if ( shard != null ) {
483
489
validateObject ( shard , 'options.shard' ) ;
484
490
// Avoid re-evaluating the shard object in case it's a getter
@@ -524,14 +530,15 @@ function run(options) {
524
530
525
531
let postRun = ( ) => root . postRun ( ) ;
526
532
let filesWatcher ;
533
+ const opts = { __proto__ : null , root, signal, inspectPort, testNamePatterns, only } ;
527
534
if ( watch ) {
528
- filesWatcher = watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) ;
535
+ filesWatcher = watchFiles ( testFiles , opts ) ;
529
536
postRun = undefined ;
530
537
}
531
538
const runFiles = ( ) => {
532
539
root . harness . bootstrapComplete = true ;
533
540
return SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
534
- const subtest = runTestFile ( path , root , inspectPort , filesWatcher , testNamePatterns ) ;
541
+ const subtest = runTestFile ( path , filesWatcher , opts ) ;
535
542
filesWatcher ?. runningSubtests . set ( path , subtest ) ;
536
543
return subtest ;
537
544
} ) ;
0 commit comments