Skip to content

Commit d8f4e46

Browse files
authored
tools: make visual baseline take a git revision arg (#2934)
1 parent 9d8156a commit d8f4e46

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

test/visual/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
### 1. Generate Baseline Snapshots
66

7-
First, generate baseline snapshots from a commit before your changes:
7+
First, generate baseline snapshots from some other revision:
88

99
```bash
10-
# Generate baseline from latest origin/main (most common)
11-
npm run visual:baseline -- --main
10+
# From main (most common)
11+
npm run visual:baseline
1212

1313
# Or from a specific commit hash
1414
npm run visual:baseline -- abc123
@@ -17,7 +17,13 @@ npm run visual:baseline -- abc123
1717
npm run visual:baseline -- HEAD~1
1818
```
1919

20-
This will check out that revision in a git work tree, run the visual snapshot tests, and copy the snapshots back into your current working directory.
20+
This will check out that revision in a git worktree in a temp dir, run the
21+
visual snapshot tests, and copy the snapshots back into your current working
22+
directory.
23+
24+
Note that this command does not fetch anything from the remote repo; it uses
25+
whatever you have locally. If you want to make sure you have the latest `main`,
26+
you need to pull it first.
2127

2228
### 2. Compare Current Changes
2329

tools/generate-visual-baseline.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ set -euo pipefail
1010
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
1111
cd "$PROJECT_ROOT"
1212

13-
echo "Fetching latest from origin..."
14-
git fetch origin main --quiet
13+
REV=${1:-main}
1514

16-
COMMIT=$(git rev-parse origin/main)
15+
COMMIT=$(git rev-parse "$REV")
1716
WORKTREE_DIR=$(mktemp -d -t visual-baseline-XXXXXX)
1817

1918
cleanup() {
@@ -22,7 +21,7 @@ cleanup() {
2221
}
2322
trap cleanup EXIT INT TERM
2423

25-
echo "Creating worktree at origin/main ($COMMIT)..."
24+
echo "Creating worktree at $REV ($COMMIT)..."
2625
git worktree add --detach "$WORKTREE_DIR" "$COMMIT" --quiet
2726

2827
echo "Copying test files..."
@@ -35,7 +34,7 @@ echo "Installing dependencies..."
3534
npm ci
3635

3736
echo "Generating baseline snapshots..."
38-
npx playwright test --config=playwright.visual.config.ts --project=chrome --update-snapshots
37+
npx playwright test --config=playwright.visual.config.ts --update-snapshots
3938

4039
echo "Copying snapshots back..."
4140
cp -r test/visual/regression.e2e.ts-snapshots "$PROJECT_ROOT/test/visual/"

0 commit comments

Comments
 (0)