// A real, unmodified Hono app (hono + @hono/node-server from npm, pinned by // demo/apps/hono/package-lock.json) runs in the runtime from its snapshot. Its answers for // public/ through serveStatic must match tests/goldens/http/hono.json, what the pinned // Node answered to demo/apps/hono/requests.json (recorded by `node scripts/golden.mjs`). import { test, expect, type Page } from "@playwright/test"; import { appUrl, recordExchanges, type RecordedRequest } from "./http-golden"; import { readGolden } from "../scripts/golden-files.ts"; const GOLDEN = readGolden("http", "hono"); async function bootHono(page: Page): Promise { await page.goto("/demo/hono.html"); await expect(page.frameLocator("#app").locator("#hi")).toBeVisible({ timeout: 20_000 }); return await appUrl(page); } test("the iframe renders Hono's HTML and the listen callback logs", async ({ page }) => { await bootHono(page); await expect(page.frameLocator("#app").locator("#hi")).toHaveText("Hello from Hono"); await expect(page.locator("#out")).toContainText("listening on 3000"); }); test("a JSON POST round-trips through c.req.json()", async ({ page }) => { const base = await bootHono(page); const res = await page.evaluate(async (base) => { const r = await fetch(base + "echo", { method: "POST", headers: { "content-type": "application/json" }, body: '{"a":1}', }); return { status: r.status, json: await r.json() }; }, base); expect(res).toEqual({ status: 200, json: { got: { a: 1 } } }); }); test("a ReadableStream body arrives whole", async ({ page }) => { const base = await bootHono(page); const text = await page.evaluate(async (base) => (await fetch(base + "stream")).text(), base); expect(text).toBe("ab"); }); test("an unknown route gets Hono's default 404", async ({ page }) => { const base = await bootHono(page); const res = await page.evaluate(async (base) => { const r = await fetch(base + "nope"); return { status: r.status, text: await r.text() }; }, base); expect(res).toEqual({ status: 404, text: "404 Not Found" }); }); test("stderr stays empty across all routes", async ({ page }) => { const base = await bootHono(page); await page.evaluate(async (base) => { await fetch(base + "echo", { method: "POST", headers: { "content-type": "application/json" }, body: '{"a":1}' }); await (await fetch(base + "stream")).text(); await fetch(base + "nope"); }, base); await expect(page.locator("#out")).toContainText("listening on 3000"); await expect(page.locator("#err")).toHaveText(""); }); test("serveStatic answers public/ as Node does, Last-Modified included", async ({ page }) => { const requests: RecordedRequest[] = await (await page.request.get(`/${GOLDEN.requests}`)).json(); const base = await bootHono(page); expect(await recordExchanges(page, base, requests)).toEqual(GOLDEN.exchanges); await expect(page.frameLocator("#app").locator("#hi")).toHaveCSS("color", "rgb(0, 128, 128)"); await expect(page.locator("#err")).toHaveText(""); });