-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathNodeBuiltinsAndOptionalModulesTests.mjs
More file actions
35 lines (29 loc) · 1.24 KB
/
NodeBuiltinsAndOptionalModulesTests.mjs
File metadata and controls
35 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
describe("Node built-in and optional module resolution", function () {
it("provides an in-memory polyfill for node:url", async function () {
// Dynamic import to exercise ResolveModuleCallback ESM path.
const mod = await import("node:url");
expect(mod).toBeDefined();
expect(typeof mod.fileURLToPath).toBe("function");
expect(typeof mod.pathToFileURL).toBe("function");
const p = mod.fileURLToPath("file:///foo/bar.txt");
expect(p === "/foo/bar.txt" || p === "foo/bar.txt").toBe(true);
const u = mod.pathToFileURL("/foo/bar.txt");
expect(u instanceof URL).toBe(true);
expect(u.protocol).toBe("file:");
});
it("creates an in-memory placeholder for likely-optional modules", async function () {
// Use a name that IsLikelyOptionalModule will treat as optional (no slashes, no extension).
const mod = await import("__ns_optional_test_module__");
expect(mod).toBeDefined();
expect(typeof mod.default).toBe("object");
let threw = false;
try {
// Any property access should throw according to the placeholder implementation.
// eslint-disable-next-line no-unused-expressions
mod.default.someProperty;
} catch (e) {
threw = true;
}
expect(threw).toBe(true);
});
});