Skip to content

Commit 928a324

Browse files
committed
Add single-command visual regression workflow
Add compare-branches.sh that automates the baseline generation and comparison workflow into a single npm run test:visual command. The script checks out trunk (or a specified base branch), generates baseline snapshots, switches back to the feature branch, and runs the comparison.
1 parent 43bf5a9 commit 928a324

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"test:php": "node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit",
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",
132-
"test:visual": "wp-scripts test-playwright --config tests/visual-regression/playwright.config.js",
132+
"test:visual": "bash tests/visual-regression/compare-branches.sh",
133133
"gutenberg:checkout": "node tools/gutenberg/checkout-gutenberg.js",
134134
"gutenberg:build": "node tools/gutenberg/build-gutenberg.js",
135135
"gutenberg:copy": "node tools/gutenberg/copy-gutenberg-build.js",

tests/visual-regression/README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,32 @@ These tests make use of Playwright, with a setup very similar to that of the e2e
44

55
## How to Run the Tests Locally
66

7-
1. Check out trunk.
8-
2. Run `npm run test:visual` to generate some base snapshots.
9-
3. Check out the feature branch to be tested.
10-
4. Run `npm run test:visual` again. If any tests fail, the diff images can be found in `artifacts/`
7+
From a feature branch with a clean working tree, run:
8+
9+
```bash
10+
npm run test:visual
11+
```
12+
13+
This will automatically:
14+
1. Check out trunk to generate baseline snapshots.
15+
2. Return to your feature branch.
16+
3. Compare the current branch against those baselines.
17+
18+
If any tests fail, diff images can be found in `artifacts/`.
19+
20+
### Specifying a Base Branch
1121

22+
By default, baselines are generated from `trunk`. To compare against a different branch:
23+
24+
```bash
25+
npm run test:visual -- some-other-branch
26+
```
27+
28+
### Manual 2-Step Workflow
29+
30+
You can also generate baselines and compare manually:
31+
32+
1. Check out the base branch (e.g. trunk).
33+
2. Run `npx playwright test --config tests/visual-regression/playwright.config.js --update-snapshots`
34+
3. Check out the feature branch to be tested.
35+
4. Run `npx playwright test --config tests/visual-regression/playwright.config.js`
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -e
3+
4+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
5+
BASELINE_BRANCH="${1:-trunk}"
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
CONFIG="$SCRIPT_DIR/playwright.config.js"
8+
9+
if [ "$CURRENT_BRANCH" = "$BASELINE_BRANCH" ]; then
10+
echo "Error: Already on $BASELINE_BRANCH. Checkout a feature branch first."
11+
exit 1
12+
fi
13+
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
18+
19+
echo "Generating baselines from $BASELINE_BRANCH..."
20+
git checkout "$BASELINE_BRANCH"
21+
npx playwright test --config "$CONFIG" --update-snapshots
22+
23+
echo "Comparing against $CURRENT_BRANCH..."
24+
git checkout "$CURRENT_BRANCH"
25+
npx playwright test --config "$CONFIG"

0 commit comments

Comments
 (0)