Repository navigation
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
76 lines (70 loc) · 3.31 KB
/
Copy pathplaywright.config.ts
File metadata and controls
76 lines (70 loc) · 3.31 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (C) ConfigHub, Inc.
// SPDX-License-Identifier: MIT
import { defineConfig, devices } from '@playwright/test';
import { existsSync } from 'fs';
import dotenv from 'dotenv';
dotenv.config({ path: '.env' });
// To simulate slow CI machines locally, use CPU throttling via CDP:
// SLOW_MODE=1 npx playwright test (6x CPU throttle, like CI)
// SLOW_MODE=4 npx playwright test (custom throttle rate)
// This is applied automatically by tests/fixtures/slow-mode.ts
export const cpuThrottleRate = process.env.SLOW_MODE ? (Number(process.env.SLOW_MODE) || 6) : 0;
// Only use storageState if the file exists (it's generated by globalSetup)
// This prevents Playwright from hanging during config load when file is missing
const storageStatePath = existsSync('authentication.json') ? 'authentication.json' : undefined;
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
timeout: 60000, // Global timeout of 60 seconds per test
// Global timeout for the whole run - allows graceful shutdown and report generation.
// Must stay LOWER than the workflow step timeout (45min, .github/workflows/playwright.yml)
// so Playwright exits gracefully and writes its blob report before the step is killed.
// In CI the suite is sharded, so this budget applies to one shard's slice, not the whole suite.
globalTimeout: process.env.CI ? 40 * 60 * 1000 : undefined, // 40 minutes in CI (5 min buffer before step timeout)
retries: process.env.CI ? 2 : 1,
globalSetup: './global.setup.ts',
/* Run tests in files in parallel */
// In CI the suite is sharded, and --shard splits on whatever Playwright treats
// as a schedulable unit. With fullyParallel the unit is a single test, so one
// spec file can be spread over several shards - and each shard has its own
// database. Specs here routinely depend on data an earlier test in the same
// file created, so a split file fails on the shard that got the reader without
// the writer. Keeping this false in CI makes the unit a whole file, so a file
// always lands in one shard and keeps its declaration order.
fullyParallel: !process.env.CI,
// Use all available CPU cores in CI for maximum parallelization
workers: process.env.CI ? '100%' : 2,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI
? [
// Blob reporter writes results incrementally, ensuring partial results on timeout.
// Each shard emits blob-report/report-<shard>.zip; the merge-reports job combines
// them into the single HTML report for the run.
['blob', { outputDir: 'blob-report' }],
// List reporter prints results to stdout in real time, visible in CI logs even on timeout
['list'],
]
: [['html', { open: 'never' }]],
use: {
/* Collect trace and video only on failure to reduce storage overhead */
trace: 'retain-on-failure',
video: 'retain-on-failure',
screenshot: 'only-on-failure',
baseURL: process.env.TEST_BASE_URL,
browserName: 'chromium',
storageState: storageStatePath,
},
/* Timeout for expect() assertions */
// expect: {
// timeout: 10000,
// },
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
});