mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 14:25:18 +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>
28 lines
755 B
JavaScript
28 lines
755 B
JavaScript
import '../common/index.mjs';
|
|
import assert from 'node:assert';
|
|
import { registerHooks } from 'node:module';
|
|
import process from 'node:process';
|
|
|
|
// This tests that builtins can be redirected to another builtin.
|
|
// Pick a builtin that's unlikely to be loaded already - like zlib.
|
|
assert(!process.moduleLoadList.includes('NativeModule zlib'));
|
|
|
|
const hook = registerHooks({
|
|
resolve(specifier, context, nextLoad) {
|
|
if (specifier === 'node:assert') {
|
|
return {
|
|
url: 'node:zlib',
|
|
shortCircuit: true,
|
|
};
|
|
}
|
|
},
|
|
});
|
|
|
|
|
|
// Check assert, which is already loaded.
|
|
// zlib.createGzip is a function.
|
|
const redirected = await import('node:assert');
|
|
assert.strictEqual(typeof redirected.createGzip, 'function');
|
|
|
|
hook.deregister();
|