Repository navigation
Expand file tree
/
Copy pathplaywright.config.js
More file actions
129 lines (117 loc) · 3.09 KB
/
Copy pathplaywright.config.js
File metadata and controls
129 lines (117 loc) · 3.09 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Playwright config for every Publishio E2E run; configure via env vars.
*/
/**
* External dependencies
*/
import path from 'node:path';
import { defineConfig, devices } from '@playwright/test';
/**
* Internal dependencies
*/
import { artifacts, projects, settings, site } from './tests/e2e/config/env';
const viewport = { width: 1280, height: 900 };
const browser = { ...devices[ 'Desktop Chrome' ], viewport };
/**
* @param {string} tags The project's tag pattern, e.g. "@smoke".
* @return {RegExp} Pattern Playwright matches against each test's title and tags.
*/
function projectGrep( tags ) {
const any = [ tags, ...settings.extraTags ].join( '|' );
return settings.update
? new RegExp( `^(?=.*@${ settings.update }\\b)(?=.*(?:${ any }))` )
: new RegExp( any );
}
const usedSites = [
...new Set( Object.values( projects ).map( ( p ) => p.site ) ),
];
const siteProjects = usedSites.flatMap( ( name ) => [
{
name: `setup-${ name }`,
testDir: './tests/e2e/setup',
testMatch: 'site.setup.js',
teardown: `teardown-${ name }`,
// A cold start pulls Docker images.
timeout: 20 * 60_000,
metadata: { site: name },
use: { ...browser, baseURL: site( name ).baseURL },
},
{
name: `teardown-${ name }`,
testDir: './tests/e2e/setup',
testMatch: 'site.teardown.js',
timeout: 5 * 60_000,
metadata: { site: name },
},
] );
const testProjects = Object.entries( projects ).map( ( [ name, project ] ) => {
const s = site( project.site );
return {
name,
testMatch: project.testMatch,
testIgnore: project.testIgnore,
grep: projectGrep( project.grep ),
retries: settings.ci ? project.retries : 0,
timeout: project.timeout,
dependencies: [ `setup-${ project.site }` ],
metadata: {
site: project.site,
wordpress: s.wpLabel,
php: s.phpLabel,
theme: settings.theme,
...( s.plugin === 'zip'
? { zip: path.basename( settings.zip ) }
: {} ),
},
use: { ...browser, baseURL: s.baseURL, storageState: s.storageState },
};
} );
export default defineConfig( {
testDir: './tests/e2e/specs',
outputDir: path.join( artifacts, 'test-results' ),
// One database per site.
fullyParallel: false,
workers: 1,
forbidOnly: settings.ci,
expect: {
timeout: 10_000,
},
reporter: [
[ 'list' ],
[
'html',
{ open: 'never', outputFolder: path.join( artifacts, 'report' ) },
],
[ 'json', { outputFile: path.join( artifacts, 'results.json' ) } ],
...( settings.ci
? [
[ 'github' ],
// Merged across the run's jobs into one report (e2e.yml → report job).
[
'blob',
{
outputDir: path.join( artifacts, 'blob' ),
fileName: `${
process.env.E2E_REPORT_NAME || 'report'
}.zip`,
},
],
]
: [] ),
],
metadata: {
theme: settings.theme,
...( settings.update ? { update: settings.update } : {} ),
...( settings.extraTags.length
? { extraTags: settings.extraTags.join( ' ' ) }
: {} ),
},
use: {
screenshot: 'on',
trace: 'retain-on-failure',
video: 'off',
actionTimeout: 15_000,
launchOptions: { slowMo: settings.slowMo },
},
projects: [ ...siteProjects, ...testProjects ],
} );