fix: show original error page in dev (#2074)
This commit is contained in:
+20
-31
@@ -6,6 +6,7 @@ import {
|
||||
assertTextMany,
|
||||
assertTextMatch,
|
||||
fetchHtml,
|
||||
getErrorOverlay,
|
||||
waitForStyle,
|
||||
withFakeServe,
|
||||
withFresh,
|
||||
@@ -25,18 +26,14 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "dev_command config: shows codeframe",
|
||||
async fn() {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_config/dev.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml("/codeframe");
|
||||
assertSelector(doc, ".frsh-error-page");
|
||||
assertSelector(doc, ".code-frame");
|
||||
},
|
||||
);
|
||||
},
|
||||
Deno.test("dev_command config: shows codeframe", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_config/dev.ts",
|
||||
async (server) => {
|
||||
const { codeFrame } = await getErrorOverlay(server, "/codeframe");
|
||||
assert(codeFrame);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
@@ -52,18 +49,14 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "dev_command legacy: shows codeframe",
|
||||
async fn() {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_legacy/dev.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml("/codeframe");
|
||||
assertSelector(doc, ".frsh-error-page");
|
||||
assertSelector(doc, ".code-frame");
|
||||
},
|
||||
);
|
||||
},
|
||||
Deno.test("dev_command legacy: shows codeframe", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_legacy/dev.ts",
|
||||
async (server) => {
|
||||
const { codeFrame } = await getErrorOverlay(server, "/codeframe");
|
||||
assert(codeFrame);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("preact/debug is active in dev mode", async () => {
|
||||
@@ -72,15 +65,11 @@ Deno.test("preact/debug is active in dev mode", async () => {
|
||||
async (server) => {
|
||||
// SSR error is shown
|
||||
const resp = await server.get("/");
|
||||
const text = await resp.text();
|
||||
await resp.text(); // Consume
|
||||
assertEquals(resp.status, Status.InternalServerError);
|
||||
assertStringIncludes(text, "Objects are not valid as a child");
|
||||
|
||||
const html = await server.getHtml("/");
|
||||
|
||||
// Error page is shown with error message
|
||||
const text2 = html.querySelector(".frsh-error-page")!.textContent!;
|
||||
assertStringIncludes(text2, "Objects are not valid as a child");
|
||||
const { title } = await getErrorOverlay(server, "/");
|
||||
assertStringIncludes(title, "Objects are not valid as a child");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
+13
-22
@@ -1,25 +1,16 @@
|
||||
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,
|
||||
},
|
||||
});
|
||||
};
|
||||
import { Status } from "../server.ts";
|
||||
import { assertEquals, assertStringIncludes } from "./deps.ts";
|
||||
import { getErrorOverlay, withFakeServe } from "./test_utils.ts";
|
||||
|
||||
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`);
|
||||
await withFakeServe("./tests/fixture_error/dev.ts", async (server) => {
|
||||
const resp = await server.get("/");
|
||||
assertEquals(resp.status, Status.InternalServerError);
|
||||
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||
await resp.text(); // Consume
|
||||
|
||||
const { title, stack } = await getErrorOverlay(server, "/");
|
||||
assertStringIncludes(title, `boom!`);
|
||||
assertStringIncludes(stack, `at render`);
|
||||
});
|
||||
});
|
||||
|
||||
+18
-11
@@ -2,9 +2,8 @@ import { assert, assertEquals, assertStringIncludes, Page } from "./deps.ts";
|
||||
import {
|
||||
assertNoPageComments,
|
||||
assertNotSelector,
|
||||
assertSelector,
|
||||
assertTextMatch,
|
||||
clickWhenListenerReady,
|
||||
getErrorOverlay,
|
||||
parseHtml,
|
||||
waitForText,
|
||||
withFakeServe,
|
||||
@@ -417,20 +416,28 @@ Deno.test("throws when passing non-jsx children to an island", async (t) => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_island_nesting/dev.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml(`/island_invalid_children`);
|
||||
const overlay1 = await getErrorOverlay(
|
||||
server,
|
||||
"/island_invalid_children",
|
||||
);
|
||||
assertStringIncludes(
|
||||
overlay1.title,
|
||||
"Invalid JSX child passed to island",
|
||||
);
|
||||
|
||||
assertSelector(doc, ".frsh-error-page");
|
||||
assertTextMatch(doc, "pre", /Invalid JSX child passed to island/);
|
||||
|
||||
const doc2 = await server.getHtml(`/island_invalid_children_fn`);
|
||||
|
||||
assertSelector(doc2, ".frsh-error-page");
|
||||
assertTextMatch(doc2, "pre", /Invalid JSX child passed to island/);
|
||||
const overlay2 = await getErrorOverlay(
|
||||
server,
|
||||
"/island_invalid_children_fn",
|
||||
);
|
||||
assertStringIncludes(
|
||||
overlay2.title,
|
||||
"Invalid JSX child passed to island",
|
||||
);
|
||||
|
||||
await t.step("should not throw on valid children", async () => {
|
||||
const doc2 = await server.getHtml(`/island_valid_children`);
|
||||
|
||||
assertNotSelector(doc2, ".frsh-error-page");
|
||||
assertNotSelector(doc2, "#fresh-error-overlay");
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
+15
-2
@@ -6,6 +6,7 @@ import {
|
||||
assertNotSelector,
|
||||
assertSelector,
|
||||
assertTextMany,
|
||||
getErrorOverlay,
|
||||
parseHtml,
|
||||
waitFor,
|
||||
waitForText,
|
||||
@@ -41,9 +42,21 @@ Deno.test(
|
||||
await withFakeServe(
|
||||
"./tests/fixture_partials/main.ts",
|
||||
async (server) => {
|
||||
const html = await server.getHtml("/partial_slot_inside_island");
|
||||
const res = await server.get("/partial_slot_inside_island");
|
||||
assertEquals(res.status, 500);
|
||||
await res.text(); // Consume
|
||||
},
|
||||
);
|
||||
|
||||
await withFakeServe(
|
||||
"./tests/fixture_partials/dev.ts",
|
||||
async (server) => {
|
||||
const { title } = await getErrorOverlay(
|
||||
server,
|
||||
"/partial_slot_inside_island",
|
||||
);
|
||||
assertMatch(
|
||||
html.querySelector("h1")!.textContent!,
|
||||
title,
|
||||
/<Partial> components cannot be used inside islands/,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -166,6 +166,24 @@ function _printDomNode(
|
||||
return out;
|
||||
}
|
||||
|
||||
export async function getErrorOverlay(
|
||||
server: FakeServer,
|
||||
url: string,
|
||||
): Promise<{ title: string; codeFrame: boolean; stack: string }> {
|
||||
const doc = await server.getHtml(url);
|
||||
const iframe = doc.querySelector(
|
||||
"#fresh-error-overlay",
|
||||
) as HTMLIFrameElement;
|
||||
|
||||
const doc2 = await server.getHtml(iframe.src);
|
||||
|
||||
return {
|
||||
title: doc2.querySelector(".title")!.textContent!,
|
||||
codeFrame: doc2.querySelector(".code-frame") !== null,
|
||||
stack: doc2.querySelector(".stack")!.textContent!,
|
||||
};
|
||||
}
|
||||
|
||||
export async function withFresh(
|
||||
name: string | { name: string; options: Omit<Deno.CommandOptions, "args"> },
|
||||
fn: (address: string) => Promise<void>,
|
||||
|
||||
Reference in New Issue
Block a user