MCPcopy Index your code
hub / github.com/nodejs/node / resolve

Function resolve

lib/internal/test_runner/mock/loader.js:18–43  ·  view source on GitHub ↗
(specifier, context, nextResolve)

Source from the content-addressed store, hash-verified

16const mocks = new SafeMap();
17
18function resolve(specifier, context, nextResolve) {
19 debug('resolve hook entry, specifier = "%s", context = %o', specifier, context);
20
21 const nextResolveResult = nextResolve(specifier, context);
22 const mockSpecifier = nextResolveResult.url;
23
24 const mock = mocks.get(mockSpecifier);
25 debug('resolve hook, specifier = "%s", mock = %o', specifier, mock);
26
27 if (mock?.active !== true) {
28 return nextResolveResult;
29 }
30
31 const url = new URL(mockSpecifier);
32 url.searchParams.set(kMockSearchParam, mock.localVersion);
33
34 if (!mock.cache) {
35 // With ESM, we can't remove modules from the cache. Bump the module's
36 // version instead so that the next import will be uncached.
37 mock.localVersion++;
38 }
39
40 const { href } = url;
41 debug('resolve hook finished, url = "%s"', href);
42 return { __proto__: null, url: href, format: nextResolveResult.format };
43}
44
45function load(url, context, nextLoad) {
46 debug('load hook entry, url = "%s", context = %o', url, context);

Callers 9

setupCoverageFunction · 0.50
constructorMethod · 0.50
onChangedFunction · 0.50
runFunction · 0.50
checkMethod · 0.50
doneMethod · 0.50
runMethod · 0.50
cbFunction · 0.50

Calls 3

getMethod · 0.65
debugFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…