From 8b0d62f690e8bbddbe9cc19796f8f61f7acced10 Mon Sep 17 00:00:00 2001 From: Magnus Dahl Eide Date: Wed, 1 Oct 2025 14:04:01 +0200 Subject: [PATCH] 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); } });