MCPcopy Create free account
hub / github.com/nodejs/node / resolve

Function resolve

test/fixtures/es-module-loaders/hooks-input.mjs:13–56  ·  view source on GitHub ↗
(specifier, context, next)

Source from the content-addressed store, hash-verified

11let loadCalls = 0;
12
13export async function resolve(specifier, context, next) {
14 resolveCalls++;
15 let url;
16
17 if (resolveCalls === 1) {
18 url = new URL(specifier).href;
19 assert.match(specifier, /json-modules\.mjs$/);
20
21 if (!(/\[eval\d*\]$/).test(context.parentURL)) {
22 assert.strictEqual(context.parentURL, undefined);
23 }
24
25 assert.deepStrictEqual(context.importAttributes, {});
26 } else if (resolveCalls === 2) {
27 url = new URL(specifier, context.parentURL).href;
28 assert.match(specifier, /experimental\.json$/);
29 assert.match(context.parentURL, /json-modules\.mjs$/);
30 assert.deepStrictEqual(context.importAttributes, {
31 type: 'json',
32 });
33 } else {
34 throw new Error(`Unexpected resolve call: ${specifier}`);
35 }
36
37 // Ensure `context` has all and only the properties it's supposed to
38 assert.deepStrictEqual(Reflect.ownKeys(context), [
39 'conditions',
40 'importAttributes',
41 'parentURL',
42 'importAssertions',
43 ]);
44 assert.ok(Array.isArray(context.conditions));
45 assert.strictEqual(typeof next, 'function');
46
47 const returnValue = {
48 url,
49 format: 'test',
50 shortCircuit: true,
51 }
52
53 writeSync(1, JSON.stringify(returnValue) + '\n'); // For the test to validate when it parses stdout
54
55 return returnValue;
56}
57
58export async function load(url, context, next) {
59 loadCalls++;

Callers

nothing calls this directly

Calls 4

writeSyncFunction · 0.90
matchMethod · 0.65
testMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected