mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 06:19:07 +00:00

PR-URL: https://github.com/nodejs/node/pull/55698 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com>
30 lines
676 B
JavaScript
30 lines
676 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { registerHooks } = require('module');
|
|
|
|
// Test that shortCircuit works for the resolve hook.
|
|
const source1 = 'module.exports = "modified"';
|
|
const hook1 = registerHooks({
|
|
load: common.mustNotCall(),
|
|
});
|
|
const hook2 = registerHooks({
|
|
load(url, context, nextLoad) {
|
|
if (url.includes('empty')) {
|
|
return {
|
|
format: 'commonjs',
|
|
source: source1,
|
|
shortCircuit: true,
|
|
};
|
|
}
|
|
return nextLoad(url, context);
|
|
},
|
|
});
|
|
|
|
const value = require('../fixtures/empty.js');
|
|
assert.strictEqual(value, 'modified');
|
|
|
|
hook1.deregister();
|
|
hook2.deregister();
|