@@ -82,7 +82,7 @@ const {
8282const {
8383 convertStringToRegExp,
8484 countCompletedTest,
85- kDefaultPattern ,
85+ getDefaultPattern ,
8686 parseCommandLine,
8787} = require ( 'internal/test_runner/utils' ) ;
8888const { Glob } = require ( 'internal/fs/glob' ) ;
@@ -105,20 +105,20 @@ const kCanceledTests = new SafeSet()
105105
106106let kResistStopPropagation ;
107107
108- function createTestFileList ( patterns , cwd ) {
109- const hasUserSuppliedPattern = patterns != null ;
110- if ( ! patterns || patterns . length === 0 ) {
111- patterns = [ kDefaultPattern ] ;
108+ function createTestFileList ( { globPatterns , cwd, typescript } ) {
109+ const hasUserSuppliedPattern = globPatterns != null ;
110+ if ( ! globPatterns || globPatterns . length === 0 ) {
111+ globPatterns = [ getDefaultPattern ( typescript ) ] ;
112112 }
113- const glob = new Glob ( patterns , {
113+ const glob = new Glob ( globPatterns , {
114114 __proto__ : null ,
115115 cwd,
116116 exclude : ( name ) => name === 'node_modules' ,
117117 } ) ;
118118 const results = glob . globSync ( ) ;
119119
120120 if ( hasUserSuppliedPattern && results . length === 0 && ArrayPrototypeEvery ( glob . matchers , ( m ) => ! m . hasMagic ( ) ) ) {
121- console . error ( `Could not find '${ ArrayPrototypeJoin ( patterns , ', ' ) } '` ) ;
121+ console . error ( `Could not find '${ ArrayPrototypeJoin ( globPatterns , ', ' ) } '` ) ;
122122 process . exit ( kGenericUserError ) ;
123123 }
124124
@@ -130,7 +130,7 @@ function filterExecArgv(arg, i, arr) {
130130 ! ArrayPrototypeSome ( kFilterArgValues , ( p ) => arg === p || ( i > 0 && arr [ i - 1 ] === p ) || StringPrototypeStartsWith ( arg , `${ p } =` ) ) ;
131131}
132132
133- function getRunArgs ( path , { forceExit, inspectPort, testNamePatterns, testSkipPatterns, only } ) {
133+ function getRunArgs ( path , { forceExit, inspectPort, testNamePatterns, testSkipPatterns, typescript , only } ) {
134134 const argv = ArrayPrototypeFilter ( process . execArgv , filterExecArgv ) ;
135135 if ( forceExit === true ) {
136136 ArrayPrototypePush ( argv , '--test-force-exit' ) ;
@@ -147,6 +147,9 @@ function getRunArgs(path, { forceExit, inspectPort, testNamePatterns, testSkipPa
147147 if ( only === true ) {
148148 ArrayPrototypePush ( argv , '--test-only' ) ;
149149 }
150+ if ( typescript !== 'none' ) {
151+ ArrayPrototypePush ( argv , `--experimental-${ typescript } -types` ) ;
152+ }
150153
151154 if ( path === kIsolatedProcessName ) {
152155 ArrayPrototypePush ( argv , '--test' , ...ArrayPrototypeSlice ( process . argv , 1 ) ) ;
@@ -473,7 +476,7 @@ function watchFiles(testFiles, opts) {
473476 // Watch for changes in current filtered files
474477 watcher . on ( 'changed' , ( { owners, eventType } ) => {
475478 if ( ! opts . hasFiles && ( eventType === 'rename' || eventType === 'change' ) ) {
476- const updatedTestFiles = createTestFileList ( opts . globPatterns , opts . cwd ) ;
479+ const updatedTestFiles = createTestFileList ( opts ) ;
477480 const newFileName = ArrayPrototypeFind ( updatedTestFiles , ( x ) => ! ArrayPrototypeIncludes ( testFiles , x ) ) ;
478481 const previousFileName = ArrayPrototypeFind ( testFiles , ( x ) => ! ArrayPrototypeIncludes ( updatedTestFiles , x ) ) ;
479482
@@ -540,6 +543,7 @@ function run(options = kEmptyObject) {
540543 forceExit,
541544 inspectPort,
542545 isolation = 'process' ,
546+ typescript = 'none' ,
543547 watch,
544548 setup,
545549 only,
@@ -626,6 +630,7 @@ function run(options = kEmptyObject) {
626630 } ) ;
627631 }
628632 validateOneOf ( isolation , 'options.isolation' , [ 'process' , 'none' ] ) ;
633+ validateOneOf ( typescript , 'options.typescript' , [ 'strip' , 'transform' , 'none' ] ) ;
629634 validateBoolean ( coverage , 'options.coverage' ) ;
630635 if ( coverageExcludeGlobs != null ) {
631636 if ( ! ArrayIsArray ( coverageExcludeGlobs ) ) {
@@ -662,12 +667,6 @@ function run(options = kEmptyObject) {
662667 // This const should be replaced by a run option in the future.
663668 const cwd = process . cwd ( ) ;
664669
665- let testFiles = files ?? createTestFileList ( globPatterns , cwd ) ;
666-
667- if ( shard ) {
668- testFiles = ArrayPrototypeFilter ( testFiles , ( _ , index ) => index % shard . total === shard . index - 1 ) ;
669- }
670-
671670 let teardown ;
672671 let postRun ;
673672 let filesWatcher ;
@@ -685,8 +684,15 @@ function run(options = kEmptyObject) {
685684 forceExit,
686685 cwd,
687686 isolation,
687+ typescript,
688688 } ;
689689
690+ let testFiles = files ?? createTestFileList ( opts ) ;
691+
692+ if ( shard ) {
693+ testFiles = ArrayPrototypeFilter ( testFiles , ( _ , index ) => index % shard . total === shard . index - 1 ) ;
694+ }
695+
690696 if ( isolation === 'process' ) {
691697 if ( process . env . NODE_TEST_CONTEXT !== undefined ) {
692698 process . emitWarning ( 'node:test run() is being called recursively within a test file. skipping running files.' ) ;
0 commit comments