@greendrake/e2e 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +2 -2
- package/src/playwrightConfig.ts +13 -7
package/README.md
CHANGED
|
@@ -19,14 +19,14 @@ import { spaPlaywright } from '@greendrake/e2e'
|
|
|
19
19
|
export default spaPlaywright({ defaultPort: '5173' })
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
The frontend port is `VITE_PORT`, falling back to `defaultPort` — the variable the app's own Vite config is expected to pin its dev server to, so the config targets the server the app actually started. Omit `defaultPort` in an app whose harness always supplies `VITE_PORT`: a missing port then throws rather than silently testing whatever happens to be listening on a default.
|
|
22
|
+
The frontend port is `VITE_PORT`, falling back to `defaultPort` — the variable the app's own Vite config is expected to pin its dev server to, so the config targets the server the app actually started. Omit `defaultPort` in an app whose harness always supplies `VITE_PORT`: a missing port then throws rather than silently testing whatever happens to be listening on a default. An app its own backend serves passes that origin as `baseURL` instead, and `VITE_PORT` is not read.
|
|
23
23
|
|
|
24
24
|
What it returns (a `PlaywrightTestConfig` via `defineConfig`):
|
|
25
25
|
|
|
26
26
|
- `testDir: './tests'`, `fullyParallel: true`, `workers: 5`, `retries: 0`, `forbidOnly` when `CI` is set.
|
|
27
27
|
- `timeout: 120_000` — crawl-style specs visit every page and click through every link; Playwright's 30s default is sized for single-interaction tests.
|
|
28
28
|
- Reporter: `html`, `open: 'never'`.
|
|
29
|
-
- `use`: `baseURL` `http://localhost:<port
|
|
29
|
+
- `use`: `baseURL` `http://localhost:<port>` (or the `baseURL` given), `trace: 'on-first-retry'`, `video: 'retain-on-failure'`.
|
|
30
30
|
- One project, `chromium`, on `devices['Desktop Chrome']`.
|
|
31
31
|
- No `webServer`: the app, and whatever backs it, are started by the caller.
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greendrake/e2e",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Playwright kit for single-page apps: config factories, a same-origin crawler, a clipped-content detector, a polling helper and a layout checker",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eugene Greendrake <eugene@greendrake.nz>",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@playwright/test": ">=1.49.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@greendrake/dev-config": "0.
|
|
48
|
+
"@greendrake/dev-config": "0.7.0",
|
|
49
49
|
"@playwright/test": "1.60.0",
|
|
50
50
|
"typescript": "6.0.3"
|
|
51
51
|
}
|
package/src/playwrightConfig.ts
CHANGED
|
@@ -6,17 +6,24 @@ export interface SpaPlaywrightOptions {
|
|
|
6
6
|
// then fails the run rather than silently testing whatever happens to be
|
|
7
7
|
// listening on a default.
|
|
8
8
|
defaultPort?: string
|
|
9
|
+
// The app's origin, for an app its own backend serves rather than a dev
|
|
10
|
+
// server: VITE_PORT is then not read at all.
|
|
11
|
+
baseURL?: string
|
|
9
12
|
overrides?: PlaywrightTestConfig
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const spaPlaywright = (options: SpaPlaywrightOptions = {}): PlaywrightTestConfig => {
|
|
15
|
-
const port = process.env.VITE_PORT || options.defaultPort
|
|
15
|
+
const devServerURL = (defaultPort?: string): string => {
|
|
16
|
+
const port = process.env.VITE_PORT || defaultPort
|
|
16
17
|
if (!port) {
|
|
17
18
|
throw new Error('spaPlaywright: VITE_PORT must be set (this app configures no defaultPort)')
|
|
18
19
|
}
|
|
19
|
-
return
|
|
20
|
+
return `http://localhost:${port}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The config an SPA would otherwise hand-copy: chromium-only, ./tests dir, an
|
|
24
|
+
// html reporter that never auto-opens, and a baseURL built from VITE_PORT.
|
|
25
|
+
export const spaPlaywright = (options: SpaPlaywrightOptions = {}): PlaywrightTestConfig =>
|
|
26
|
+
defineConfig({
|
|
20
27
|
testDir: './tests',
|
|
21
28
|
fullyParallel: true,
|
|
22
29
|
forbidOnly: !!process.env.CI,
|
|
@@ -27,7 +34,7 @@ export const spaPlaywright = (options: SpaPlaywrightOptions = {}): PlaywrightTes
|
|
|
27
34
|
timeout: 120_000,
|
|
28
35
|
reporter: [['html', { open: 'never' }]],
|
|
29
36
|
use: {
|
|
30
|
-
baseURL:
|
|
37
|
+
baseURL: options.baseURL ?? devServerURL(options.defaultPort),
|
|
31
38
|
trace: 'on-first-retry',
|
|
32
39
|
video: 'retain-on-failure'
|
|
33
40
|
},
|
|
@@ -39,4 +46,3 @@ export const spaPlaywright = (options: SpaPlaywrightOptions = {}): PlaywrightTes
|
|
|
39
46
|
],
|
|
40
47
|
...options.overrides
|
|
41
48
|
})
|
|
42
|
-
}
|