Skip to content

Commit e21f91b

Browse files
committed
fix(e2e): Ensure the response event listener is registered before navigation
1 parent f1e9457 commit e21f91b

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const dynamic = "force-static";
2+
3+
export default function Page() {
4+
return (
5+
<div>
6+
<strong>This is a static page</strong>
7+
</div>
8+
);
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("should test if poweredByHeader adds the correct headers ", async ({ page }) => {
4+
const result = await page.goto("/ssg");
5+
expect(result).toBeDefined();
6+
expect(result?.status()).toBe(200);
7+
const headers = result?.headers();
8+
9+
// This header should not be defined even when cache interception happens in the external middleware
10+
expect(headers?.["x-opennext-requestid"]).toBeFalsy();
11+
12+
await page.waitForTimeout(2000); // Wait 2s
13+
14+
const result2 = await page.goto("/ssg");
15+
expect(result2).toBeDefined();
16+
expect(result2?.status()).toBe(200);
17+
const headers2 = result2?.headers();
18+
19+
expect(headers2?.["x-opennext-requestid"]).toBeFalsy();
20+
});

examples/e2e/app-router/e2e/middleware.rewrite.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ test("Middleware Rewrite", async ({ page }) => {
2323
});
2424

2525
test("Middleware Rewrite External Image", async ({ page }) => {
26-
await page.goto("/rewrite-external");
2726
page.on("response", async (response) => {
2827
expect(response.status()).toBe(200);
2928
expect(response.headers()["content-type"]).toBe("image/png");
3029
expect(response.headers()["cache-control"]).toBe("max-age=600");
3130
const bodyBuffer = await response.body();
3231
expect(validateMd5(bodyBuffer, OPENNEXT_PNG_MD5)).toBe(true);
3332
});
33+
await page.goto("/rewrite-external");
3434
});
3535

3636
test("Middleware Rewrite Status Code", async ({ page }) => {
37-
await page.goto("/rewrite-status-code");
38-
const el = page.getByText("Rewritten Destination", { exact: true });
39-
await expect(el).toBeVisible();
4037
page.on("response", async (response) => {
4138
expect(response.status()).toBe(403);
4239
});
40+
await page.goto("/rewrite-status-code");
41+
const el = page.getByText("Rewritten Destination", { exact: true });
42+
await expect(el).toBeVisible();
4343
});

examples/e2e/pages-router/e2e/header.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ test("should test if poweredByHeader adds the correct headers ", async ({ page }
99
// Both these headers should be present cause poweredByHeader is true in pagesRouter
1010
expect(headers?.["x-powered-by"]).toBe("Next.js");
1111
expect(headers?.["x-opennext"]).toBe("1");
12+
// This header should be defined cause we have set the `OPEN_NEXT_REQUEST_ID_HEADER` env variable in wrangler.jsonc
13+
expect(headers?.["x-opennext-requestid"]).not.toBeFalsy();
1214
});

examples/e2e/pages-router/wrangler.jsonc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"binding": "WORKER_SELF_REFERENCE",
2020
"service": "pages-router"
2121
}
22-
]
22+
],
23+
"vars": {
24+
"OPEN_NEXT_REQUEST_ID_HEADER": "true"
25+
}
2326
}

0 commit comments

Comments
 (0)