@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 96 lines 3.43 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Path from "effect/Path";
7 import { MinimumLogLevel } from "effect/References";
8 import * as pathe from "pathe";
9 import { cloneFixture } from "../Utils/Fixture.ts";
10 import { expectUrlContains } from "../Utils/Http.ts";
11
12 const { test } = Test.make({ providers: Cloudflare.providers(), dev: true });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 const fixtureDir = pathe.resolve(
17 import.meta.dirname,
18 "../../../../../examples/cloudflare-website-vocs",
19 );
20 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
21
22 describe.concurrent(
23 "Vocs dev",
24 { tags: ["provider:cloudflare", "provider:cloudflare:website", "local"] },
25 () => {
26 test.provider(
27 "Vocs dev: serves SSR, MDX and assets locally and responds to source edits",
28 (stack) =>
29 Effect.gen(function* () {
30 const fs = yield* FileSystem.FileSystem;
31 const path = yield* Path.Path;
32
33 yield* stack.destroy();
34
35 const rootDir = yield* cloneFixture(fixtureDir, {
36 prefix: "alchemy-vocs-dev-",
37 tempRoot,
38 entries: ["package.json", "public", "src", "tsconfig.json", "vocs.config.ts"],
39 });
40
41 const site = yield* stack.deploy(
42 Cloudflare.Website.Vocs("VocsLocal", {
43 rootDir,
44 dev: { port: 0 },
45 memo: {
46 include: ["src/**", "public/**", "package.json", "tsconfig.json", "vocs.config.ts"],
47 },
48 }),
49 );
50
51 expect(site.url).toMatch(/^http:\/\/localhost:\d+/);
52 yield* expectUrlContains(`${site.url!}/`, "Alchemy with Vocs", {
53 timeout: "180 seconds",
54 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
55 label: "Vocs dev SSR home",
56 });
57 yield* expectUrlContains(`${site.url!}/guide`, "Deployment guide", {
58 timeout: "60 seconds",
59 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
60 label: "Vocs dev MDX guide",
61 });
62 yield* expectUrlContains(
63 `${site.url!}/hello.txt`,
64 "hello from the Vocs public directory",
65 {
66 timeout: "60 seconds",
67 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
68 label: "Vocs dev public asset",
69 },
70 );
71
72 const pagePath = path.join(rootDir, "src/pages/index.mdx");
73 const page = yield* fs.readFileString(pagePath);
74 yield* fs.writeFileString(
75 pagePath,
76 page.replace(
77 "No Wrangler configuration or Vocs adapter setup is required.",
78 "This Vocs page was updated through HMR.",
79 ),
80 );
81 yield* expectUrlContains(
82 `${site.url!}/?__alchemy_cb=${Date.now()}`,
83 "This Vocs page was updated through HMR.",
84 {
85 timeout: "120 seconds",
86 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
87 label: "Vocs dev page after source edit",
88 },
89 );
90
91 yield* stack.destroy();
92 }).pipe(logLevel),
93 { timeout: 300_000 },
94 );
95 },
96 );