Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more readable test
  • Loading branch information
awto committed Jan 16, 2025
commit 5451b5823bfd38ff548e93f80618184275d7fe61
9 changes: 5 additions & 4 deletions test/module-hooks/test-module-hooks-load-url-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ const { registerHooks } = require('module');
const fixtures = require('../common/fixtures');

// 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(specifier, context, nextLoad) {
assert.strictEqual(specifier, 'rfs');
assert.strictEqual(specifier, 'foo');
return {
url: 'file:///rfs',
url: 'file:///foo',
shortCircuit: true,
};
},
load: common.mustCall(function load(url, context, nextLoad) {
assert.strictEqual(url, 'file:///rfs');
assert.strictEqual(url, 'file:///foo');
return nextLoad(
fixtures.fileURL('module-hooks', `redirected-fs.js`).href,
context
);
}),
});

assert.strictEqual(require('rfs').exports_for_test, 'redirected fs');
assert.strictEqual(require('foo').exports_for_test, 'redirected fs');

hook.deregister();