Skip to content

Commit

Permalink
test_runner: get format from parentURL as default or pass specifier a…
Browse files Browse the repository at this point in the history
…rgument as fallback
  • Loading branch information
syi0808 committed Jul 15, 2024
1 parent 94b1014 commit bad16b3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/test/mock_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
debug = fn;
});
const { createRequire, isBuiltin } = require('module');
const { defaultResolve } = require('internal/modules/esm/resolve');
const { defaultGetFormatWithoutErrors } = require('internal/modules/esm/get_format');
const { defaultResolve } = require('internal/modules/esm/resolve');

// TODO(cjihrig): This file should not be exposed publicly, but register() does
// not handle internal loaders. Before marking this API as stable, one of the
Expand Down Expand Up @@ -97,13 +97,13 @@ async function resolve(specifier, context, nextResolve) {
if (isBuiltin(specifier)) {
mockSpecifier = ensureNodeScheme(specifier);
} else {
const format = defaultGetFormatWithoutErrors(pathToFileURL(specifier));
const format = defaultGetFormatWithoutErrors(
pathToFileURL(context.parentURL ?? specifier)
);

try {
if(format === "module") {
specifier = pathToFileURL(
defaultResolve(specifier, context)
).href;
if (format === 'module') {
specifier = defaultResolve(specifier, context).url;
} else {
const req = createRequire(context.parentURL);
specifier = pathToFileURL(req.resolve(specifier)).href;
Expand Down Expand Up @@ -240,4 +240,4 @@ function sendAck(buf, status = kMockSuccess) {
AtomicsNotify(buf, 0);
}

module.exports = { initialize, load, resolve };
module.exports = { initialize, load, resolve };

0 comments on commit bad16b3

Please sign in to comment.