@@ -154,14 +154,17 @@ function filterExecArgv(arg, i, arr) {
154154 ! ArrayPrototypeSome ( kFilterArgValues , ( p ) => arg === p || ( i > 0 && arr [ i - 1 ] === p ) || StringPrototypeStartsWith ( arg , `${ p } =` ) ) ;
155155}
156156
157- function getRunArgs ( { path, inspectPort, testNamePatterns } ) {
157+ function getRunArgs ( path , { inspectPort, testNamePatterns, only } ) {
158158 const argv = ArrayPrototypeFilter ( process . execArgv , filterExecArgv ) ;
159159 if ( isUsingInspector ( ) ) {
160160 ArrayPrototypePush ( argv , `--inspect-port=${ getInspectPort ( inspectPort ) } ` ) ;
161161 }
162- if ( testNamePatterns ) {
162+ if ( testNamePatterns != null ) {
163163 ArrayPrototypeForEach ( testNamePatterns , ( pattern ) => ArrayPrototypePush ( argv , `--test-name-pattern=${ pattern } ` ) ) ;
164164 }
165+ if ( only === true ) {
166+ ArrayPrototypePush ( argv , '--test-only' ) ;
167+ }
165168 ArrayPrototypePush ( argv , path ) ;
166169
167170 return argv ;
@@ -345,17 +348,17 @@ class FileTest extends Test {
345348 }
346349}
347350
348- function runTestFile ( path , root , inspectPort , filesWatcher , testNamePatterns ) {
351+ function runTestFile ( path , filesWatcher , opts ) {
349352 const watchMode = filesWatcher != null ;
350- const subtest = root . createSubtest ( FileTest , path , async ( t ) => {
351- const args = getRunArgs ( { __proto__ : null , path, inspectPort , testNamePatterns } ) ;
353+ const subtest = opts . root . createSubtest ( FileTest , path , async ( t ) => {
354+ const args = getRunArgs ( path , opts ) ;
352355 const stdio = [ 'pipe' , 'pipe' , 'pipe' ] ;
353356 const env = { __proto__ : null , ...process . env , NODE_TEST_CONTEXT : 'child-v8' } ;
354357 if ( watchMode ) {
355358 stdio . push ( 'ipc' ) ;
356359 env . WATCH_REPORT_DEPENDENCIES = '1' ;
357360 }
358- if ( root . harness . shouldColorizeTestFiles ) {
361+ if ( opts . root . harness . shouldColorizeTestFiles ) {
359362 env . FORCE_COLOR = '1' ;
360363 }
361364
@@ -402,7 +405,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
402405 filesWatcher . runningProcesses . delete ( path ) ;
403406 filesWatcher . runningSubtests . delete ( path ) ;
404407 if ( filesWatcher . runningSubtests . size === 0 ) {
405- root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
408+ opts . root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
406409 }
407410 }
408411
@@ -425,10 +428,10 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
425428 return subtest . start ( ) ;
426429}
427430
428- function watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) {
431+ function watchFiles ( testFiles , opts ) {
429432 const runningProcesses = new SafeMap ( ) ;
430433 const runningSubtests = new SafeMap ( ) ;
431- const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal } ) ;
434+ const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal : opts . signal } ) ;
432435 const filesWatcher = { __proto__ : null , watcher, runningProcesses, runningSubtests } ;
433436
434437 watcher . on ( 'changed' , ( { owners } ) => {
@@ -444,19 +447,19 @@ function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) {
444447 }
445448 if ( ! runningSubtests . size ) {
446449 // Reset the topLevel counter
447- root . harness . counters . topLevel = 0 ;
450+ opts . root . harness . counters . topLevel = 0 ;
448451 }
449452 await runningSubtests . get ( file ) ;
450- runningSubtests . set ( file , runTestFile ( file , root , inspectPort , filesWatcher , testNamePatterns ) ) ;
453+ runningSubtests . set ( file , runTestFile ( file , filesWatcher , opts ) ) ;
451454 } , undefined , ( error ) => {
452455 triggerUncaughtException ( error , true /* fromPromise */ ) ;
453456 } ) ) ;
454457 } ) ;
455- if ( signal ) {
458+ if ( opts . signal ) {
456459 kResistStopPropagation ??= require ( 'internal/event_target' ) . kResistStopPropagation ;
457- signal . addEventListener (
460+ opts . signal . addEventListener (
458461 'abort' ,
459- ( ) => root . postRun ( ) ,
462+ ( ) => opts . root . postRun ( ) ,
460463 { __proto__ : null , once : true , [ kResistStopPropagation ] : true } ,
461464 ) ;
462465 }
@@ -469,14 +472,17 @@ function run(options) {
469472 options = kEmptyObject ;
470473 }
471474 let { testNamePatterns, shard } = options ;
472- const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
475+ const { concurrency, timeout, signal, files, inspectPort, watch, setup, only } = options ;
473476
474477 if ( files != null ) {
475478 validateArray ( files , 'options.files' ) ;
476479 }
477480 if ( watch != null ) {
478481 validateBoolean ( watch , 'options.watch' ) ;
479482 }
483+ if ( only != null ) {
484+ validateBoolean ( only , 'options.only' ) ;
485+ }
480486 if ( shard != null ) {
481487 validateObject ( shard , 'options.shard' ) ;
482488 // Avoid re-evaluating the shard object in case it's a getter
@@ -522,14 +528,15 @@ function run(options) {
522528
523529 let postRun = ( ) => root . postRun ( ) ;
524530 let filesWatcher ;
531+ const opts = { __proto__ : null , root, signal, inspectPort, testNamePatterns, only } ;
525532 if ( watch ) {
526- filesWatcher = watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) ;
533+ filesWatcher = watchFiles ( testFiles , opts ) ;
527534 postRun = undefined ;
528535 }
529536 const runFiles = ( ) => {
530537 root . harness . bootstrapComplete = true ;
531538 return SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
532- const subtest = runTestFile ( path , root , inspectPort , filesWatcher , testNamePatterns ) ;
539+ const subtest = runTestFile ( path , filesWatcher , opts ) ;
533540 filesWatcher ?. runningSubtests . set ( path , subtest ) ;
534541 return subtest ;
535542 } ) ;
0 commit comments