(specifier, context, nextResolve)
| 16 | const mocks = new SafeMap(); |
| 17 | |
| 18 | function 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 | |
| 45 | function load(url, context, nextLoad) { |
| 46 | debug('load hook entry, url = "%s", context = %o', url, context); |
no test coverage detected
searching dependent graphs…