File
Blob: test/hono-routing.worker.test.ts
| 1 | import { beforeAll, describe, expect, it } from "vitest"; |
| 2 | import { env, exports as workerExports } from "cloudflare:workers"; |
| 3 | |
| 4 | import { ensureD1Migrations } from "./util/d1Setup"; |
| 5 | import { setupRepoForTests } from "./util/repoSeed"; |
| 6 | |
| 7 | beforeAll(async () => { |
| 8 | await ensureD1Migrations(env); |
| 9 | }); |
| 10 | |
| 11 | describe("Hono routing compatibility", () => { |
| 12 | it("renders the root page and the shared 404 fallback", async () => { |
| 13 | const root = await workerExports.default.fetch("https://example.com/"); |
| 14 | expect(root.status).toBe(200); |
| 15 | expect(root.headers.get("X-Page-Renderer")).toBe("react-ssr"); |
| 16 | |
| 17 | const missing = await workerExports.default.fetch("https://example.com/does/not/exist"); |
| 18 | expect(missing.status).toBe(404); |
| 19 | expect(missing.headers.get("X-Page-Renderer")).toBe("react-ssr"); |
| 20 | }); |
| 21 | |
| 22 | it("keeps auth precedence and trailing-slash route matching", async () => { |
| 23 | const auth = await workerExports.default.fetch("https://example.com/auth/"); |
| 24 | expect(auth.status).toBe(200); |
| 25 | expect(auth.headers.get("X-Page-Renderer")).toBe("react-ssr"); |
| 26 | |
| 27 | const owner = "hono-routing-owner"; |
| 28 | await setupRepoForTests(env, owner, "placeholder"); |
| 29 | const ownerOverview = await workerExports.default.fetch(`https://example.com/${owner}/`); |
| 30 | expect(ownerOverview.status).toBe(200); |
| 31 | expect(ownerOverview.headers.get("X-Page-Renderer")).toBe("react-ssr"); |
| 32 | expect(await ownerOverview.text()).toContain(owner); |
| 33 | }); |
| 34 | |
| 35 | it("keeps unsupported methods on the rendered 404 fallback", async () => { |
| 36 | const postOwner = await workerExports.default.fetch("https://example.com/hono-routing-owner", { |
| 37 | method: "POST", |
| 38 | }); |
| 39 | expect(postOwner.status).toBe(404); |
| 40 | expect(postOwner.headers.get("X-Page-Renderer")).toBe("react-ssr"); |
| 41 | }); |
| 42 | }); |