fix(core): support method handler on _error, _404 and _500 routes (#2955)
This PR adds support for using method handlers in `_error`, `_404` and `_500` files. Fixes https://github.com/denoland/fresh/issues/2953
This commit is contained in:
@@ -646,6 +646,28 @@ Deno.test("fsRoutes - _404", async () => {
|
||||
expect(content).toContain("Custom 404 - Not Found");
|
||||
});
|
||||
|
||||
Deno.test("fsRoutes - _404 method handler", async () => {
|
||||
const server = await createServer({
|
||||
"routes/_404.tsx": {
|
||||
handlers: {
|
||||
GET() {
|
||||
return new Response("ok");
|
||||
},
|
||||
},
|
||||
},
|
||||
"routes/index.tsx": {
|
||||
handlers: {
|
||||
GET() {
|
||||
return new Response("fail");
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const res = await server.get("/invalid");
|
||||
expect(await res.text()).toEqual("ok");
|
||||
});
|
||||
|
||||
Deno.test("fsRoutes - _500", async () => {
|
||||
const server = await createServer({
|
||||
"routes/_500.tsx": {
|
||||
@@ -665,6 +687,26 @@ Deno.test("fsRoutes - _500", async () => {
|
||||
expect(content).toContain("Custom Error Page");
|
||||
});
|
||||
|
||||
Deno.test("fsRoutes - _500 method handler", async () => {
|
||||
const server = await createServer({
|
||||
"routes/_500.tsx": {
|
||||
handlers: {
|
||||
GET() {
|
||||
return new Response("ok");
|
||||
},
|
||||
},
|
||||
},
|
||||
"routes/index.tsx": {
|
||||
handlers: () => {
|
||||
throw new Error("fail");
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const res = await server.get("/");
|
||||
expect(await res.text()).toEqual("ok");
|
||||
});
|
||||
|
||||
Deno.test("fsRoutes - _error", async () => {
|
||||
const server = await createServer({
|
||||
"routes/_error.tsx": {
|
||||
@@ -730,6 +772,26 @@ Deno.test("fsRoutes - _error nested throw", async () => {
|
||||
expect(await res.text()).toEqual("ok");
|
||||
});
|
||||
|
||||
Deno.test("fsRoutes - _error method handler", async () => {
|
||||
const server = await createServer({
|
||||
"routes/_error.tsx": {
|
||||
handlers: {
|
||||
GET() {
|
||||
return new Response("ok");
|
||||
},
|
||||
},
|
||||
},
|
||||
"routes/index.tsx": {
|
||||
handlers: () => {
|
||||
throw new Error("fail");
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const res = await server.get("/");
|
||||
expect(await res.text()).toEqual("ok");
|
||||
});
|
||||
|
||||
Deno.test("fsRoutes - _error render component", async () => {
|
||||
const server = await createServer({
|
||||
"routes/_error.tsx": {
|
||||
|
||||
Reference in New Issue
Block a user