WIP! A BB-style forum, on the ATmosphere!
We're still working... we'll be back soon when we have something to show off!
node
typescript
hono
htmx
atproto
1import { describe, it, expect } from "vitest";
2import { Hono } from "hono";
3import { serveStatic } from "@hono/node-server/serve-static";
4
5describe("global error handler", () => {
6 const errApp = new Hono();
7 errApp.onError((err, c) => {
8 const detail =
9 process.env.NODE_ENV !== "production"
10 ? `<p><code>${err.message}</code></p>`
11 : "";
12 return c.html(
13 `<!DOCTYPE html><html lang="en"><body><h1>Internal Server Error</h1><p>Something went wrong. Please try again later.</p>${detail}</body></html>`,
14 500
15 );
16 });
17 errApp.get("/boom", () => {
18 throw new Error("test error");
19 });
20
21 it("returns 500 with HTML content-type on unhandled error", async () => {
22 const res = await errApp.request("/boom");
23 expect(res.status).toBe(500);
24 expect(res.headers.get("content-type")).toContain("text/html");
25 });
26
27 it("includes error message in dev mode", async () => {
28 const original = process.env.NODE_ENV;
29 process.env.NODE_ENV = "development";
30 try {
31 const res = await errApp.request("/boom");
32 const html = await res.text();
33 expect(html).toContain("test error");
34 } finally {
35 process.env.NODE_ENV = original;
36 }
37 });
38
39 it("omits error message in production mode", async () => {
40 const original = process.env.NODE_ENV;
41 process.env.NODE_ENV = "production";
42 try {
43 const res = await errApp.request("/boom");
44 const html = await res.text();
45 expect(html).not.toContain("test error");
46 } finally {
47 process.env.NODE_ENV = original;
48 }
49 });
50});
51
52describe("static file serving", () => {
53 const app = new Hono();
54 app.use("/static/*", serveStatic({ root: "./public" }));
55
56 it("serves reset.css with text/css content-type", async () => {
57 const res = await app.request("/static/css/reset.css");
58 expect(res.status).toBe(200);
59 expect(res.headers.get("content-type")).toContain("text/css");
60 });
61
62 it("serves theme.css with text/css content-type", async () => {
63 const res = await app.request("/static/css/theme.css");
64 expect(res.status).toBe(200);
65 expect(res.headers.get("content-type")).toContain("text/css");
66 });
67
68 it("returns 404 for unknown static paths", async () => {
69 const res = await app.request("/static/css/nonexistent.css");
70 expect(res.status).toBe(404);
71 });
72});