import { describe, it, expect } from "vitest"; import { Hono } from "hono"; import { serveStatic } from "@hono/node-server/serve-static"; describe("global error handler", () => { const errApp = new Hono(); errApp.onError((err, c) => { const detail = process.env.NODE_ENV !== "production" ? `
${err.message}
Something went wrong. Please try again later.
${detail}`, 500 ); }); errApp.get("/boom", () => { throw new Error("test error"); }); it("returns 500 with HTML content-type on unhandled error", async () => { const res = await errApp.request("/boom"); expect(res.status).toBe(500); expect(res.headers.get("content-type")).toContain("text/html"); }); it("includes error message in dev mode", async () => { const original = process.env.NODE_ENV; process.env.NODE_ENV = "development"; try { const res = await errApp.request("/boom"); const html = await res.text(); expect(html).toContain("test error"); } finally { process.env.NODE_ENV = original; } }); it("omits error message in production mode", async () => { const original = process.env.NODE_ENV; process.env.NODE_ENV = "production"; try { const res = await errApp.request("/boom"); const html = await res.text(); expect(html).not.toContain("test error"); } finally { process.env.NODE_ENV = original; } }); }); describe("static file serving", () => { const app = new Hono(); app.use("/static/*", serveStatic({ root: "./public" })); it("serves reset.css with text/css content-type", async () => { const res = await app.request("/static/css/reset.css"); expect(res.status).toBe(200); expect(res.headers.get("content-type")).toContain("text/css"); }); it("serves theme.css with text/css content-type", async () => { const res = await app.request("/static/css/theme.css"); expect(res.status).toBe(200); expect(res.headers.get("content-type")).toContain("text/css"); }); it("returns 404 for unknown static paths", async () => { const res = await app.request("/static/css/nonexistent.css"); expect(res.status).toBe(404); }); });