From 8b0d62f690e8bbddbe9cc19796f8f61f7acced10 Mon Sep 17 00:00:00 2001 From: Magnus Dahl Eide Date: Wed, 1 Oct 2025 14:04:01 +0200 Subject: [PATCH 1/2] fix(e2e): Ensure the response event listener is registered before navigation --- .../tests-e2e/tests/appRouter/middleware.rewrite.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts b/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts index 07a227666..1eec7d751 100644 --- a/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts +++ b/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts @@ -34,10 +34,11 @@ test("Middleware Rewrite External Image", async ({ page }) => { }); test("Middleware Rewrite Status Code", async ({ page }) => { + // 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) 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") { + // `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") { expect(response.status()).toBe(403); } }); From 426c397914a6434f3e8ffc02a7ab900ec3e54e74 Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 8 Oct 2025 08:51:09 +0200 Subject: [PATCH 2/2] sync --- .../tests/appRouter/middleware.rewrite.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts b/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts index 1eec7d751..afd3f7c5f 100644 --- a/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts +++ b/packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts @@ -36,13 +36,17 @@ test("Middleware Rewrite External Image", async ({ page }) => { test("Middleware Rewrite Status Code", async ({ page }) => { // 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) - 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") { - expect(response.status()).toBe(403); - } + const statusPromise = new Promise((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); });