@@ -23,6 +23,8 @@ let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
23
23
debug = fn ;
24
24
} ) ;
25
25
const { createRequire, isBuiltin } = require ( 'module' ) ;
26
+ const { defaultGetFormatWithoutErrors } = require ( 'internal/modules/esm/get_format' ) ;
27
+ const { defaultResolve } = require ( 'internal/modules/esm/resolve' ) ;
26
28
27
29
// TODO(cjihrig): This file should not be exposed publicly, but register() does
28
30
// not handle internal loaders. Before marking this API as stable, one of the
@@ -88,11 +90,20 @@ async function resolve(specifier, context, nextResolve) {
88
90
if ( isBuiltin ( specifier ) ) {
89
91
mockSpecifier = ensureNodeScheme ( specifier ) ;
90
92
} else {
91
- // TODO(cjihrig): This try...catch should be replaced by defaultResolve(),
92
- // but there are some edge cases that caused the tests to fail on Windows.
93
+ let format ;
94
+
95
+ if ( context . parentURL ) {
96
+ format = defaultGetFormatWithoutErrors ( pathToFileURL ( context . parentURL ) ) ;
97
+ }
98
+
93
99
try {
94
- const req = createRequire ( context . parentURL ) ;
95
- specifier = pathToFileURL ( req . resolve ( specifier ) ) . href ;
100
+ if ( format === 'module' ) {
101
+ specifier = defaultResolve ( specifier , context ) . url ;
102
+ } else {
103
+ specifier = pathToFileURL (
104
+ createRequire ( context . parentURL ) . resolve ( specifier ) ,
105
+ ) . href ;
106
+ }
96
107
} catch {
97
108
const parentURL = normalizeReferrerURL ( context . parentURL ) ;
98
109
const parsedURL = URL . parse ( specifier , parentURL ) ?. href ;
0 commit comments