···11+import { expect, test } from "@playwright/test";
22+33+test("should return correctly on HEAD request with an empty body", async ({ request }) => {
44+ const response = await request.head("/head");
55+ expect(response.status()).toBe(200);
66+ const body = await response.text();
77+ expect(body).toBe("");
88+ expect(response.headers()["x-from-middleware"]).toBe("true");
99+});
1010+1111+test("should return correctly for directly returning a fetch response", async ({ request }) => {
1212+ const response = await request.get("/fetch");
1313+ expect(response.status()).toBe(200);
1414+ const body = await response.json();
1515+ expect(body).toEqual({ hello: "world" });
1616+});
+17
examples/e2e/app-router/e2e/headers.test.ts
···2424 // Both these headers should not be present cause poweredByHeader is false in appRouter
2525 expect(headers["x-powered-by"]).toBeFalsy();
2626 expect(headers["x-opennext"]).toBeFalsy();
2727+2828+ // Request ID header should be set
2929+ expect(headers["x-opennext-requestid"]).not.toBeFalsy();
3030+});
3131+/**
3232+ * Tests that the middleware headers are applied after next.config.js headers. Requires 'dangerous.middlewareHeadersOverrideNextConfigHeaders' to be set.
3333+ */
3434+test("Middleware headers override next.config.js headers", async ({ page }) => {
3535+ const responsePromise = page.waitForResponse((response) => {
3636+ return response.status() === 200;
3737+ });
3838+ await page.goto("/headers/override-from-middleware");
3939+ const response = await responsePromise;
4040+ // Response header should be set
4141+ const headers = response.headers();
4242+ // The next.config.js headers is overwritten by the middleware
4343+ expect(headers["e2e-headers"]).toEqual("middleware");
2744});
-1
examples/e2e/app-router/e2e/host.test.ts
···2233/**
44 * Tests that the request.url is correct
55- *
65 */
76test("Request.url is host", async ({ baseURL, page }) => {
87 await page.goto("/api/host");
···1717 await expect(el).toHaveJSProperty("complete", true);
1818 await expect(el).not.toHaveJSProperty("naturalWidth", 0);
1919});
2020+2121+// Image Optimization is currently not supported: https://github.com/opennextjs/opennextjs-cloudflare/issues/106
2222+test.skip("should return 400 when validateParams returns an errorMessage", async ({ request }) => {
2323+ const res = await request.get("/_next/image");
2424+ expect(res.status()).toBe(400);
2525+ expect(res.headers()["cache-control"]).toBe("public,max-age=60,immutable");
2626+ expect(await res.text()).toBe(`"url" parameter is required`);
2727+});
-3
examples/e2e/app-router/e2e/isr.test.ts
···103103 test("should be HIT on a path that was prebuilt", async ({ page }) => {
104104 const res = await page.goto("/isr/dynamic-params-true/1");
105105 expect(res?.status()).toEqual(200);
106106- // TODO: sync this to aws
107106 const cacheHeader = res?.headers()["x-nextjs-cache"] ?? res?.headers()["x-opennext-cache"];
108107 expect(cacheHeader).toEqual("HIT");
109108 const title = await page.getByTestId("title").textContent();
···117116 // We are gonna skip this one for now, turborepo caching can cause this page to be STALE once deployed
118117 test.skip("should SSR on a path that was not prebuilt", async ({ page }) => {
119118 const res = await page.goto("/isr/dynamic-params-true/11");
120120- // TODO: sync this to aws
121119 const cacheHeader = res?.headers()["x-nextjs-cache"] ?? res?.headers()["x-opennext-cache"];
122120 expect(cacheHeader).toEqual("MISS");
123121 const title = await page.getByTestId("title").textContent();
···144142 test("should be HIT on a path that was prebuilt", async ({ page }) => {
145143 const res = await page.goto("/isr/dynamic-params-false/1");
146144 expect(res?.status()).toEqual(200);
147147- // TODO: sync this to aws
148145 const cacheHeader = res?.headers()["x-nextjs-cache"] ?? res?.headers()["x-opennext-cache"];
149146 expect(cacheHeader).toEqual("HIT");
150147 const title = await page.getByTestId("title").textContent();
+6
examples/e2e/app-router/middleware.ts
···4747 // Response headers should show up in the client's response headers
4848 responseHeaders.set("response-header", "response-header");
49495050+ // For dangerous.middlewareHeadersOverrideNextConfigHeaders we need to verify that middleware headers override next.config.js headers.
5151+ if (path === "/headers/override-from-middleware") {
5252+ responseHeaders.set("e2e-headers", "middleware");
5353+ return NextResponse.json({}, { headers: responseHeaders });
5454+ }
5555+5056 // Set the cache control header with custom swr
5157 // For: isr.test.ts
5258 if (path === "/isr" && !request.headers.get("x-prerender-revalidate")) {
+9-1
examples/e2e/app-router/open-next.config.ts
···44import doQueue from "@opennextjs/cloudflare/overrides/queue/do-queue";
55import queueCache from "@opennextjs/cloudflare/overrides/queue/queue-cache";
6677-export default defineCloudflareConfig({
77+const baseConfig = defineCloudflareConfig({
88 incrementalCache: r2IncrementalCache,
99 // With such a configuration, we could have up to 12 * (8 + 2) = 120 Durable Objects instances
1010 tagCache: shardedTagCache({
···2424 enableCacheInterception: true,
2525 queue: queueCache(doQueue),
2626});
2727+2828+export default {
2929+ ...baseConfig,
3030+ dangerous: {
3131+ ...baseConfig.dangerous,
3232+ middlewareHeadersOverrideNextConfigHeaders: true,
3333+ },
3434+};
···11+import { expect, test } from "@playwright/test";
22+// Going to `/`, `/conico974`, `/kheuzy` and `/sommeeer` should be catched by our `[[...page]]` route.
33+// Also the /super/long/path/to/secret/page should be pregenerated by the `getStaticPaths` function.
44+test.describe("Catch-all optional route in root should work", () => {
55+ test("should be possible to visit home and a pregenerated subpage", async ({ page }) => {
66+ await page.goto("/");
77+ await page.locator("h1").getByText("Pages Router").isVisible();
88+ await page.goto("/conico974");
99+ const pElement = page.getByText("Path: conico974", { exact: true });
1010+ await pElement.isVisible();
1111+ });
1212+1313+ test("should be possible to visit a long pregenerated path", async ({ page }) => {
1414+ await page.goto("/super/long/path/to/secret/page");
1515+ const h1Text = await page.getByTestId("page").textContent();
1616+ expect(h1Text).toBe("Page: super,long,path,to,secret,page");
1717+ });
1818+1919+ test("should be possible to request an API route when you have a catch-all in root", async ({
2020+ request,
2121+ }) => {
2222+ const response = await request.get("/api/hello");
2323+ expect(response.status()).toBe(200);
2424+ const body = await response.json();
2525+ expect(body).toEqual({ hello: "OpenNext rocks!" });
2626+ });
2727+});
···11import Nav from "@example/shared/components/Nav";
22import Head from "next/head";
3344-// Not used, but necessary to get prefetching to work
55-export function getStaticProps() {
66- return {
77- props: {
88- hello: "world",
99- },
1010- };
1111-}
1212-134export default function Home() {
145 return (
156 <>