Previously the resolve hook can be invoked twice from the synthetic module evaluation step of imported CJS in the extra module._load() call that's invoked on the resolved full path. Add an option to avoid it, since the resolution and loading has already been done before. PR-URL: https://github.com/nodejs/node/pull/61529 Fixes: https://github.com/nodejs/node/issues/57125 Refs: https://github.com/nodejs/node/issues/55808 Refs: https://github.com/nodejs/node/issues/56241 Reviewed-By: Jacob Smith <jacob@frende.me>
18 lines
549 B
JavaScript
18 lines
549 B
JavaScript
'use strict';
|
|
// Test that resolve hook in imported CJS only gets invoked once.
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { registerHooks } = require('module');
|
|
|
|
const hook = registerHooks({
|
|
resolve: common.mustCall(function(specifier, context, nextResolve) {
|
|
assert.strictEqual(specifier, '../fixtures/value.cjs');
|
|
return nextResolve(specifier, context);
|
|
}, 1),
|
|
});
|
|
|
|
import('../fixtures/value.cjs').then(common.mustCall((result) => {
|
|
assert.strictEqual(result.value, 42);
|
|
hook.deregister();
|
|
}));
|