Skip to content

Commit af6472a

Browse files
Add e2e tests to create-next-app example
1 parent 6878b74 commit af6472a

File tree

8 files changed

+145
-20
lines changed

8 files changed

+145
-20
lines changed

examples/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"e2e": "playwright test"
1515
},
1616
"dependencies": {
17-
"builder": "workspace:*",
1817
"next": "14.2.5",
1918
"react": "^18",
2019
"react-dom": "^18"
2120
},
2221
"devDependencies": {
22+
"builder": "workspace:*",
2323
"@playwright/test": "1.47.0",
2424
"@types/node": "^22.2.0",
2525
"node-url": "npm:url@^0.11.4",

examples/create-next-app/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
38+
# wrangler
39+
.wrangler
40+
41+
# playwright
42+
/test-results/
43+
/playwright-report/
44+
/blob-report/
45+
/playwright/.cache/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("the index page of the application shows the Next.js logo", async ({
4+
page,
5+
}) => {
6+
await page.goto("http://localhost:8770/");
7+
await expect(page.getByAltText("Next.js logo")).toBeVisible();
8+
});
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
declare const process: { env: Record<string, string> };
4+
5+
/**
6+
* Read environment variables from file.
7+
* https://github.com/motdotla/dotenv
8+
*/
9+
// import dotenv from 'dotenv';
10+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
11+
12+
/**
13+
* See https://playwright.dev/docs/test-configuration.
14+
*/
15+
export default defineConfig({
16+
testDir: "./",
17+
/* Run tests in files in parallel */
18+
fullyParallel: true,
19+
/* Fail the build on CI if you accidentally left test.only in the source code. */
20+
forbidOnly: !!process.env.CI,
21+
/* Retry on CI only */
22+
retries: process.env.CI ? 2 : 0,
23+
/* Opt out of parallel tests on CI. */
24+
workers: process.env.CI ? 1 : undefined,
25+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
26+
reporter: "html",
27+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
28+
use: {
29+
/* Base URL to use in actions like `await page.goto('/')`. */
30+
// baseURL: 'http://127.0.0.1:3000',
31+
32+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
33+
trace: "on-first-retry",
34+
},
35+
36+
/* Configure projects for major browsers */
37+
projects: [
38+
{
39+
name: "chromium",
40+
use: { ...devices["Desktop Chrome"] },
41+
},
42+
43+
{
44+
name: "firefox",
45+
use: { ...devices["Desktop Firefox"] },
46+
},
47+
48+
{
49+
name: "webkit",
50+
use: { ...devices["Desktop Safari"] },
51+
},
52+
53+
/* Test against mobile viewports. */
54+
// {
55+
// name: 'Mobile Chrome',
56+
// use: { ...devices['Pixel 5'] },
57+
// },
58+
// {
59+
// name: 'Mobile Safari',
60+
// use: { ...devices['iPhone 12'] },
61+
// },
62+
63+
/* Test against branded browsers. */
64+
// {
65+
// name: 'Microsoft Edge',
66+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
67+
// },
68+
// {
69+
// name: 'Google Chrome',
70+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
71+
// },
72+
],
73+
74+
/* Run your local dev server before starting the tests */
75+
webServer: {
76+
command: "pnpm preview:worker",
77+
url: "http://localhost:8770",
78+
reuseExistingServer: !process.env.CI,
79+
},
80+
});

examples/create-next-app/package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"prepreview": "node ../../builder/dist/index.mjs",
11-
"preview": "wrangler dev"
10+
"build:worker": "builder",
11+
"dev:worker": "wrangler dev --port 8770",
12+
"preview:worker": "pnpm build:worker && pnpm dev:worker",
13+
"pree2e": "playwright install --with-deps",
14+
"e2e": "playwright test -c e2e/playwright.config.ts"
1215
},
1316
"dependencies": {
1417
"react": "^18",
1518
"react-dom": "^18",
1619
"next": "14.2.11"
1720
},
1821
"devDependencies": {
19-
"typescript": "^5",
22+
"builder": "workspace:*",
23+
"@playwright/test": "1.47.0",
2024
"@types/node": "^20",
2125
"@types/react": "^18",
2226
"@types/react-dom": "^18",
23-
"postcss": "^8",
24-
"tailwindcss": "^3.4.1",
25-
"node-url": "npm:url@^0.11.4",
2627
"eslint": "^8",
2728
"eslint-config-next": "14.2.11",
29+
"postcss": "^8",
30+
"node-url": "npm:url@^0.11.4",
31+
"tailwindcss": "^3.4.1",
32+
"typescript": "^5",
2833
"wrangler": "^3.77.0"
2934
}
3035
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"name": "POC-NextJS",
2+
"name": "poc-next",
3+
"version": "0.0.0.0",
4+
"private": true,
35
"devDependencies": {
46
"prettier": "3.3.3"
57
},

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
packages:
22
- "builder"
33
- "examples/*"
4+
5+
catalog:
6+
"@playwright/test": 1.47.0
7+
"@types/node": ^22.2.0
8+
"@types/react": ^18
9+
"@types/react-dom": ^18
10+
"eslint": ^8
11+
"eslint-config-next": 14.2.11
12+
"next": 14.2.11
13+
"react": ^18
14+
"react-dom": ^18
15+
"typescript": ^5.5.4
16+
"wrangler": ^3.77.0
17+
18+

0 commit comments

Comments
 (0)