The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import { CloudflareEnvironment } from "@alchemy.run/cloudflare/CloudflareEnvironment"; |
| 3 | import { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as pathe from "pathe"; |
| 8 | import { cloneFixture } from "../Utils/Fixture.ts"; |
| 9 | import { expectClientChunkContains, expectUrlContains, expectUrlHeader } from "../Utils/Http.ts"; |
| 10 | import { expectWorkerExists, waitForWorkerToBeDeleted } from "../Utils/Worker.ts"; |
| 11 | |
| 12 | const { test } = Test.make({ providers: Cloudflare.providers() }); |
| 13 | |
| 14 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 15 | |
| 16 | const fixtureDir = pathe.resolve(import.meta.dirname, "fixtures", "vinext-app"); |
| 17 | const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp"); |
| 18 | const publicMarker = "VINEXT_PUBLIC_ENV_MARKER"; |
| 19 | |
| 20 | describe.concurrent( |
| 21 | "Vinext", |
| 22 | { |
| 23 | tags: ["provider:cloudflare", "provider:cloudflare:kv", "provider:cloudflare:website", "live"], |
| 24 | }, |
| 25 | () => { |
| 26 | test.provider( |
| 27 | "Vinext: deploys App Router SSR, inlines declared public env and serves public files through ASSETS", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | const { accountId } = yield* yield* CloudflareEnvironment; |
| 31 | |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 35 | prefix: "alchemy-vinext-", |
| 36 | tempRoot, |
| 37 | entries: [".gitignore", "package.json", "vite.config.ts", "app", "public", "worker"], |
| 38 | }); |
| 39 | |
| 40 | const site = yield* stack.deploy( |
| 41 | Cloudflare.Website.Vinext("VinextSite", { |
| 42 | rootDir, |
| 43 | workersDev: { enabled: true }, |
| 44 | env: { NEXT_PUBLIC_SITE_MARKER: publicMarker }, |
| 45 | memo: { |
| 46 | include: ["app/**", "public/**", "worker/**", "package.json", "vite.config.ts"], |
| 47 | }, |
| 48 | }), |
| 49 | ); |
| 50 | expect(site.url).toBeDefined(); |
| 51 | yield* expectWorkerExists(site.workerName, accountId); |
| 52 | |
| 53 | yield* expectUrlContains(`${site.url!}/`, "VINEXT_PAGE_MARKER", { |
| 54 | timeout: "90 seconds", |
| 55 | label: "vinext SSR home", |
| 56 | }); |
| 57 | |
| 58 | // The declared `NEXT_PUBLIC_*` value is inlined into the deployed |
| 59 | // client bundle. |
| 60 | yield* expectClientChunkContains( |
| 61 | site.url!, |
| 62 | pathe.join(rootDir, "dist", "client"), |
| 63 | publicMarker, |
| 64 | { timeout: "60 seconds", label: "vinext public env" }, |
| 65 | ); |
| 66 | |
| 67 | // Static asset from `public/`. |
| 68 | yield* expectUrlContains(`${site.url!}/robots.txt`, "User-agent", { |
| 69 | timeout: "60 seconds", |
| 70 | label: "vinext static asset", |
| 71 | }); |
| 72 | |
| 73 | // The same file read by a server route through the `ASSETS` binding. |
| 74 | yield* expectUrlContains(`${site.url!}/api/asset`, "User-agent", { |
| 75 | timeout: "60 seconds", |
| 76 | label: "vinext ASSETS binding", |
| 77 | }); |
| 78 | |
| 79 | yield* stack.destroy(); |
| 80 | yield* waitForWorkerToBeDeleted(site.workerName, accountId); |
| 81 | }).pipe(logLevel), |
| 82 | { timeout: 300_000 }, |
| 83 | ); |
| 84 | |
| 85 | // alchemy-run/alchemy#2234: the documented custom `main` was rejected |
| 86 | // beside the source provider (`"source" is mutually exclusive with "main"`). |
| 87 | test.provider( |
| 88 | "Vinext: deploys a custom main", |
| 89 | (stack) => |
| 90 | Effect.gen(function* () { |
| 91 | const { accountId } = yield* yield* CloudflareEnvironment; |
| 92 | |
| 93 | yield* stack.destroy(); |
| 94 | |
| 95 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 96 | prefix: "alchemy-vinext-main-", |
| 97 | tempRoot, |
| 98 | entries: [".gitignore", "package.json", "vite.config.ts", "app", "public", "worker"], |
| 99 | }); |
| 100 | |
| 101 | const site = yield* stack.deploy( |
| 102 | Cloudflare.Website.Vinext("VinextCustomMain", { |
| 103 | rootDir, |
| 104 | main: "worker/custom.ts", |
| 105 | workersDev: { enabled: true }, |
| 106 | memo: { |
| 107 | include: ["app/**", "public/**", "worker/**", "package.json", "vite.config.ts"], |
| 108 | }, |
| 109 | }), |
| 110 | ); |
| 111 | |
| 112 | yield* expectUrlHeader(`${site.url!}/`, "x-alchemy-entry", "custom", { |
| 113 | timeout: "90 seconds", |
| 114 | label: "vinext custom main", |
| 115 | }); |
| 116 | yield* expectUrlContains(`${site.url!}/`, "VINEXT_PAGE_MARKER", { |
| 117 | timeout: "60 seconds", |
| 118 | label: "vinext SSR through the custom main", |
| 119 | }); |
| 120 | |
| 121 | yield* stack.destroy(); |
| 122 | yield* waitForWorkerToBeDeleted(site.workerName, accountId); |
| 123 | }).pipe(logLevel), |
| 124 | { timeout: 300_000 }, |
| 125 | ); |
| 126 | }, |
| 127 | ); |