Skip to content

Commit 176aa3b

Browse files
authored
chore: sync e2e tests with aws (#974)
1 parent ddb0589 commit 176aa3b

File tree

16 files changed

+201
-48
lines changed

16 files changed

+201
-48
lines changed

examples/e2e/app-pages-router/e2e/host.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect, test } from "@playwright/test";
22

33
/**
44
* Tests that the request.url is correct
5-
*
65
*/
76
test("Request.url is host", async ({ baseURL, page }) => {
87
await page.goto("/api/host");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("should return correctly on HEAD request with an empty body", async ({ request }) => {
4+
const response = await request.head("/head");
5+
expect(response.status()).toBe(200);
6+
const body = await response.text();
7+
expect(body).toBe("");
8+
expect(response.headers()["x-from-middleware"]).toBe("true");
9+
});
10+
11+
test("should return correctly for directly returning a fetch response", async ({ request }) => {
12+
const response = await request.get("/fetch");
13+
expect(response.status()).toBe(200);
14+
const body = await response.json();
15+
expect(body).toEqual({ hello: "world" });
16+
});

examples/e2e/app-router/e2e/headers.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,21 @@ test("Headers", async ({ page }) => {
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();
27+
28+
// Request ID header should be set
29+
expect(headers["x-opennext-requestid"]).not.toBeFalsy();
30+
});
31+
/**
32+
* Tests that the middleware headers are applied after next.config.js headers. Requires 'dangerous.middlewareHeadersOverrideNextConfigHeaders' to be set.
33+
*/
34+
test("Middleware headers override next.config.js headers", async ({ page }) => {
35+
const responsePromise = page.waitForResponse((response) => {
36+
return response.status() === 200;
37+
});
38+
await page.goto("/headers/override-from-middleware");
39+
const response = await responsePromise;
40+
// Response header should be set
41+
const headers = response.headers();
42+
// The next.config.js headers is overwritten by the middleware
43+
expect(headers["e2e-headers"]).toEqual("middleware");
2744
});

examples/e2e/app-router/e2e/host.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect, test } from "@playwright/test";
22

33
/**
44
* Tests that the request.url is correct
5-
*
65
*/
76
test("Request.url is host", async ({ baseURL, page }) => {
87
await page.goto("/api/host");

examples/e2e/app-router/e2e/image-optimization.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ test.skip("Image Optimization", async ({ page }) => {
1717
await expect(el).toHaveJSProperty("complete", true);
1818
await expect(el).not.toHaveJSProperty("naturalWidth", 0);
1919
});
20+
21+
// Image Optimization is currently not supported: https://github.com/opennextjs/opennextjs-cloudflare/issues/106
22+
test.skip("should return 400 when validateParams returns an errorMessage", async ({ request }) => {
23+
const res = await request.get("/_next/image");
24+
expect(res.status()).toBe(400);
25+
expect(res.headers()["cache-control"]).toBe("public,max-age=60,immutable");
26+
expect(await res.text()).toBe(`"url" parameter is required`);
27+
});

examples/e2e/app-router/e2e/isr.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ test.describe("dynamicParams set to true", () => {
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);
106-
// 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();
@@ -117,7 +116,6 @@ test.describe("dynamicParams set to true", () => {
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");
120-
// 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();
@@ -144,7 +142,6 @@ test.describe("dynamicParams set to false", () => {
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);
147-
// 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();

examples/e2e/app-router/middleware.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export function middleware(request: NextRequest) {
4747
// Response headers should show up in the client's response headers
4848
responseHeaders.set("response-header", "response-header");
4949

50+
// For dangerous.middlewareHeadersOverrideNextConfigHeaders we need to verify that middleware headers override next.config.js headers.
51+
if (path === "/headers/override-from-middleware") {
52+
responseHeaders.set("e2e-headers", "middleware");
53+
return NextResponse.json({}, { headers: responseHeaders });
54+
}
55+
5056
// Set the cache control header with custom swr
5157
// For: isr.test.ts
5258
if (path === "/isr" && !request.headers.get("x-prerender-revalidate")) {

examples/e2e/app-router/open-next.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import shardedTagCache from "@opennextjs/cloudflare/overrides/tag-cache/do-shard
44
import doQueue from "@opennextjs/cloudflare/overrides/queue/do-queue";
55
import queueCache from "@opennextjs/cloudflare/overrides/queue/queue-cache";
66

7-
export default defineCloudflareConfig({
7+
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({
@@ -24,3 +24,11 @@ export default defineCloudflareConfig({
2424
enableCacheInterception: true,
2525
queue: queueCache(doQueue),
2626
});
27+
28+
export default {
29+
...baseConfig,
30+
dangerous: {
31+
...baseConfig.dangerous,
32+
middlewareHeadersOverrideNextConfigHeaders: true,
33+
},
34+
};

examples/e2e/app-router/wrangler.jsonc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
"binding": "WORKER_SELF_REFERENCE",
4242
"service": "app-router"
4343
}
44-
]
44+
],
45+
"vars": {
46+
"OPEN_NEXT_REQUEST_ID_HEADER": "true"
47+
}
4548
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, test } from "@playwright/test";
2+
// Going to `/`, `/conico974`, `/kheuzy` and `/sommeeer` should be catched by our `[[...page]]` route.
3+
// Also the /super/long/path/to/secret/page should be pregenerated by the `getStaticPaths` function.
4+
test.describe("Catch-all optional route in root should work", () => {
5+
test("should be possible to visit home and a pregenerated subpage", async ({ page }) => {
6+
await page.goto("/");
7+
await page.locator("h1").getByText("Pages Router").isVisible();
8+
await page.goto("/conico974");
9+
const pElement = page.getByText("Path: conico974", { exact: true });
10+
await pElement.isVisible();
11+
});
12+
13+
test("should be possible to visit a long pregenerated path", async ({ page }) => {
14+
await page.goto("/super/long/path/to/secret/page");
15+
const h1Text = await page.getByTestId("page").textContent();
16+
expect(h1Text).toBe("Page: super,long,path,to,secret,page");
17+
});
18+
19+
test("should be possible to request an API route when you have a catch-all in root", async ({
20+
request,
21+
}) => {
22+
const response = await request.get("/api/hello");
23+
expect(response.status()).toBe(200);
24+
const body = await response.json();
25+
expect(body).toEqual({ hello: "OpenNext rocks!" });
26+
});
27+
});

0 commit comments

Comments
 (0)