Skip to content

Commit 656f698

Browse files
committed
Tests: Improve visual regression workflow for admin reskin iteration
Add impact summary reporter, fast re-run mode, and auto-open HTML report to streamline CSS iteration during the admin reskin effort.
1 parent 1a4e1e9 commit 656f698

5 files changed

Lines changed: 155 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"test:coverage": "npm run test:php -- --coverage-html ./coverage/html/ --coverage-php ./coverage/php/report.php --coverage-text=./coverage/text/report.txt",
131131
"test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js",
132132
"test:visual": "bash tests/visual-regression/compare-branches.sh",
133+
"test:visual:quick": "bash tests/visual-regression/compare-branches.sh --skip-baselines",
133134
"gutenberg:checkout": "node tools/gutenberg/checkout-gutenberg.js",
134135
"gutenberg:build": "node tools/gutenberg/build-gutenberg.js",
135136
"gutenberg:copy": "node tools/gutenberg/copy-gutenberg-build.js",

tests/visual-regression/README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
These tests make use of Playwright, with a setup very similar to that of the e2e tests.
44

5+
## Prerequisites
6+
7+
- Node.js >= 20.10.0
8+
- A running WordPress environment (`npm run env:start`)
9+
- Playwright browsers installed (`npx playwright install chromium`)
10+
511
## How to Run the Tests Locally
612

713
From a feature branch with a clean working tree, run:
@@ -14,8 +20,27 @@ This will automatically:
1420
1. Check out trunk to generate baseline snapshots.
1521
2. Return to your feature branch.
1622
3. Compare the current branch against those baselines.
23+
4. Print a visual impact summary in the terminal.
24+
5. Open the HTML report with side-by-side visual diffs.
25+
26+
### Quick Re-run (Skip Baseline Generation)
1727

18-
If any tests fail, diff images can be found in `artifacts/`.
28+
After the first run, baselines from trunk are already saved. To re-compare without regenerating them:
29+
30+
```bash
31+
npm run test:visual:quick
32+
```
33+
34+
This is useful when iterating on CSS — no need to commit changes or wait for trunk baselines to regenerate each time.
35+
36+
**Typical workflow:**
37+
```bash
38+
npm run test:visual # First run: generates baselines from trunk
39+
# ... tweak CSS ...
40+
npm run test:visual:quick # Fast: reuses existing baselines
41+
# ... tweak more CSS ...
42+
npm run test:visual:quick # Fast again
43+
```
1944

2045
### Specifying a Base Branch
2146

@@ -33,3 +58,24 @@ You can also generate baselines and compare manually:
3358
2. Run `npx playwright test --config tests/visual-regression/playwright.config.js --update-snapshots`
3459
3. Check out the feature branch to be tested.
3560
4. Run `npx playwright test --config tests/visual-regression/playwright.config.js`
61+
62+
## Impact Summary
63+
64+
After each run, a summary is printed to the terminal showing which pages changed and which remained unchanged:
65+
66+
```
67+
────────────────────────────────────────────────
68+
Visual Impact Summary
69+
────────────────────────────────────────────────
70+
Changed: 27 of 35 pages
71+
Unchanged: 8 of 35 pages
72+
73+
Changed:
74+
Dashboard, All Posts, Categories, Tags, ...
75+
76+
Unchanged:
77+
Login, Media Settings, ...
78+
────────────────────────────────────────────────
79+
```
80+
81+
The HTML report also opens automatically with side-by-side visual diffs for detailed inspection.
Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
#!/bin/bash
22
set -e
33

4+
SKIP_BASELINES=false
5+
BASELINE_BRANCH="trunk"
6+
7+
# Parse arguments.
8+
for arg in "$@"; do
9+
case "$arg" in
10+
--skip-baselines)
11+
SKIP_BASELINES=true
12+
;;
13+
*)
14+
BASELINE_BRANCH="$arg"
15+
;;
16+
esac
17+
done
18+
419
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
5-
BASELINE_BRANCH="${1:-trunk}"
620
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
721
CONFIG="$SCRIPT_DIR/playwright.config.js"
822

@@ -11,15 +25,34 @@ if [ "$CURRENT_BRANCH" = "$BASELINE_BRANCH" ]; then
1125
exit 1
1226
fi
1327

14-
if ! git diff-index --quiet HEAD --; then
15-
echo "Error: Uncommitted changes detected. Please commit or stash before running."
16-
exit 1
17-
fi
28+
if [ "$SKIP_BASELINES" = true ]; then
29+
# Verify baselines exist before skipping regeneration.
30+
SNAPSHOT_DIR="$SCRIPT_DIR/specs/__snapshots__"
31+
if [ ! -d "$SNAPSHOT_DIR" ] || [ -z "$(ls -A "$SNAPSHOT_DIR" 2>/dev/null)" ]; then
32+
echo "Error: No baselines found. Run 'npm run test:visual' first to generate them."
33+
exit 1
34+
fi
1835

19-
echo "Generating baselines from $BASELINE_BRANCH..."
20-
git checkout "$BASELINE_BRANCH"
21-
npx playwright test --config "$CONFIG" --update-snapshots
36+
echo "Skipping baseline generation (reusing existing baselines)..."
37+
echo "Ensuring Playwright browsers are installed..."
38+
npx playwright install --with-deps chromium
2239

23-
echo "Comparing against $CURRENT_BRANCH..."
24-
git checkout "$CURRENT_BRANCH"
25-
npx playwright test --config "$CONFIG"
40+
echo "Comparing against existing baselines..."
41+
npx playwright test --config "$CONFIG" || true
42+
else
43+
if ! git diff-index --quiet HEAD --; then
44+
echo "Error: Uncommitted changes detected. Please commit or stash before running."
45+
exit 1
46+
fi
47+
48+
echo "Ensuring Playwright browsers are installed..."
49+
npx playwright install --with-deps chromium
50+
51+
echo "Generating baselines from $BASELINE_BRANCH..."
52+
git checkout "$BASELINE_BRANCH"
53+
npx playwright test --config "$CONFIG" --update-snapshots
54+
55+
echo "Comparing against $CURRENT_BRANCH..."
56+
git checkout "$CURRENT_BRANCH"
57+
npx playwright test --config "$CONFIG" || true
58+
fi

tests/visual-regression/playwright.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ const reporter = [
2020
[
2121
'html',
2222
{
23-
open: 'on-failure',
23+
open: process.env.CI ? 'never' : 'always',
2424
outputFolder: path.join(
2525
process.env.WP_ARTIFACTS_PATH,
2626
'visual-report'
2727
),
2828
},
2929
],
30+
[ './reporters/impact-summary.js' ],
3031
];
3132

3233
const config = defineConfig( {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Impact Summary Reporter
3+
*
4+
* A custom Playwright reporter that prints a visual impact summary
5+
* at the end of the test run, showing which pages changed and which
6+
* remained unchanged.
7+
*/
8+
class ImpactSummaryReporter {
9+
constructor() {
10+
this.changed = [];
11+
this.unchanged = [];
12+
}
13+
14+
onTestEnd( test, result ) {
15+
const name = test.title;
16+
17+
if ( result.status === 'passed' ) {
18+
this.unchanged.push( name );
19+
} else {
20+
this.changed.push( name );
21+
}
22+
}
23+
24+
onEnd() {
25+
const total = this.changed.length + this.unchanged.length;
26+
27+
if ( total === 0 ) {
28+
return;
29+
}
30+
31+
const separator = '─'.repeat( 48 );
32+
33+
console.log( '' );
34+
console.log( separator );
35+
console.log( 'Visual Impact Summary' );
36+
console.log( separator );
37+
console.log(
38+
`Changed: ${ this.changed.length } of ${ total } pages`
39+
);
40+
console.log(
41+
`Unchanged: ${ this.unchanged.length } of ${ total } pages`
42+
);
43+
44+
if ( this.changed.length > 0 ) {
45+
console.log( '' );
46+
console.log( 'Changed:' );
47+
console.log( ` ${ this.changed.join( ', ' ) }` );
48+
}
49+
50+
if ( this.unchanged.length > 0 ) {
51+
console.log( '' );
52+
console.log( 'Unchanged:' );
53+
console.log( ` ${ this.unchanged.join( ', ' ) }` );
54+
}
55+
56+
console.log( separator );
57+
console.log( '' );
58+
}
59+
}
60+
61+
module.exports = ImpactSummaryReporter;

0 commit comments

Comments
 (0)