Skip to content

Commit 1b0271c

Browse files
authored
add snapshot checking in CI (#1587)
* add snapshot checking in CI * linting * tests
1 parent c2dd617 commit 1b0271c

16 files changed

+159
-3
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Update Snapshots on a PR
2+
description: |
3+
Runs previously failed snapshot tests, and commits the changes.
4+
5+
Your PR will receive a commit with the changes so you can manually verify before merging.
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
pr_number:
11+
description: 'Pull Request Number (Warning: This action will push a commit to the referenced PR)'
12+
required: true
13+
type: number
14+
15+
permissions:
16+
pull-requests: write
17+
contents: write
18+
19+
jobs:
20+
update-pr-with-snapshots:
21+
name: Update PR With Snapshots
22+
runs-on: macos-14
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Checkout PR ${{ github.event.inputs.pr_number }}
26+
if: github.event_name == 'workflow_dispatch'
27+
run: gh pr checkout ${{ github.event.inputs.pr_number }}
28+
env:
29+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Use Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version-file: '.nvmrc'
35+
- uses: actions/cache@v4
36+
with:
37+
path: |
38+
~/.npm
39+
~/.cache/ms-playwright
40+
key: ${{ runner.os }}-node-playwright-${{ hashFiles('**/package-lock.json') }}
41+
restore-keys: |
42+
${{ runner.os }}-node-playwright-
43+
${{ runner.os }}-node-
44+
45+
- name: Install dependencies
46+
run: npm ci
47+
48+
- name: Build all
49+
run: npm run build
50+
51+
- name: Install Playwright Browsers
52+
run: npx playwright install --with-deps
53+
54+
- name: Run Screenshot tests
55+
id: screenshot_tests
56+
run: npm run test-int-snapshots
57+
58+
- if: ${{ steps.screenshot_tests.conclusion == 'success' }}
59+
run: |
60+
echo "nothing to update - tests all passed"
61+
62+
- name: Re-Running Playwright to update snapshots
63+
id: screenshot_tests_update
64+
if: ${{ failure() && steps.screenshot_tests.conclusion == 'failure' }}
65+
run: npm run test-int-snapshots-update
66+
67+
- name: Commit the updated files to the PR branch
68+
if: ${{ failure() && steps.screenshot_tests_update.conclusion == 'success' }}
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
run: |
72+
# Configure Git with a bot's username and email for committing changes
73+
# This makes it easy to identify in the PR
74+
git config user.name "github-actions[bot]"
75+
git config user.email "github-actions[bot]@users.noreply.github.com"
76+
77+
# Stage all updated PNG files for commit
78+
git add "*.png"
79+
80+
# Commit the changes with a descriptive message
81+
git commit -m "Updated snapshots via workflow"
82+
83+
# Push the changes to the current branch in the PR
84+
git push origin HEAD

.github/workflows/snapshots.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Test Snapshots
2+
description: |
3+
Runs snapshot tests and uploads test reports as artifacts
4+
5+
If this workflow fails, you can trigger `update-snapshots.yml` from the
6+
GitHub UI.
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
pull_request:
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
snapshots:
19+
timeout-minutes: 5
20+
runs-on: macos-14
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Use Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version-file: '.nvmrc'
27+
- uses: actions/cache@v4
28+
with:
29+
path: |
30+
~/.npm
31+
~/.cache/ms-playwright
32+
key: ${{ runner.os }}-node-playwright-${{ hashFiles('**/package-lock.json') }}
33+
restore-keys: |
34+
${{ runner.os }}-node-playwright-
35+
${{ runner.os }}-node-
36+
37+
- run: npm ci
38+
- run: npm run build
39+
40+
- run: npm run lint
41+
continue-on-error: true
42+
43+
- run: npm run stylelint
44+
continue-on-error: true
45+
46+
- run: npm run test-unit
47+
continue-on-error: true
48+
49+
- name: 'Clean tree'
50+
run: 'npm run test-clean-tree'
51+
52+
- name: Install Playwright Browsers
53+
run: npx playwright install --with-deps
54+
55+
- run: npm run test-int-snapshots
56+
57+
- uses: actions/upload-artifact@v4
58+
if: always()
59+
with:
60+
name: playwright-report-pages
61+
path: |
62+
special-pages/playwright-report
63+
special-pages/test-results
64+
injected/playwright-report
65+
injected/test-results
66+
retention-days: 5
-2.72 KB
Loading

injected/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
"build-types": "node scripts/types.mjs",
1212
"bundle-trackers": "node scripts/bundleTrackers.mjs --output ../build/tracker-lookup.json",
1313
"test-unit": "jasmine --config=unit-test/config.json",
14-
"test-int": "npm run playwright",
14+
"test-int": "playwright test --grep-invert '@screenshots'",
1515
"test-int-x": "xvfb-run --server-args='-screen 0 1024x768x24' npm run test-int",
16+
"test-int-snapshots": "playwright test --grep '@screenshots'",
17+
"test-int-snapshots-update": "playwright test --grep '@screenshots' --update-snapshots --last-failed",
1618
"test": "npm run lint && npm run test-unit && npm run test-int && npm run playwright",
1719
"serve": "http-server -c-1 --port 3220 integration-test/test-pages",
1820
"playwright": "playwright test --grep-invert '@screenshots'",

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"test-unit": "npm run test-unit --workspaces --if-present",
1515
"test-int": "npm run test-int --workspaces --if-present",
1616
"test-int-x": "npm run test-int-x --workspaces --if-present",
17+
"test-int-snapshots": "npm run test-int-snapshots --workspaces --if-present",
18+
"test-int-snapshots-update": "npm run test-int-snapshots-update --workspaces --if-present",
1719
"test-clean-tree": "npm run build && sh scripts/check-for-changes.sh",
1820
"docs": "typedoc",
1921
"docs-watch": "typedoc --watch",

special-pages/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
"build.dev": "npm run build -- --env development",
1212
"lint-fix": "cd ../ && npm run lint-fix",
1313
"test-unit": "node --test \"unit-test/*\" \"pages/history/unit-tests/*\" \"pages/duckplayer/unit-tests/*\" \"pages/new-tab/app/freemium-pir-banner/unit-tests/*\"",
14-
"test-int": "npm run test-unit && npm run build.dev && playwright test --grep-invert '@screenshots'",
14+
"test-int": "playwright test --grep-invert '@screenshots'",
1515
"test-int-x": "npm run test-int",
16-
"test.screenshots": "npm run test-unit && npm run build.dev && playwright test --grep '@screenshots'",
16+
"test-int-snapshots": "playwright test --grep '@screenshots'",
17+
"test-int-snapshots-update": "playwright test --grep '@screenshots' --update-snapshots --last-failed",
18+
"test.screenshots": "playwright test --grep '@screenshots'",
1719
"test.windows": "npm run test-int -- --project windows",
1820
"test.macos": "npm run test-int -- --project macos",
1921
"test.ios": "npm run test-int -- --project ios",
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)