fix: include middlewares and layouts for error pages (#2598)

Fixes https://github.com/denoland/fresh/issues/2594
This commit is contained in:
Marvin Hagemeister
2024-07-16 10:53:38 +02:00
committed by GitHub
parent 3f78058ae9
commit b510113655
2 changed files with 12 additions and 8 deletions
+3 -3
View File
@@ -438,10 +438,10 @@ export function sortRoutePaths(a: string, b: string) {
function getRoutePathScore(char: string, s: string, i: number): number { function getRoutePathScore(char: string, s: string, i: number): number {
if (char === "_") { if (char === "_") {
if (i + 1 < s.length) { if (i + 1 < s.length) {
if (s[i + 1] === "e") return 6; if (s[i + 1] === "e") return 4;
if (s[i + 1] === "m") return 5; if (s[i + 1] === "m") return 6;
} }
return 4; return 5;
} else if (char === "[") { } else if (char === "[") {
if (i + 1 < s.length && s[i + 1] === ".") { if (i + 1 < s.length && s[i + 1] === ".") {
return 0; return 0;
+9 -5
View File
@@ -831,7 +831,9 @@ Deno.test("fsRoutes - route group specific templates", async () => {
); );
res = await server.get("/foo_error"); res = await server.get("/foo_error");
doc = parseHtml(await res.text()); doc = parseHtml(await res.text());
expect(doc.body.firstChild?.textContent).toEqual("fail foo"); expect(doc.body.firstChild?.textContent).toEqual(
"(foo)_middleware/(foo)_layout/fail foo",
);
res = await server.get("/bar"); res = await server.get("/bar");
doc = parseHtml(await res.text()); doc = parseHtml(await res.text());
@@ -841,7 +843,9 @@ Deno.test("fsRoutes - route group specific templates", async () => {
res = await server.get("/bar_error"); res = await server.get("/bar_error");
doc = parseHtml(await res.text()); doc = parseHtml(await res.text());
expect(doc.body.firstChild?.textContent).toEqual("fail bar"); expect(doc.body.firstChild?.textContent).toEqual(
"(bar)_middleware/(bar)_layout/fail bar",
);
}); });
Deno.test("fsRoutes - async route components", async () => { Deno.test("fsRoutes - async route components", async () => {
@@ -882,7 +886,7 @@ Deno.test("fsRoutes - async route components", async () => {
res = await server.get("/foo_error"); res = await server.get("/foo_error");
doc = parseHtml(await res.text()); doc = parseHtml(await res.text());
expect(doc.body.firstChild?.textContent).toEqual("fail foo"); expect(doc.body.firstChild?.textContent).toEqual("/_layout/fail foo");
}); });
Deno.test("fsRoutes - async route components returning response", async () => { Deno.test("fsRoutes - async route components returning response", async () => {
@@ -1048,13 +1052,13 @@ Deno.test("fsRoutes - sortRoutePaths", () => {
]; ];
let sorted = [ let sorted = [
"/_error", "/_error",
"/foo/_error",
"/foo/_middleware", "/foo/_middleware",
"/foo/_layout", "/foo/_layout",
"/foo/_error",
"/foo/index", "/foo/index",
"/foo/bar/_error",
"/foo/bar/_middleware", "/foo/bar/_middleware",
"/foo/bar/_layout", "/foo/bar/_layout",
"/foo/bar/_error",
"/foo/bar/index", "/foo/bar/index",
"/foo/bar/baz", "/foo/bar/baz",
"/foo/bar/[...foo]", "/foo/bar/[...foo]",