Repository navigation
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
44 lines (40 loc) · 1.74 KB
/
Copy pathplaywright.config.ts
File metadata and controls
44 lines (40 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { PlaywrightTestConfig } from '@playwright/test';
process.env.PW_TEST_SCREENSHOT_NO_FONTS_READY ??= '1';
const baseURL = process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:4173';
const parsedBaseURL = new URL(baseURL);
const isLocalBase = ['127.0.0.1', 'localhost'].includes(parsedBaseURL.hostname);
const localPort = Number(parsedBaseURL.port || 80);
if (isLocalBase && (!Number.isInteger(localPort) || localPort < 1 || localPort > 65535)) {
throw new Error(`Invalid PLAYWRIGHT_BASE_URL port: ${parsedBaseURL.port}`);
}
const localBindHost = parsedBaseURL.hostname === 'localhost' ? '127.0.0.1' : parsedBaseURL.hostname;
const localServerCommand = `python3 -m http.server ${localPort} --bind ${localBindHost} --directory .`;
const reuseExistingServer = process.env.PLAYWRIGHT_REUSE_SERVER === 'true';
const skipBuild = process.env.PLAYWRIGHT_SKIP_BUILD === 'true';
const useSystemChrome = process.env.PLAYWRIGHT_USE_SYSTEM_CHROME === 'true';
const config: PlaywrightTestConfig = {
testDir: './tests',
// Node *.test.mjs suites run in pretest:e2e, where failures stop the command.
// Importing them during Playwright collection does not register their failures.
testMatch: '**/*.spec.ts',
timeout: 180_000,
retries: process.env.CI ? 1 : 0,
use: {
baseURL,
screenshot: 'only-on-failure',
trace: 'retain-on-failure',
...(useSystemChrome ? { channel: 'chrome' } : {})
},
webServer: isLocalBase
? {
// Serve repo root so GitHub Pages-style `/docs/*` assets resolve in local E2E.
command: skipBuild
? localServerCommand
: `npm run build && ${localServerCommand}`,
url: baseURL,
timeout: 120_000,
reuseExistingServer
}
: undefined
};
export default config;