Skip to content

Commit 12d6e4c

Browse files
committed
factor playwright configs
1 parent 29dcfe4 commit 12d6e4c

File tree

27 files changed

+182
-582
lines changed

27 files changed

+182
-582
lines changed
Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,3 @@
1-
import { defineConfig, devices } from "@playwright/test";
2-
import type nodeProcess from "node:process";
1+
import { configurePlaywright } from "../../common/config-e2e";
32

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:8770",
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-
37-
{
38-
name: "firefox",
39-
use: { ...devices["Desktop Firefox"] },
40-
},
41-
42-
{
43-
name: "webkit",
44-
use: { ...devices["Desktop Safari"] },
45-
},
46-
],
47-
48-
/* Run your local dev server before starting the tests */
49-
webServer: {
50-
command: "pnpm preview",
51-
url: "http://localhost:8770",
52-
reuseExistingServer: !process.env.CI,
53-
timeout: 500_000,
54-
},
55-
});
3+
export default configurePlaywright("api", { isCI: !!process.env.CI });
Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,7 @@
1-
import { defineConfig, devices } from "@playwright/test";
2-
import type nodeProcess from "node:process";
1+
import { configurePlaywright } from "../../common/config-e2e";
32

4-
declare const process: typeof nodeProcess;
5-
6-
/**
7-
* See https://playwright.dev/docs/test-configuration.
8-
*/
9-
export default defineConfig({
10-
testDir: "./",
11-
testIgnore: "cloudflare.spec.ts",
12-
/* Run tests in files in parallel */
13-
fullyParallel: true,
14-
/* Fail the build on CI if you accidentally left test.only in the source code. */
15-
forbidOnly: !!process.env.CI,
16-
/* Retry on CI only */
17-
retries: process.env.CI ? 2 : 0,
18-
/* Opt out of parallel tests on CI. */
19-
workers: process.env.CI ? 1 : undefined,
20-
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
21-
reporter: "html",
22-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
23-
use: {
24-
/* Base URL to use in actions like `await page.goto('/')`. */
25-
baseURL: "http://localhost:3333",
26-
27-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
28-
trace: "on-first-retry",
29-
},
30-
31-
/* Configure projects for major browsers */
32-
projects: [
33-
{
34-
name: "chromium",
35-
use: { ...devices["Desktop Chrome"] },
36-
},
37-
38-
{
39-
name: "firefox",
40-
use: { ...devices["Desktop Firefox"] },
41-
},
42-
43-
{
44-
name: "webkit",
45-
use: { ...devices["Desktop Safari"] },
46-
},
47-
],
48-
49-
/* Run your local dev server before starting the tests */
50-
webServer: {
51-
command: "pnpm dev --port 3333",
52-
url: "http://localhost:3333",
53-
reuseExistingServer: !process.env.CI,
54-
},
3+
export default configurePlaywright("api", {
4+
isCI: !!process.env.CI,
5+
isWorker: false,
6+
multipleBrowsers: false,
557
});

examples/api/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"start": "next start",
1010
"lint": "next lint",
1111
"build:worker": "pnpm opennextjs-cloudflare",
12-
"dev:worker": "wrangler dev --port 8770",
13-
"preview": "pnpm build:worker && pnpm dev:worker",
12+
"preview": "pnpm build:worker && pnpm wrangler dev",
1413
"e2e": "playwright test -c e2e/playwright.config.ts",
1514
"e2e:dev": "playwright test -c e2e/playwright.dev.config.ts",
1615
"cf-typegen": "wrangler types --env-interface CloudflareEnv"
Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
1-
import { defineConfig, devices } from "@playwright/test";
2-
import type nodeProcess from "node:process";
1+
import { configurePlaywright } from "../../../common/config-e2e";
32

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:8750",
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-
],
37-
38-
/* Run your local dev server before starting the tests */
39-
webServer: {
40-
command: "pnpm preview",
41-
url: "http://localhost:8750",
42-
reuseExistingServer: !process.env.CI,
43-
timeout: 500_000,
44-
},
45-
});
3+
export default configurePlaywright("gh-119", { isCI: !!process.env.CI, multipleBrowsers: false });

examples/bugs/gh-119/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"start": "next start",
99
"lint": "next lint",
1010
"build:worker": "pnpm opennextjs-cloudflare",
11-
"dev:worker": "wrangler dev --port 8750",
12-
"preview": "pnpm build:worker && pnpm dev:worker",
11+
"preview": "pnpm build:worker && pnpm wrangler dev",
1312
"e2e": "playwright test -c e2e/playwright.config.ts",
1413
"cf-typegen": "wrangler types --env-interface CloudflareEnv"
1514
},
Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
1-
import { defineConfig, devices } from "@playwright/test";
2-
import type nodeProcess from "node:process";
1+
import { configurePlaywright } from "../../../common/config-e2e";
32

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:8751",
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-
],
37-
38-
/* Run your local dev server before starting the tests */
39-
webServer: {
40-
command: "pnpm preview",
41-
url: "http://localhost:8751",
42-
reuseExistingServer: !process.env.CI,
43-
timeout: 500_000,
44-
},
45-
});
3+
export default configurePlaywright("gh-219", { isCI: !!process.env.CI, multipleBrowsers: false });

examples/bugs/gh-219/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"start": "next start",
99
"lint": "next lint",
1010
"build:worker": "opennextjs-cloudflare",
11-
"dev:worker": "wrangler dev --port 8751",
12-
"preview": "npm run build:worker && npm run dev:worker",
11+
"preview": "npm run build:worker && npx wrangler dev",
1312
"e2e": "playwright test -c e2e/playwright.config.ts",
1413
"deploy:worker": "npm run build:worker && wrangler deploy"
1514
},
Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
1-
import { defineConfig, devices } from "@playwright/test";
2-
import type nodeProcess from "node:process";
1+
import { configurePlaywright } from "../../../common/config-e2e";
32

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:8752",
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-
],
37-
38-
/* Run your local dev server before starting the tests */
39-
webServer: {
40-
command: "pnpm preview",
41-
url: "http://localhost:8752",
42-
reuseExistingServer: !process.env.CI,
43-
timeout: 500_000,
44-
},
45-
});
3+
export default configurePlaywright("gh-223", { isCI: !!process.env.CI, multipleBrowsers: false });

examples/bugs/gh-223/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"start": "next start",
99
"lint": "next lint",
1010
"build:worker": "opennextjs-cloudflare",
11-
"dev:worker": "wrangler dev --port 8752",
12-
"preview": "npm run build:worker && npm run dev:worker",
11+
"preview": "npm run build:worker && npx wrangler dev",
1312
"e2e": "playwright test -c e2e/playwright.config.ts",
1413
"deploy:worker": "npm run build:worker && wrangler deploy"
1514
},

examples/common/apps.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// List of all e2e tested apps
2+
const apps = [
3+
// examples
4+
"api",
5+
"create-next-app",
6+
"middleware",
7+
"vercel-blog-starter",
8+
"vercel-commerce",
9+
// // e2e
10+
"app-pages-router",
11+
"app-router",
12+
"pages-router",
13+
// // bugs
14+
"gh-119",
15+
"gh-219",
16+
"gh-223",
17+
] as const;
18+
19+
export type AppName = (typeof apps)[number];
20+
21+
const BASE_WRANGLER_PORT = 8770;
22+
const BASE_NEXT_PORT = 3100;
23+
24+
/**
25+
* Returns a distinct port for each application so they can run in parallel.
26+
*/
27+
export function getAppPort(app: AppName, { isWorker = true } = {}) {
28+
const index = apps.indexOf(app);
29+
if (index === -1) {
30+
throw new Error(`Unknown app: ${app}`);
31+
}
32+
return isWorker ? BASE_WRANGLER_PORT + index : BASE_NEXT_PORT + index;
33+
}

0 commit comments

Comments
 (0)