| 4 | import { createResolve } from "./hooks.ts"; |
| 5 |
| 6 | const remoteContext: ResolveHookContext = { |
| 7 | conditions: [], importAttributes: {}, parentURL: "https://modules.test/main.mjs", |
| 8 | }; |
| 9 | const resolve = createResolve((url) => ({ |
| 10 | source: "export default 1;", contentType: "application/javascript", url, finalUrl: url, redirectChain: [url], |
| 11 | })); |
| 12 |
| 13 | describe("node built-ins and local packages from remote modules", () => { |
| 14 | it("delegates built-ins without interpreting them as relative URLs", () => { |
| 15 | for (const specifier of ["node:fs", "fs/promises", "http", "node:path"]) { |
| 16 | const result = resolve(specifier, remoteContext, (specifier, context) => { |
| 17 | assert.ok(context?.parentURL?.startsWith("file:")); |
| 18 | return { url: specifier, shortCircuit: true }; |
| 19 | }); |
| 20 | assert.equal(result.url, specifier); |
| 21 | } |
| 22 | }); |
| 23 |
| 24 | it("resolves installed packages from the project instead of the HTTP parent", () => { |
| 25 | const result = resolve("typescript", remoteContext, (specifier, context) => { |
| 26 | assert.ok(context?.parentURL?.startsWith("file:")); |
| 27 | return { url: specifier }; |
| 28 | }); |
| 29 | assert.equal(result.url, "typescript"); |
| 30 | }); |
| 31 |
| 32 | it("resolves remote relative imports without involving the local resolver", () => { |
| 33 | const result = resolve("./util.js", remoteContext, () => { |
| 34 | assert.fail("Remote dependencies must not reach the local resolver"); |
| 35 | }); |
| 36 | assert.equal(result.url, "https://modules.test/util.js"); |
| 37 | }); |
| 38 | }); |
| 39 |