-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathplaywright.config.js
More file actions
86 lines (80 loc) · 2.53 KB
/
playwright.config.js
File metadata and controls
86 lines (80 loc) · 2.53 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
/**
* Playwright config for visual regression tests.
*
* Captures full-page screenshots of WordPress admin screens and compares
* them against baseline snapshots. Intended for local use to catch
* unintended visual changes during development.
*
* Usage:
* npm run test:visual -- --update-snapshots # generate baselines
* npm run test:visual # compare against baselines
*
* @see tests/visual-regression/config/screenshot.css for globally hidden elements.
* @see tests/visual-regression/specs/visual-snapshots.test.js for the test spec.
*/
/**
* External dependencies
*/
import path from 'node:path';
import { defineConfig } from '@playwright/test';
/**
* WordPress dependencies
*/
const baseConfig = require( '@wordpress/scripts/config/playwright.config' );
process.env.WP_ARTIFACTS_PATH ??= path.join( process.cwd(), 'artifacts' );
process.env.STORAGE_STATE_PATH ??= path.join(
process.env.WP_ARTIFACTS_PATH,
'storage-states/admin.json'
);
// Reporters:
// - 'list' — prints pass/fail per test in the terminal.
// - 'github' — adds inline PR annotations when running in CI.
// - 'html' — generates a visual report with side-by-side diff images;
// opens automatically after local runs.
const reporter = [
[ 'list' ],
...( process.env.CI ? [ [ 'github' ] ] : [] ),
[
'html',
{
open: process.env.CI ? 'never' : 'always',
outputFolder: path.join(
process.env.WP_ARTIFACTS_PATH,
'visual-report'
),
},
],
];
const config = defineConfig( {
...baseConfig,
fullyParallel: true,
// No retries — visual diffs are expected when regressions exist;
// retrying would just re-confirm the same diff.
retries: 0,
// Serialize tests in CI to reduce flakiness from resource contention.
workers: process.env.CI ? 1 : undefined,
reporter,
use: {
...baseConfig.use,
viewport: { width: 1280, height: 720 },
},
expect: {
toHaveScreenshot: {
// Only disables CSS animations/transitions. JavaScript-driven
// animations (e.g. jQuery .animate()) can still cause flakes.
animations: 'disabled',
// Captures the entire scrollable page, not just the viewport.
// The viewport width (1280) still matters — it controls layout.
fullPage: true,
// 1% tolerance — catches real regressions while ignoring
// sub-pixel anti-aliasing differences across environments.
maxDiffPixelRatio: 0.01,
stylePath: path.join( __dirname, 'config', 'screenshot.css' ),
},
},
webServer: {
...baseConfig.webServer,
command: 'npm run env:start',
},
} );
export default config;