this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: sync e2e tests with aws (#974)

authored by

Victor Berchet and committed by
GitHub
176aa3b1 ddb0589a

+195 -42
-1
examples/e2e/app-pages-router/e2e/host.test.ts
··· 2 2 3 3 /** 4 4 * Tests that the request.url is correct 5 - * 6 5 */ 7 6 test("Request.url is host", async ({ baseURL, page }) => { 8 7 await page.goto("/api/host");
+16
examples/e2e/app-pages-router/e2e/middleware.test.ts
··· 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 + });
+17
examples/e2e/app-router/e2e/headers.test.ts
··· 24 24 // Both these headers should not be present cause poweredByHeader is false in appRouter 25 25 expect(headers["x-powered-by"]).toBeFalsy(); 26 26 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"); 27 44 });
-1
examples/e2e/app-router/e2e/host.test.ts
··· 2 2 3 3 /** 4 4 * Tests that the request.url is correct 5 - * 6 5 */ 7 6 test("Request.url is host", async ({ baseURL, page }) => { 8 7 await page.goto("/api/host");
+8
examples/e2e/app-router/e2e/image-optimization.test.ts
··· 17 17 await expect(el).toHaveJSProperty("complete", true); 18 18 await expect(el).not.toHaveJSProperty("naturalWidth", 0); 19 19 }); 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 + });
-3
examples/e2e/app-router/e2e/isr.test.ts
··· 103 103 test("should be HIT on a path that was prebuilt", async ({ page }) => { 104 104 const res = await page.goto("/isr/dynamic-params-true/1"); 105 105 expect(res?.status()).toEqual(200); 106 - // TODO: sync this to aws 107 106 const cacheHeader = res?.headers()["x-nextjs-cache"] ?? res?.headers()["x-opennext-cache"]; 108 107 expect(cacheHeader).toEqual("HIT"); 109 108 const title = await page.getByTestId("title").textContent(); ··· 117 116 // We are gonna skip this one for now, turborepo caching can cause this page to be STALE once deployed 118 117 test.skip("should SSR on a path that was not prebuilt", async ({ page }) => { 119 118 const res = await page.goto("/isr/dynamic-params-true/11"); 120 - // TODO: sync this to aws 121 119 const cacheHeader = res?.headers()["x-nextjs-cache"] ?? res?.headers()["x-opennext-cache"]; 122 120 expect(cacheHeader).toEqual("MISS"); 123 121 const title = await page.getByTestId("title").textContent(); ··· 144 142 test("should be HIT on a path that was prebuilt", async ({ page }) => { 145 143 const res = await page.goto("/isr/dynamic-params-false/1"); 146 144 expect(res?.status()).toEqual(200); 147 - // TODO: sync this to aws 148 145 const cacheHeader = res?.headers()["x-nextjs-cache"] ?? res?.headers()["x-opennext-cache"]; 149 146 expect(cacheHeader).toEqual("HIT"); 150 147 const title = await page.getByTestId("title").textContent();
+6
examples/e2e/app-router/middleware.ts
··· 47 47 // Response headers should show up in the client's response headers 48 48 responseHeaders.set("response-header", "response-header"); 49 49 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 + 50 56 // Set the cache control header with custom swr 51 57 // For: isr.test.ts 52 58 if (path === "/isr" && !request.headers.get("x-prerender-revalidate")) {
+9 -1
examples/e2e/app-router/open-next.config.ts
··· 4 4 import doQueue from "@opennextjs/cloudflare/overrides/queue/do-queue"; 5 5 import queueCache from "@opennextjs/cloudflare/overrides/queue/queue-cache"; 6 6 7 - export default defineCloudflareConfig({ 7 + const baseConfig = defineCloudflareConfig({ 8 8 incrementalCache: r2IncrementalCache, 9 9 // With such a configuration, we could have up to 12 * (8 + 2) = 120 Durable Objects instances 10 10 tagCache: shardedTagCache({ ··· 24 24 enableCacheInterception: true, 25 25 queue: queueCache(doQueue), 26 26 }); 27 + 28 + export default { 29 + ...baseConfig, 30 + dangerous: { 31 + ...baseConfig.dangerous, 32 + middlewareHeadersOverrideNextConfigHeaders: true, 33 + }, 34 + };
+4 -1
examples/e2e/app-router/wrangler.jsonc
··· 41 41 "binding": "WORKER_SELF_REFERENCE", 42 42 "service": "app-router" 43 43 } 44 - ] 44 + ], 45 + "vars": { 46 + "OPEN_NEXT_REQUEST_ID_HEADER": "true" 47 + } 45 48 }
+27
examples/e2e/pages-router/e2e/catch-all-optional.test.ts
··· 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 + });
+4 -1
examples/e2e/pages-router/e2e/data.test.ts
··· 17 17 expect(response2.request().url()).toMatch(/\/_next\/data\/.*\/en\.json$/); 18 18 await page.waitForURL("/"); 19 19 const body = await response2.json(); 20 - expect(body).toEqual({ pageProps: { hello: "world" }, __N_SSG: true }); 20 + expect(body).toEqual({ 21 + pageProps: { subpage: [], pageType: "home" }, 22 + __N_SSG: true, 23 + }); 21 24 });
+12
examples/e2e/pages-router/e2e/middleware.test.ts
··· 1 + import { expect, test } from "playwright/test"; 2 + 3 + test("should return 500 on middleware error", async ({ request }) => { 4 + const response = await request.get("/", { 5 + headers: { 6 + "x-throw": "true", 7 + }, 8 + }); 9 + const body = await response.text(); 10 + expect(response.status()).toBe(500); 11 + expect(body).toContain("Internal Server Error"); 12 + });
+27 -25
examples/e2e/pages-router/e2e/rewrite.test.ts
··· 3 3 4 4 const EXT_PNG_MD5 = "405f45cc3397b09717a13ebd6f1e027b"; 5 5 6 - test("Single Rewrite", async ({ page }) => { 7 - await page.goto("/rewrite"); 6 + test.describe("Rewrite", () => { 7 + test("Single Rewrite", async ({ page }) => { 8 + await page.goto("/rewrite"); 8 9 9 - const el = page.getByText("Nextjs Pages Router"); 10 - await expect(el).toBeVisible(); 11 - }); 10 + const el = page.getByText("Nextjs Pages Router"); 11 + await expect(el).toBeVisible(); 12 + }); 12 13 13 - test("Rewrite with query", async ({ page }) => { 14 - await page.goto("/rewriteUsingQuery?d=ssr"); 14 + test("Rewrite with query", async ({ page }) => { 15 + await page.goto("/rewriteUsingQuery?d=ssr"); 15 16 16 - const el = page.getByText("SSR"); 17 - await expect(el).toBeVisible(); 18 - }); 17 + const el = page.getByText("SSR"); 18 + await expect(el).toBeVisible(); 19 + }); 19 20 20 - test("Rewrite to external image", async ({ request }) => { 21 - const response = await request.get("/external-on-image"); 22 - expect(response.status()).toBe(200); 23 - expect(response.headers()["content-type"]).toBe("image/png"); 24 - expect(validateMd5(await response.body(), EXT_PNG_MD5)).toBe(true); 25 - }); 21 + test("Rewrite to external image", async ({ request }) => { 22 + const response = await request.get("/external-on-image"); 23 + expect(response.status()).toBe(200); 24 + expect(response.headers()["content-type"]).toBe("image/png"); 25 + expect(validateMd5(await response.body(), EXT_PNG_MD5)).toBe(true); 26 + }); 26 27 27 - test("Rewrite with query in destination", async ({ request }) => { 28 - const response = await request.get("/rewriteWithQuery"); 29 - expect(response.status()).toBe(200); 30 - expect(await response.json()).toEqual({ query: { q: "1" } }); 31 - }); 28 + test("Rewrite with query in destination", async ({ request }) => { 29 + const response = await request.get("/rewriteWithQuery"); 30 + expect(response.status()).toBe(200); 31 + expect(await response.json()).toEqual({ query: { q: "1" } }); 32 + }); 32 33 33 - test("Rewrite with query should merge query params", async ({ request }) => { 34 - const response = await request.get("/rewriteWithQuery?b=2"); 35 - expect(response.status()).toBe(200); 36 - expect(await response.json()).toEqual({ query: { q: "1", b: "2" } }); 34 + test("Rewrite with query should merge query params", async ({ request }) => { 35 + const response = await request.get("/rewriteWithQuery?b=2"); 36 + expect(response.status()).toBe(200); 37 + expect(await response.json()).toEqual({ query: { q: "1", b: "2" } }); 38 + }); 37 39 });
+3
examples/e2e/pages-router/src/middleware.ts
··· 2 2 import { NextResponse } from "next/server"; 3 3 4 4 export function middleware(request: NextRequest) { 5 + if (request.headers.get("x-throw")) { 6 + throw new Error("Middleware error"); 7 + } 5 8 return NextResponse.next({ 6 9 headers: { 7 10 "x-from-middleware": "true",
+62
examples/e2e/pages-router/src/pages/[[...page]].tsx
··· 1 + import Home from "@/components/home"; 2 + import type { GetStaticPathsResult, GetStaticPropsContext, InferGetStaticPropsType } from "next"; 3 + 4 + const validRootPages = ["conico974", "kheuzy", "sommeeer"]; 5 + const validLongPaths = ["super/long/path/to/secret/page"]; 6 + 7 + export async function getStaticPaths(): Promise<GetStaticPathsResult> { 8 + const rootPaths = validRootPages.map((page) => ({ 9 + params: { page: [page] }, 10 + })); 11 + 12 + const longPaths = validLongPaths.map((path) => ({ 13 + params: { page: path.split("/") }, 14 + })); 15 + 16 + const paths = [{ params: { page: [] } }, ...rootPaths, ...longPaths]; 17 + 18 + return { 19 + paths, 20 + fallback: false, 21 + }; 22 + } 23 + 24 + export async function getStaticProps(context: GetStaticPropsContext) { 25 + const page = (context.params?.page as string[]) || []; 26 + 27 + if (page.length === 0) { 28 + return { 29 + props: { 30 + subpage: [], 31 + pageType: "home", 32 + }, 33 + }; 34 + } 35 + if (page.length === 1 && validRootPages.includes(page[0])) { 36 + return { 37 + props: { 38 + subpage: page, 39 + pageType: "root", 40 + }, 41 + }; 42 + } 43 + 44 + const pagePath = page.join("/"); 45 + if (validLongPaths.includes(pagePath)) { 46 + return { props: { subpage: page, pageType: "long-path" } }; 47 + } 48 + return { notFound: true }; 49 + } 50 + 51 + export default function Page({ subpage, pageType }: InferGetStaticPropsType<typeof getStaticProps>) { 52 + if (subpage.length === 0 && pageType === "home") { 53 + return <Home />; 54 + } 55 + return ( 56 + <div> 57 + <h1 data-testid="page">{`Page: ${subpage}`}</h1> 58 + <p>Page type: {pageType}</p> 59 + <p>Path: {subpage.join("/")}</p> 60 + </div> 61 + ); 62 + }
-9
examples/e2e/pages-router/src/pages/index.tsx examples/e2e/pages-router/src/components/home.tsx
··· 1 1 import Nav from "@example/shared/components/Nav"; 2 2 import Head from "next/head"; 3 3 4 - // Not used, but necessary to get prefetching to work 5 - export function getStaticProps() { 6 - return { 7 - props: { 8 - hello: "world", 9 - }, 10 - }; 11 - } 12 - 13 4 export default function Home() { 14 5 return ( 15 6 <>