node/test/module-hooks/test-module-hooks-load-url-change-import.mjs
Antoine du Hamel 0457bfee2c
test: forbid use of named imports for fixtures
PR-URL: https://github.com/nodejs/node/pull/61228
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
2026-01-01 23:48:26 +00:00

25 lines
854 B
JavaScript

import { mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import { registerHooks } from 'node:module';
import * as fixtures from '../common/fixtures.mjs';
// This tests shows the url parameter in `load` can be changed in the `nextLoad` call
// It changes `foo` package name into `redirected-fs` and then loads `redirected-fs`
const hook = registerHooks({
resolve: mustCall((specifier, context, nextResolve) => {
assert.strictEqual(specifier, 'foo');
return {
url: 'foo://bar',
shortCircuit: true,
};
}),
load: mustCall(function load(url, context, nextLoad) {
assert.strictEqual(url, 'foo://bar');
return nextLoad(fixtures.fileURL('module-hooks', 'redirected-fs.js').href, context);
}),
});
assert.strictEqual((await import('foo')).exports_for_test, 'redirected fs');
hook.deregister();