@@ -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 } ) {
158158const argv = ArrayPrototypeFilter ( process . execArgv , filterExecArgv ) ;
159159if ( isUsingInspector ( ) ) {
160160ArrayPrototypePush ( argv , `--inspect-port=${ getInspectPort ( inspectPort ) } ` ) ;
161161}
162- if ( testNamePatterns ) {
162+ if ( testNamePatterns != null ) {
163163ArrayPrototypeForEach ( testNamePatterns , ( pattern ) => ArrayPrototypePush ( argv , `--test-name-pattern=${ pattern } ` ) ) ;
164164}
165+ if ( only === true ) {
166+ ArrayPrototypePush ( argv , '--test-only' ) ;
167+ }
165168ArrayPrototypePush ( argv , path ) ;
166169
167170return 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 ) {
349352const 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 ) ;
352355const stdio = [ 'pipe' , 'pipe' , 'pipe' ] ;
353356const env = { __proto__ : null , ...process . env , NODE_TEST_CONTEXT : 'child-v8' } ;
354357if ( watchMode ) {
355358stdio . push ( 'ipc' ) ;
356359env . WATCH_REPORT_DEPENDENCIES = '1' ;
357360}
358- if ( root . harness . shouldColorizeTestFiles ) {
361+ if ( opts . root . harness . shouldColorizeTestFiles ) {
359362env . FORCE_COLOR = '1' ;
360363}
361364
@@ -402,7 +405,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns){
402405filesWatcher . runningProcesses . delete ( path ) ;
403406filesWatcher . runningSubtests . delete ( path ) ;
404407if ( 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){
425428return subtest . start ( ) ;
426429}
427430
428- function watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) {
431+ function watchFiles ( testFiles , opts ) {
429432const runningProcesses = new SafeMap ( ) ;
430433const 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 } ) ;
432435const filesWatcher = { __proto__ : null , watcher, runningProcesses, runningSubtests } ;
433436
434437watcher . on ( 'changed' , ( { owners } ) => {
@@ -444,19 +447,19 @@ function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns){
444447}
445448if ( ! runningSubtests . size ) {
446449// Reset the topLevel counter
447- root . harness . counters . topLevel = 0 ;
450+ opts . root . harness . counters . topLevel = 0 ;
448451}
449452await runningSubtests . get ( file ) ;
450- runningSubtests . set ( file , runTestFile ( file , root , inspectPort , filesWatcher , testNamePatterns ) ) ;
453+ runningSubtests . set ( file , runTestFile ( file , filesWatcher , opts ) ) ;
451454} , undefined , ( error ) => {
452455triggerUncaughtException ( error , true /* fromPromise */ ) ;
453456} ) ) ;
454457} ) ;
455- if ( signal ) {
458+ if ( opts . signal ) {
456459kResistStopPropagation ??= 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){
469472options = kEmptyObject ;
470473}
471474let { 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
474477if ( files != null ) {
475478validateArray ( files , 'options.files' ) ;
476479}
477480if ( watch != null ) {
478481validateBoolean ( watch , 'options.watch' ) ;
479482}
483+ if ( only != null ) {
484+ validateBoolean ( only , 'options.only' ) ;
485+ }
480486if ( shard != null ) {
481487validateObject ( shard , 'options.shard' ) ;
482488// Avoid re-evaluating the shard object in case it's a getter
@@ -522,14 +528,15 @@ function run(options){
522528
523529let postRun = ( ) => root . postRun ( ) ;
524530let filesWatcher ;
531+ const opts = { __proto__ : null , root, signal, inspectPort, testNamePatterns, only } ;
525532if ( watch ) {
526- filesWatcher = watchFiles ( testFiles , root , inspectPort , signal , testNamePatterns ) ;
533+ filesWatcher = watchFiles ( testFiles , opts ) ;
527534postRun = undefined ;
528535}
529536const runFiles = ( ) => {
530537root . harness . bootstrapComplete = true ;
531538return SafePromiseAllSettledReturnVoid ( testFiles , ( path ) => {
532- const subtest = runTestFile ( path , root , inspectPort , filesWatcher , testNamePatterns ) ;
539+ const subtest = runTestFile ( path , filesWatcher , opts ) ;
533540filesWatcher ?. runningSubtests . set ( path , subtest ) ;
534541return subtest ;
535542} ) ;
0 commit comments