Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ test("Middleware Rewrite External Image", async ({ page }) => {
});

test("Middleware Rewrite Status Code", async ({ page }) => {
page.on("response", async (response) => {
// Need to set up the event before navigating to the page to avoid missing it
// We need to check the URL here also cause there will be multiple responses (i.e the fonts, css, js, etc)
if (response.url() === "/rewrite-status-code") {
expect(response.status()).toBe(403);
}
// Need to set up the event before navigating to the page to avoid missing it
// We need to check the URL here also cause there will be multiple responses (i.e the fonts, css, js, etc)
const statusPromise = new Promise<number>((resolve) => {
page.on("response", async (response) => {
// `response.url()` will be the full URL including the host, so we need to check the pathname
if (new URL(response.url()).pathname === "/rewrite-status-code") {
resolve(response.status());
}
});
});

await page.goto("/rewrite-status-code");
const el = page.getByText("Rewritten Destination", { exact: true });
await expect(el).toBeVisible();
expect(statusPromise).resolves.toEqual(403);
});
Loading