@@ -33,7 +33,7 @@ const {
33
33
34
34
const { spawn } = require ( 'child_process' ) ;
35
35
const { finished } = require ( 'internal/streams/end-of-stream' ) ;
36
- const { resolve } = require ( 'path' ) ;
36
+ const { resolve, sep , isAbsolute } = require ( 'path' ) ;
37
37
const { DefaultDeserializer, DefaultSerializer } = require ( 'v8' ) ;
38
38
const { getOptionValue } = require ( 'internal/options' ) ;
39
39
const { Interface } = require ( 'internal/readline/interface' ) ;
@@ -56,14 +56,14 @@ const {
56
56
validateObject,
57
57
validateOneOf,
58
58
validateInteger,
59
+ validateString,
59
60
validateStringArray,
60
61
} = require ( 'internal/validators' ) ;
61
62
const { getInspectPort, isUsingInspector, isInspectorMessage } = require ( 'internal/util/inspector' ) ;
62
63
const { isRegExp } = require ( 'internal/util/types' ) ;
63
64
const { pathToFileURL } = require ( 'internal/url' ) ;
64
65
const {
65
66
createDeferredPromise,
66
- getCWDURL,
67
67
kEmptyObject,
68
68
} = require ( 'internal/util' ) ;
69
69
const { kEmitMessage } = require ( 'internal/test_runner/tests_stream' ) ;
@@ -137,7 +137,8 @@ function getRunArgs(path, { forceExit,
137
137
testSkipPatterns,
138
138
only,
139
139
argv : suppliedArgs ,
140
- execArgv } ) {
140
+ execArgv,
141
+ cwd } ) {
141
142
const argv = ArrayPrototypeFilter ( process . execArgv , filterExecArgv ) ;
142
143
if ( forceExit === true ) {
143
144
ArrayPrototypePush ( argv , '--test-force-exit' ) ;
@@ -494,7 +495,8 @@ function watchFiles(testFiles, opts) {
494
495
// When file renamed (created / deleted) we need to update the watcher
495
496
if ( newFileName ) {
496
497
owners = new SafeSet ( ) . add ( newFileName ) ;
497
- watcher . filterFile ( resolve ( newFileName ) , owners ) ;
498
+ const resolveFileName = isAbsolute ( newFileName ) ? newFileName : resolve ( opts . cwd , newFileName ) ;
499
+ watcher . filterFile ( resolveFileName , owners ) ;
498
500
}
499
501
500
502
if ( ! newFileName && previousFileName ) {
@@ -562,6 +564,7 @@ function run(options = kEmptyObject) {
562
564
functionCoverage = 0 ,
563
565
execArgv = [ ] ,
564
566
argv = [ ] ,
567
+ cwd = process . cwd ( ) ,
565
568
} = options ;
566
569
567
570
if ( files != null ) {
@@ -586,6 +589,8 @@ function run(options = kEmptyObject) {
586
589
validateArray ( globPatterns , 'options.globPatterns' ) ;
587
590
}
588
591
592
+ validateString ( cwd , 'options.cwd' ) ;
593
+
589
594
if ( globPatterns ?. length > 0 && files ?. length > 0 ) {
590
595
throw new ERR_INVALID_ARG_VALUE (
591
596
'options.globPatterns' , globPatterns , 'is not supported when specifying \'options.files\'' ,
@@ -673,12 +678,9 @@ function run(options = kEmptyObject) {
673
678
lineCoverage : lineCoverage ,
674
679
branchCoverage : branchCoverage ,
675
680
functionCoverage : functionCoverage ,
681
+ cwd,
676
682
} ;
677
683
const root = createTestTree ( rootTestOptions , globalOptions ) ;
678
-
679
- // This const should be replaced by a run option in the future.
680
- const cwd = process . cwd ( ) ;
681
-
682
684
let testFiles = files ?? createTestFileList ( globPatterns , cwd ) ;
683
685
684
686
if ( shard ) {
@@ -731,7 +733,8 @@ function run(options = kEmptyObject) {
731
733
} ;
732
734
} else if ( isolation === 'none' ) {
733
735
if ( watch ) {
734
- filesWatcher = watchFiles ( testFiles , opts ) ;
736
+ const absoluteTestFiles = ArrayPrototypeMap ( testFiles , ( file ) => ( isAbsolute ( file ) ? file : resolve ( cwd , file ) ) ) ;
737
+ filesWatcher = watchFiles ( absoluteTestFiles , opts ) ;
735
738
runFiles = async ( ) => {
736
739
root . harness . bootstrapPromise = null ;
737
740
root . harness . buildPromise = null ;
@@ -744,7 +747,7 @@ function run(options = kEmptyObject) {
744
747
const { promise, resolve : finishBootstrap } = createDeferredPromise ( ) ;
745
748
746
749
await root . runInAsyncScope ( async ( ) => {
747
- const parentURL = getCWDURL ( ) . href ;
750
+ const parentURL = pathToFileURL ( cwd + sep ) . href ;
748
751
const cascadedLoader = esmLoader . getOrInitializeCascadedLoader ( ) ;
749
752
let topLevelTestCount = 0 ;
750
753
@@ -757,7 +760,7 @@ function run(options = kEmptyObject) {
757
760
758
761
for ( let i = 0 ; i < testFiles . length ; ++ i ) {
759
762
const testFile = testFiles [ i ] ;
760
- const fileURL = pathToFileURL ( testFile ) ;
763
+ const fileURL = pathToFileURL ( resolve ( cwd , testFile ) ) ;
761
764
const parent = i === 0 ? undefined : parentURL ;
762
765
let threw = false ;
763
766
let importError ;
0 commit comments