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 aa8fe42
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/test/mock_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const { normalizeReferrerURL } = require('internal/modules/helpers');
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 { createRequire, isBuiltin, Module } = require('module');
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 aa8fe42

Please sign in to comment.