Return a 404 when paring the route fails (#3860)
* return a 404 when paring the route fails * add a playwright test for fullstack routing status codes * Fix new playwright test * document SSRError * Make SSRError public and fix clippy * Move the error display bound to the routable trait * fix clippy * return a more generic 404 message * fix router tests
This commit is contained in:
1 parent
7b7357037f
commit
09a4b5eb4e
18 files changed
+253
-46
No files matched your search
@@ -0,0 +1,53 @@
|
||||
// @ts-check
|
||||
const { test, expect } = require("@playwright/test");
|
||||
|
||||
// Wait for the build to finish
|
||||
async function waitForBuild(request) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const build = await request.get("http://localhost:8888");
|
||||
let text = await build.text();
|
||||
if (!text.includes("Backend connection failed")) {
|
||||
return;
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
// The home and id routes should return 200
|
||||
test("home route", async ({ request }) => {
|
||||
await waitForBuild(request);
|
||||
const response = await request.get("http://localhost:8888");
|
||||
|
||||
expect(response.status()).toBe(200);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toContain("Home");
|
||||
});
|
||||
|
||||
test("blog route", async ({ request }) => {
|
||||
await waitForBuild(request);
|
||||
const response = await request.get("http://localhost:8888/blog/123");
|
||||
|
||||
expect(response.status()).toBe(200);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toContain("id: 123");
|
||||
});
|
||||
|
||||
// The error route should return 500
|
||||
test("error route", async ({ request }) => {
|
||||
await waitForBuild(request);
|
||||
const response = await request.get("http://localhost:8888/error");
|
||||
|
||||
expect(response.status()).toBe(500);
|
||||
});
|
||||
|
||||
// An unknown route should return 404
|
||||
test("unknown route", async ({ request }) => {
|
||||
await waitForBuild(request);
|
||||
const response = await request.get(
|
||||
"http://localhost:8888/this-route-does-not-exist"
|
||||
);
|
||||
|
||||
expect(response.status()).toBe(404);
|
||||
});
|
||||
Reference in new issue
Block a user