The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { makeCloudflareTarget, NITRO_HANDLER_SPECIFIER, NITRO_PRESET } from "../cloudflare.ts"; |
| 3 | import type { NitroConfigSlice } from "../UserConfig.ts"; |
| 4 | |
| 5 | describe("makeCloudflareTarget", () => { |
| 6 | it("declares the cloudflare platform, the nitro preset, and workerd bundle settings", () => { |
| 7 | const target = makeCloudflareTarget(); |
| 8 | expect(target.platform).toBe("cloudflare"); |
| 9 | expect(target.nitroPreset).toBe(NITRO_PRESET); |
| 10 | expect(target.bundle?.conditions).toEqual(["workerd", "worker", "module", "browser"]); |
| 11 | expect(target.bundle?.external).toEqual(["cloudflare:"]); |
| 12 | // No wholesale build and no finishing pass: nitro's cloudflare_module |
| 13 | // output is already workerd ESM. |
| 14 | expect(target.build).toBeUndefined(); |
| 15 | expect(target.finish).toBeUndefined(); |
| 16 | }); |
| 17 | |
| 18 | it("surfaces a configured main through the generic user-entry carriage", () => { |
| 19 | expect(makeCloudflareTarget().entry).toBeUndefined(); |
| 20 | expect(makeCloudflareTarget({ main: "./worker-entry.ts" }).entry).toEqual({ |
| 21 | main: "./worker-entry.ts", |
| 22 | }); |
| 23 | }); |
| 24 | |
| 25 | it("enforces wrangler-free nitro config: deployConfig off, nodeCompat on", () => { |
| 26 | const target = makeCloudflareTarget(); |
| 27 | const config: NitroConfigSlice = {}; |
| 28 | target.configureNitro?.(config, { root: "/project" }); |
| 29 | expect(config.cloudflare).toEqual({ |
| 30 | deployConfig: false, |
| 31 | nodeCompat: true, |
| 32 | }); |
| 33 | expect(config.entry).toBeUndefined(); |
| 34 | }); |
| 35 | |
| 36 | it("preserves foreign cloudflare keys while overriding the owned ones", () => { |
| 37 | const target = makeCloudflareTarget(); |
| 38 | const config: NitroConfigSlice = { |
| 39 | cloudflare: { deployConfig: true, pages: { routes: [] } }, |
| 40 | }; |
| 41 | target.configureNitro?.(config, { root: "/project" }); |
| 42 | expect(config.cloudflare).toEqual({ |
| 43 | deployConfig: false, |
| 44 | nodeCompat: true, |
| 45 | pages: { routes: [] }, |
| 46 | }); |
| 47 | }); |
| 48 | |
| 49 | it("honors an explicit nodeCompat opt-out", () => { |
| 50 | const target = makeCloudflareTarget({ nodeCompat: false }); |
| 51 | const config: NitroConfigSlice = {}; |
| 52 | target.configureNitro?.(config, { root: "/project" }); |
| 53 | expect(config.cloudflare).toEqual({ |
| 54 | deployConfig: false, |
| 55 | nodeCompat: false, |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | it("does NOT wire the user entry at the config level (prerender-clone safety)", () => { |
| 60 | // The framework package sets the entry on the nitro INSTANCE at |
| 61 | // `nitro:init`; a config-level entry would leak into the prerenderer's |
| 62 | // Node-preset clone, which cannot load `cloudflare:` imports. |
| 63 | const target = makeCloudflareTarget({ main: "./worker-entry.ts" }); |
| 64 | const config: NitroConfigSlice = {}; |
| 65 | target.configureNitro?.(config, { |
| 66 | root: "/project", |
| 67 | entry: "/project/worker-entry.ts", |
| 68 | }); |
| 69 | expect(config.entry).toBeUndefined(); |
| 70 | }); |
| 71 | |
| 72 | it("exports the wrappable-handler specifier for user entries", () => { |
| 73 | expect(NITRO_HANDLER_SPECIFIER).toBe("nitropack/presets/cloudflare/runtime/cloudflare-module"); |
| 74 | }); |
| 75 | }); |