Skip to content

Commit b198749

Browse files
add playwright test for testing dev mode too
1 parent 26bc5bb commit b198749

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

examples/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dev:worker": "wrangler dev --port 8770",
1212
"preview:worker": "pnpm build:worker && pnpm dev:worker",
1313
"e2e": "playwright test",
14+
"e2e:dev": "playwright test -c playwright.dev.config.ts",
1415
"cf-typegen": "wrangler types --env-interface CloudflareEnv"
1516
},
1617
"dependencies": {
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 var 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: "./e2e-tests",
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://localhost:3333",
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 dev --port 3333",
77+
url: "http://localhost:3333",
78+
reuseExistingServer: !process.env.CI,
79+
},
80+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"prettier:fix": "prettier --write .",
1212
"postinstall": "pnpm --filter cloudflare build",
1313
"install-playwright": "playwright install --with-deps",
14-
"e2e": "pnpm -r e2e"
14+
"e2e": "pnpm -r e2e",
15+
"e2e:dev": "pnpm -r e2e:dev"
1516
}
1617
}

0 commit comments

Comments
 (0)