1+ /**
2+ * Playwright config for visual regression tests.
3+ *
4+ * Captures full-page screenshots of WordPress admin screens and compares
5+ * them against baseline snapshots. Intended for local use to catch
6+ * unintended visual changes during development.
7+ *
8+ * Usage:
9+ * npm run test:visual -- --update-snapshots # generate baselines
10+ * npm run test:visual # compare against baselines
11+ *
12+ * @see tests/visual-regression/config/screenshot.css for globally hidden elements.
13+ * @see tests/visual-regression/specs/visual-snapshots.test.js for the test spec.
14+ */
15+
116/**
217 * External dependencies
318 */
@@ -15,9 +30,53 @@ process.env.STORAGE_STATE_PATH ??= path.join(
1530 'storage-states/admin.json'
1631) ;
1732
33+ // Reporters:
34+ // - 'list' — prints pass/fail per test in the terminal.
35+ // - 'github' — adds inline PR annotations when running in CI.
36+ // - 'html' — generates a visual report with side-by-side diff images;
37+ // opens automatically after local runs.
38+ const reporter = [
39+ [ 'list' ] ,
40+ ...( process . env . CI ? [ [ 'github' ] ] : [ ] ) ,
41+ [
42+ 'html' ,
43+ {
44+ open : process . env . CI ? 'never' : 'always' ,
45+ outputFolder : path . join (
46+ process . env . WP_ARTIFACTS_PATH ,
47+ 'visual-report'
48+ ) ,
49+ } ,
50+ ] ,
51+ ] ;
52+
1853const config = defineConfig ( {
1954 ...baseConfig ,
20- globalSetup : undefined ,
55+ fullyParallel : true ,
56+ // No retries — visual diffs are expected when regressions exist;
57+ // retrying would just re-confirm the same diff.
58+ retries : 0 ,
59+ // Serialize tests in CI to reduce flakiness from resource contention.
60+ workers : process . env . CI ? 1 : undefined ,
61+ reporter,
62+ use : {
63+ ...baseConfig . use ,
64+ viewport : { width : 1280 , height : 720 } ,
65+ } ,
66+ expect : {
67+ toHaveScreenshot : {
68+ // Only disables CSS animations/transitions. JavaScript-driven
69+ // animations (e.g. jQuery .animate()) can still cause flakes.
70+ animations : 'disabled' ,
71+ // Captures the entire scrollable page, not just the viewport.
72+ // The viewport width (1280) still matters — it controls layout.
73+ fullPage : true ,
74+ // 1% tolerance — catches real regressions while ignoring
75+ // sub-pixel anti-aliasing differences across environments.
76+ maxDiffPixelRatio : 0.01 ,
77+ stylePath : path . join ( __dirname , 'config' , 'screenshot.css' ) ,
78+ } ,
79+ } ,
2180 webServer : {
2281 ...baseConfig . webServer ,
2382 command : 'npm run env:start' ,
0 commit comments