Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions examples/e2e/app-pages-router/app/ssg/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const dynamic = "force-static";

export default function Page() {
return (
<div>
<strong>This is a static page</strong>
</div>
);
}
11 changes: 11 additions & 0 deletions examples/e2e/app-pages-router/e2e/headers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from "@playwright/test";

test("does not set x-opennext-requestid header on cache interceptor response", async ({ page }) => {
const result = await page.goto("/ssg");
expect(result).toBeDefined();
expect(result?.status()).toBe(200);
const headers = result?.headers();

// This header should not be defined even when its a cached response from the cache interception in the external middleware
expect(headers?.["x-opennext-requestid"]).toBeUndefined();
});
38 changes: 27 additions & 11 deletions examples/e2e/app-router/e2e/middleware.rewrite.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from "@playwright/test";
import { expect, test, Response as PwResponse } from "@playwright/test";
import { validateMd5 } from "../../utils";

/*
Expand All @@ -23,21 +23,37 @@ test("Middleware Rewrite", async ({ page }) => {
});

test("Middleware Rewrite External Image", async ({ page }) => {
await page.goto("/rewrite-external");
page.on("response", async (response) => {
expect(response.status()).toBe(200);
expect(response.headers()["content-type"]).toBe("image/png");
expect(response.headers()["cache-control"]).toBe("max-age=600");
const bodyBuffer = await response.body();
expect(validateMd5(bodyBuffer, OPENNEXT_PNG_MD5)).toBe(true);
let responsePromise = new Promise<PwResponse>((resolve) => {
page.on("response", async (resp) => {
resolve(resp);
});
});

await page.goto("/rewrite-external");

const response = await responsePromise;

expect(response.status()).toBe(200);
expect(response.headers()["content-type"]).toBe("image/png");
expect(response.headers()["cache-control"]).toBe("max-age=600");
const bodyBuffer = await response.body();
expect(validateMd5(bodyBuffer, OPENNEXT_PNG_MD5)).toBe(true);
});

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)
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();
page.on("response", async (response) => {
expect(response.status()).toBe(403);
});
expect(statusPromise).resolves.toEqual(403);
});
2 changes: 2 additions & 0 deletions examples/e2e/pages-router/e2e/header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ test("should test if poweredByHeader adds the correct headers ", async ({ page }
// Both these headers should be present cause poweredByHeader is true in pagesRouter
expect(headers?.["x-powered-by"]).toBe("Next.js");
expect(headers?.["x-opennext"]).toBe("1");
// This header should be defined cause we have set the `OPEN_NEXT_REQUEST_ID_HEADER` env variable in wrangler.jsonc
expect(headers?.["x-opennext-requestid"]).not.toBeUndefined();
});
5 changes: 4 additions & 1 deletion examples/e2e/pages-router/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"binding": "WORKER_SELF_REFERENCE",
"service": "pages-router"
}
]
],
"vars": {
"OPEN_NEXT_REQUEST_ID_HEADER": "true"
}
}