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
| 1 | import * as fs from "node:fs/promises"; |
| 2 | import * as path from "node:path"; |
| 3 | import { dev } from "astro"; |
| 4 | import type { HMRPayload } from "vite"; |
| 5 | import { expect, it, vi } from "vitest"; |
| 6 | import { distilledCloudflare } from "../integration.ts"; |
| 7 | |
| 8 | it("evaluates the Worker entry and image page without replacing cold SSR dependencies", async () => { |
| 9 | // A fresh root gives every run an empty optimizer cache while keeping the |
| 10 | // package's dependencies reachable through its parent node_modules. |
| 11 | const tempRoot = path.resolve(import.meta.dirname, "../../.cache/astro-cold-start"); |
| 12 | await fs.mkdir(tempRoot, { recursive: true }); |
| 13 | const root = await fs.mkdtemp(path.join(tempRoot, "app-")); |
| 14 | const reloads: Array<unknown> = []; |
| 15 | let server: Awaited<ReturnType<typeof dev>> | undefined; |
| 16 | try { |
| 17 | await fs.mkdir(path.join(root, "src/pages"), { recursive: true }); |
| 18 | await fs.mkdir(path.join(root, "node_modules/@alchemy.run"), { recursive: true }); |
| 19 | await fs.symlink( |
| 20 | path.resolve(import.meta.dirname, "../../.."), |
| 21 | path.join(root, "node_modules/@alchemy.run/frontend-frameworks"), |
| 22 | "junction", |
| 23 | ); |
| 24 | await fs.writeFile(path.join(root, "package.json"), '{"type":"module"}'); |
| 25 | await fs.writeFile( |
| 26 | path.join(root, "src/pages/index.astro"), |
| 27 | `--- |
| 28 | import { Image } from "astro:assets"; |
| 29 | --- |
| 30 | <h1>Hello</h1> |
| 31 | <Image src="https://example.com/a.png" alt="" width={1} height={1} /> |
| 32 | `, |
| 33 | ); |
| 34 | server = await dev({ |
| 35 | root, |
| 36 | configFile: false, |
| 37 | logLevel: "warn", |
| 38 | server: { port: 0, host: "127.0.0.1" }, |
| 39 | integrations: [ |
| 40 | distilledCloudflare({ |
| 41 | vite: { |
| 42 | compatibilityDate: "2026-03-10", |
| 43 | compatibilityFlags: ["nodejs_compat"], |
| 44 | worker: { name: "astro-cold-start-test", bindings: [] }, |
| 45 | }, |
| 46 | }), |
| 47 | ], |
| 48 | vite: { |
| 49 | plugins: [ |
| 50 | { |
| 51 | name: "test:capture-ssr-reloads", |
| 52 | enforce: "pre", |
| 53 | configureServer(viteServer) { |
| 54 | const hot = viteServer.environments.ssr.hot; |
| 55 | const send = hot.send.bind(hot); |
| 56 | vi.spyOn(hot, "send").mockImplementation( |
| 57 | (payload: HMRPayload | string, data?: unknown) => { |
| 58 | if (typeof payload === "string") return send(payload, data); |
| 59 | if (payload.type === "full-reload") { |
| 60 | reloads.push(payload); |
| 61 | } |
| 62 | return send(payload); |
| 63 | }, |
| 64 | ); |
| 65 | }, |
| 66 | }, |
| 67 | ], |
| 68 | }, |
| 69 | }); |
| 70 | for (let request = 0; request < 2; request++) { |
| 71 | const response = await fetch(`http://127.0.0.1:${server.address.port}/`, { |
| 72 | signal: AbortSignal.timeout(10_000), |
| 73 | }); |
| 74 | expect(response.status).toBe(200); |
| 75 | const html = await response.text(); |
| 76 | // Astro's dev server annotates elements with `data-astro-source-*`. |
| 77 | expect(html).toMatch(/<h1[^>]*>Hello<\/h1>/); |
| 78 | expect(html).toContain("<img"); |
| 79 | } |
| 80 | // A 200 alone is insufficient: entry export detection can fail while |
| 81 | // Astro later recovers enough to serve the page (alchemy#1981). |
| 82 | expect(reloads).toEqual([]); |
| 83 | } finally { |
| 84 | await server?.stop(); |
| 85 | await fs.rm(root, { recursive: true, force: true }); |
| 86 | } |
| 87 | }, 60_000); |