Skip to content

Commit 60e7582

Browse files
authored
test: import pages-router from aws (#290)
1 parent e4285a7 commit 60e7582

31 files changed

+768
-1
lines changed

examples/e2e/app-router/sst-env.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SOME_PROD_VAR=bar

examples/e2e/pages-router/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
.open-next
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
.pnpm-debug.log*
28+
29+
# local env files
30+
.env*.local
31+
32+
# vercel
33+
.vercel
34+
35+
# typescript
36+
*.tsbuildinfo
37+
next-env.d.ts
38+
39+
# playwright
40+
/test-results/
41+
/playwright-report/
42+
/blob-report/
43+
/playwright/.cache/

examples/e2e/pages-router/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Pages Router
2+
3+
This project uses the Pages Router exclusively.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("should return 404 on a route not corresponding to any route", async ({ page }) => {
4+
const result = await page.goto("/not-existing/route");
5+
expect(result).toBeDefined();
6+
expect(result?.status()).toBe(404);
7+
const headers = result?.headers();
8+
expect(headers?.["cache-control"]).toBe("private, no-cache, no-store, max-age=0, must-revalidate");
9+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("fix _next/data", async ({ page }) => {
4+
await page.goto("/");
5+
6+
const isrJson = page.waitForResponse("/_next/data/*/en/isr.json");
7+
await page.locator('[href="/isr/"]').click();
8+
const response = await isrJson;
9+
expect(response.ok()).toBe(true);
10+
expect(response.request().url()).toMatch(/\/_next\/data\/.*\/en\/isr\.json$/);
11+
await page.waitForURL("/isr/");
12+
13+
const homeJson = page.waitForResponse("/_next/data/*/en.json");
14+
await page.locator('[href="/"]').click();
15+
const response2 = await homeJson;
16+
expect(response2.ok()).toBe(true);
17+
expect(response2.request().url()).toMatch(/\/_next\/data\/.*\/en\.json$/);
18+
await page.waitForURL("/");
19+
const body = await response2.json();
20+
expect(body).toEqual({ pageProps: { hello: "world" }, __N_SSG: true });
21+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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("/");
5+
expect(result).toBeDefined();
6+
expect(result?.status()).toBe(200);
7+
const headers = result?.headers();
8+
9+
// Both these headers should be present cause poweredByHeader is true in pagesRouter
10+
expect(headers?.["x-powered-by"]).toBe("Next.js");
11+
expect(headers?.["x-opennext"]).toBe("1");
12+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("Next config headers with i18n", async ({ page }) => {
4+
const responsePromise = page.waitForResponse((response) => {
5+
return response.status() === 200;
6+
});
7+
await page.goto("/");
8+
9+
const response = await responsePromise;
10+
// Response header should be set
11+
const headers = response.headers();
12+
// Headers from next.config.js should be set
13+
expect(headers["x-custom-header"]).toEqual("my custom header value");
14+
15+
// Headers from middleware should be set
16+
expect(headers["x-from-middleware"]).toEqual("true");
17+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("Incremental Static Regeneration", async ({ page }) => {
4+
test.setTimeout(45000);
5+
await page.goto("/");
6+
await page.locator("[href='/isr/']").click();
7+
await page.waitForURL("/isr/");
8+
// Load the page a couple times to regenerate ISR
9+
10+
let el = page.getByText("Time:");
11+
// Track the static time
12+
let time = await el.textContent();
13+
let newTime: typeof time;
14+
let tempTime = time;
15+
do {
16+
await page.waitForTimeout(1000);
17+
await page.reload();
18+
time = tempTime;
19+
el = page.getByText("Time:");
20+
newTime = await el.textContent();
21+
tempTime = newTime;
22+
} while (time !== newTime);
23+
await page.reload();
24+
await page.waitForTimeout(1000);
25+
el = page.getByText("Time:");
26+
const midTime = await el.textContent();
27+
// Expect that the time is still stale
28+
expect(midTime).toEqual(newTime);
29+
30+
// Wait 10 + 1 seconds for ISR to regenerate time
31+
await page.waitForTimeout(11000);
32+
let finalTime = newTime;
33+
do {
34+
await page.waitForTimeout(2000);
35+
el = page.getByText("Time:");
36+
finalTime = await el.textContent();
37+
await page.reload();
38+
} while (newTime === finalTime);
39+
40+
expect(newTime).not.toEqual(finalTime);
41+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
import type nodeProcess from "node:process";
3+
4+
declare const process: typeof nodeProcess;
5+
6+
/**
7+
* See https://playwright.dev/docs/test-configuration.
8+
*/
9+
export default defineConfig({
10+
testDir: "./",
11+
/* Run tests in files in parallel */
12+
fullyParallel: true,
13+
/* Fail the build on CI if you accidentally left test.only in the source code. */
14+
forbidOnly: !!process.env.CI,
15+
/* Retry on CI only */
16+
retries: process.env.CI ? 2 : 0,
17+
/* Opt out of parallel tests on CI. */
18+
workers: process.env.CI ? 1 : undefined,
19+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
20+
reporter: "html",
21+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
22+
use: {
23+
/* Base URL to use in actions like `await page.goto('/')`. */
24+
baseURL: "http://localhost:8791",
25+
26+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
27+
trace: "on-first-retry",
28+
},
29+
30+
/* Configure projects for major browsers */
31+
projects: [
32+
{
33+
name: "chromium",
34+
use: { ...devices["Desktop Chrome"] },
35+
},
36+
// TODO(vicb): enable all browsers
37+
// {
38+
// name: "firefox",
39+
// use: { ...devices["Desktop Firefox"] },
40+
// },
41+
// {
42+
// name: "webkit",
43+
// use: { ...devices["Desktop Safari"] },
44+
// },
45+
],
46+
47+
/* Run your local dev server before starting the tests */
48+
webServer: {
49+
command: "pnpm preview",
50+
url: "http://localhost:8791",
51+
reuseExistingServer: !process.env.CI,
52+
timeout: 70_000,
53+
},
54+
});

0 commit comments

Comments
 (0)