Skip to content

Commit 1debd9b

Browse files
committed
test: add middleware e2e
1 parent 3af28ee commit 1debd9b

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

examples/middleware/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
38+
# playwright
39+
/test-results/
40+
/playwright-report/
41+
/blob-report/
42+
/playwright/.cache/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("redirect", async ({ page }) => {
4+
await page.goto("/");
5+
await page.click('[href="/about"]');
6+
expect(page.waitForURL("**/redirected"));
7+
expect(await page.textContent("h1")).toContain("Redirected");
8+
});
9+
10+
test("rewrite", async ({ page }) => {
11+
await page.goto("/");
12+
await page.click('[href="/another"]');
13+
expect(page.waitForURL("**/another"));
14+
expect(await page.textContent("h1")).toContain("Rewrite");
15+
});
16+
17+
test("noop middleware", async ({ page }) => {
18+
await page.goto("/");
19+
await page.click('[href="/about2"]');
20+
expect(page.waitForURL("**/about2"));
21+
expect(await page.textContent("h1")).toContain("About 2");
22+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
declare const process: { env: Record<string, string> };
4+
5+
/**
6+
* See https://playwright.dev/docs/test-configuration.
7+
*/
8+
export default defineConfig({
9+
testDir: "./",
10+
/* Run tests in files in parallel */
11+
fullyParallel: true,
12+
/* Fail the build on CI if you accidentally left test.only in the source code. */
13+
forbidOnly: !!process.env.CI,
14+
/* Retry on CI only */
15+
retries: process.env.CI ? 2 : 0,
16+
/* Opt out of parallel tests on CI. */
17+
workers: process.env.CI ? 1 : undefined,
18+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
19+
reporter: "html",
20+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
21+
use: {
22+
/* Base URL to use in actions like `await page.goto('/')`. */
23+
baseURL: "http://localhost:8770",
24+
25+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
26+
trace: "on-first-retry",
27+
},
28+
29+
/* Configure projects for major browsers */
30+
projects: [
31+
{
32+
name: "chromium",
33+
use: { ...devices["Desktop Chrome"] },
34+
},
35+
36+
{
37+
name: "firefox",
38+
use: { ...devices["Desktop Firefox"] },
39+
},
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:worker",
50+
url: "http://localhost:8770",
51+
reuseExistingServer: !process.env.CI,
52+
},
53+
});

examples/middleware/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"lint": "next lint",
99
"build:worker": "pnpm cloudflare",
1010
"dev:worker": "wrangler dev --port 8770 --inspector-port 9330",
11-
"preview:worker": "pnpm build:worker && pnpm dev:worker"
11+
"preview:worker": "pnpm build:worker && pnpm dev:worker",
12+
"e2e": "playwright test -c e2e/playwright.config.ts"
1213
},
1314
"dependencies": {
1415
"next": "catalog:",
@@ -17,6 +18,7 @@
1718
},
1819
"devDependencies": {
1920
"@opennextjs/cloudflare": "workspace:*",
21+
"@playwright/test": "catalog:",
2022
"@types/node": "18.0.0",
2123
"@types/react": "catalog:",
2224
"@types/react-dom": "catalog:",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)