| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { hasNodejsCompat, sanitizePath } from "../utils.ts"; |
| 3 | |
| 4 | describe("utils", () => { |
| 5 | describe("sanitizePath", () => { |
| 6 | it("strips query strings", () => { |
| 7 | expect(sanitizePath("/tmp/example.wasm?init")).toBe("/tmp/example.wasm"); |
| 8 | expect(sanitizePath("/tmp/example.wasm?module")).toBe( |
| 9 | "/tmp/example.wasm", |
| 10 | ); |
| 11 | }); |
| 12 | |
| 13 | it("strips hashes", () => { |
| 14 | expect(sanitizePath("/tmp/example.wasm#fragment")).toBe( |
| 15 | "/tmp/example.wasm", |
| 16 | ); |
| 17 | expect(sanitizePath("/tmp/example.wasm?init#fragment")).toBe( |
| 18 | "/tmp/example.wasm", |
| 19 | ); |
| 20 | }); |
| 21 | }); |
| 22 | |
| 23 | describe("hasNodejsCompat", () => { |
| 24 | it("detects nodejs_compat", () => { |
| 25 | expect(hasNodejsCompat(["nodejs_compat"])).toBe(true); |
| 26 | }); |
| 27 | |
| 28 | it("detects nodejs_compat_v2", () => { |
| 29 | expect(hasNodejsCompat(["nodejs_compat_v2"])).toBe(true); |
| 30 | }); |
| 31 | |
| 32 | it("detects Node.js compatibility enabled by date", () => { |
| 33 | expect(hasNodejsCompat(undefined, "2026-08-31")).toBe(true); |
| 34 | }); |
| 35 | |
| 36 | it("honors an explicit opt-out on a default-on date", () => { |
| 37 | expect(hasNodejsCompat(["no_nodejs_compat"], "2026-08-31")).toBe(false); |
| 38 | }); |
| 39 | |
| 40 | it("returns false without compatibility flags", () => { |
| 41 | expect(hasNodejsCompat()).toBe(false); |
| 42 | expect(hasNodejsCompat(["durable_object_alarms"])).toBe(false); |
| 43 | }); |
| 44 | }); |
| 45 | }); |