The best way to control Claude Code, Codex and more from any computer or phone

main
ts 61 lines 2.13 KB
Raw
1 import path from "node:path";
2 import { describe, expect, it } from "vitest";
3 import { createMiniflareFromRolldown } from "../../../../cloudflare-test-tools/src/miniflare/miniflare.ts";
4 import { buildFixture } from "./utils/build-fixture.ts";
5
6 describe("module resolution", async () => {
7 const built = await buildFixture({
8 fixture: "module-resolution/index.ts",
9 inputOptions: {
10 resolve: {
11 alias: {
12 "@alias/test": path.resolve("test/fixtures/module-resolution/aliasing.ts"),
13 },
14 },
15 },
16 });
17
18 it("supports package exports and subpath exports", async () => {
19 await using miniflare = await createMiniflareFromRolldown(built.output, {
20 compatibilityDate: "2025-07-01",
21 });
22
23 expect(await miniflare.fetchJson<{ packageMessage: string }>("/package-export")).toEqual({
24 packageMessage: "package export",
25 });
26 expect(await miniflare.fetchJson<{ featureMessage: string }>("/package-subpath")).toEqual({
27 featureMessage: "package subpath",
28 });
29 });
30
31 it("resolves packages that rely on mainFields when no exports map is present", async () => {
32 await using miniflare = await createMiniflareFromRolldown(built.output, {
33 compatibilityDate: "2025-07-01",
34 });
35
36 expect(await miniflare.fetchJson<{ legacyMessage: string }>("/package-main-fields")).toEqual({
37 legacyMessage: "browser field",
38 });
39 });
40
41 it("supports explicit and extensionless resolution for js and cjs modules", async () => {
42 await using miniflare = await createMiniflareFromRolldown(built.output, {
43 compatibilityDate: "2025-07-01",
44 });
45
46 expect(await miniflare.fetchJson<{ helloWorldExt: string }>("/require-ext")).toEqual({
47 helloWorldExt: "hello (.js) world (.cjs)",
48 });
49 expect(await miniflare.fetchJson<{ helloWorldNoExt: string }>("/require-no-ext")).toEqual({
50 helloWorldNoExt: "hello (.js) world (.cjs)",
51 });
52 });
53
54 it("coexists with user aliases", async () => {
55 await using miniflare = await createMiniflareFromRolldown(built.output, {
56 compatibilityDate: "2025-07-01",
57 });
58
59 expect(await miniflare.fetchText("/@alias/test")).toBe("OK!");
60 });
61 });