Adds code frame to errors if possible: <img width="1095" alt="Screenshot 2023-09-15 at 11 33 46" src="https://github.com/denoland/fresh/assets/1062408/7f4a5378-d00f-4550-b995-37a77f96ce0c"> Default error page in dev mode: <img width="937" alt="Screenshot 2023-09-15 at 11 30 59" src="https://github.com/denoland/fresh/assets/1062408/130172f4-beed-4d8c-b2b5-0e23be0b8f84"> Default error page in prod mode: <img width="939" alt="Screenshot 2023-09-15 at 11 31 23" src="https://github.com/denoland/fresh/assets/1062408/4ef58b83-b5f4-45cb-bc3f-1c8c4e5b6357">
26 lines
839 B
TypeScript
26 lines
839 B
TypeScript
import { ServerContext, Status } from "../server.ts";
|
|
import { assert, assertEquals, assertStringIncludes } from "./deps.ts";
|
|
import manifest from "./fixture_error/fresh.gen.ts";
|
|
|
|
const ctx = await ServerContext.fromManifest(manifest, { dev: true });
|
|
const handler = ctx.handler();
|
|
const router = (req: Request) => {
|
|
return handler(req, {
|
|
remoteAddr: {
|
|
transport: "tcp",
|
|
hostname: "127.0.0.1",
|
|
port: 80,
|
|
},
|
|
});
|
|
};
|
|
|
|
Deno.test("error page rendered", async () => {
|
|
const resp = await router(new Request("https://fresh.deno.dev/"));
|
|
assert(resp);
|
|
assertEquals(resp.status, Status.InternalServerError);
|
|
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
|
const body = await resp.text();
|
|
assertStringIncludes(body, `Error: boom!`);
|
|
assertStringIncludes(body, `at render`);
|
|
});
|