|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// This tests that when builtins that demand the `node:` prefix are |
| 4 | +// required, the URL that gets passed to the load hook is still |
| 5 | +// the one with the `node:` prefix, and the one with the prefix |
| 6 | +// stripped for internal lookups don't get passed into the hooks. |
| 7 | + |
| 8 | +const common = require('../common'); |
| 9 | +const assert = require('assert'); |
| 10 | +const { registerHooks } = require('module'); |
| 11 | + |
| 12 | +const schemelessBlockList = new Set([ |
| 13 | + 'sea', |
| 14 | + 'sqlite', |
| 15 | + 'test', |
| 16 | + 'test/reporters', |
| 17 | +]); |
| 18 | + |
| 19 | +const testModules = []; |
| 20 | +for (const mod of schemelessBlockList) { |
| 21 | + testModules.push(`node:${mod}`); |
| 22 | +} |
| 23 | + |
| 24 | +const hook = registerHooks({ |
| 25 | + resolve: common.mustCall((specifier, context, nextResolve) => { |
| 26 | + return nextResolve(specifier, context); |
| 27 | + }, testModules.length), |
| 28 | + load: common.mustCall(function load(url, context, nextLoad) { |
| 29 | + assert.match(url, /^node:/); |
| 30 | + assert.strictEqual(schemelessBlockList.has(url.slice(5, url.length)), true); |
| 31 | + const result = nextLoad(url, context); |
| 32 | + assert.strictEqual(result.source, null); |
| 33 | + return { |
| 34 | + source: 'throw new Error("I should not be thrown because the loader ignores user-supplied source for builtins")', |
| 35 | + format: 'builtin', |
| 36 | + }; |
| 37 | + }, testModules.length), |
| 38 | +}); |
| 39 | + |
| 40 | +for (const mod of testModules) { |
| 41 | + require(mod); |
| 42 | +} |
| 43 | + |
| 44 | +hook.deregister(); |
0 commit comments