-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplaywright.config.ts
116 lines (103 loc) · 3 KB
/
playwright.config.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { devices, PlaywrightTestConfig, ReporterDescription } from '@playwright/test';
import os from 'node:os';
enum Reporter {
HTML = 'html',
List = 'list',
CI = 'github'
}
/**
* Customize reporters.
* By default, we want to have a standard list reporting and a pretty HTML output.
* In CI pipelines, we want to have an annotated report visible on the GitHub Actions page.
*/
const addReporter = (): ReporterDescription[] => {
const defaultReporter: ReporterDescription[] = [
[Reporter.List],
[Reporter.HTML],
];
if (isPipeline) {
return defaultReporter.concat([[Reporter.CI]]);
}
return defaultReporter;
}
// Default development URL - change if necessary
const DEV_URL = 'http://localhost:3000';
// Check whether tests are running as part of a CI/CD pipeline
const isPipeline = !!process.env.CI;
// Match pixel comparison at least 95 % to avoid flaky tests but ensure enough confidence
const threshold = 0.95;
// Use all the logical cores available for maximum performance
const workers = '100%';
// Ensure we are not wasting build minutes in CI by operating in a fail-fast mode
const maxFailures = isPipeline ? 1 : undefined;
// Increase the default test timeout to 60 seconds to allow more resiliency
const timeout = 60 * 1000;
// Potentially interesting metadata to append into the test report – might help with debugging
const metadata: Record<string, string> = {
cpu: os.arch(),
memory: `${os.totalmem() / (1024 ** 2)} MB`,
hostname: os.hostname(),
system: os.type(),
kernel: os.version(),
};
const config: PlaywrightTestConfig = {
name: 'Playwright Acceptance Test Suite',
preserveOutput: 'failures-only',
testDir: 'tests',
fullyParallel: true,
forbidOnly: isPipeline,
reporter: addReporter(),
retries: 1,
timeout,
workers,
metadata,
maxFailures,
webServer: process.env.APP_URL
? undefined
: {
command: 'yarn serve',
url: DEV_URL,
reuseExistingServer: !isPipeline,
timeout: 120 * 1000,
},
use: {
headless: true,
baseURL: process.env.APP_URL ?? DEV_URL,
userAgent: 'Microsoft Playwright',
locale: 'en-GB',
colorScheme: 'dark',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
trace: 'retain-on-failure',
},
expect: {
toMatchSnapshot: { threshold },
},
projects: [
{
name: 'Firefox',
...devices[ 'Desktop Firefox' ],
},
{
name: 'Chromium',
...devices[ 'Desktop Chrome' ],
},
{
name: 'Edge',
...devices[ 'Desktop Edge' ],
},
{
name: 'Safari',
...devices[ 'Desktop Safari' ],
},
{
name: 'iPhone 13',
...devices[ 'iPhone 13' ],
},
{
name: 'Pixel 5',
...devices[ 'Pixel 5' ],
}
]
};
export default config;