Skip to content

Commit d7ba775

Browse files
authored
infra: Add screenshot testing on PRs (#14)
* infra: Add screenshot testing on PRs Uses Vitest, Browser Test Tools and jest-image-snapshot to create snapshots of dev pages and comparing results with previous captured results from main branch. * infra: Label workflow results * chore: Remove unused file + set base wdio url
1 parent 4387ca6 commit d7ba775

15 files changed

+2286
-164
lines changed

.eslintrc

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,52 @@
1515
"jsx": true
1616
}
1717
},
18-
"plugins": ["unicorn", "react-hooks", "no-unsanitized", "header"],
18+
"plugins": [
19+
"unicorn",
20+
"react-hooks",
21+
"no-unsanitized",
22+
"header"
23+
],
1924
"rules": {
2025
"@typescript-eslint/no-unused-vars": "error",
21-
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
26+
"@typescript-eslint/consistent-type-definitions": [
27+
"error",
28+
"interface"
29+
],
2230
"react/react-in-jsx-scope": "off",
2331
"react/no-danger": "error",
24-
"react/no-unstable-nested-components": ["error", { "allowAsProps": true }],
25-
"react/forbid-component-props": ["warn", { "forbid": ["className", "id"] }],
26-
"react/jsx-boolean-value": ["error", "always"],
32+
"react/no-unstable-nested-components": [
33+
"error",
34+
{
35+
"allowAsProps": true
36+
}
37+
],
38+
"react/forbid-component-props": [
39+
"warn",
40+
{
41+
"forbid": [
42+
"className",
43+
"id"
44+
]
45+
}
46+
],
47+
"react/jsx-boolean-value": [
48+
"error",
49+
"always"
50+
],
2751
"@typescript-eslint/naming-convention": [
2852
"error",
2953
{
3054
"selector": "typeLike",
31-
"format": ["PascalCase"]
55+
"format": [
56+
"PascalCase"
57+
]
3258
}
3359
],
3460
"react-hooks/rules-of-hooks": "error",
35-
"react-hooks/exhaustive-deps": ["error"],
61+
"react-hooks/exhaustive-deps": [
62+
"error"
63+
],
3664
"unicorn/filename-case": "error",
3765
"curly": "error",
3866
"dot-notation": "error",
@@ -42,7 +70,10 @@
4270
"header/header": [
4371
"error",
4472
"line",
45-
[" Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.", " SPDX-License-Identifier: Apache-2.0"]
73+
[
74+
" Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.",
75+
" SPDX-License-Identifier: Apache-2.0"
76+
]
4677
]
4778
},
4879
"settings": {
@@ -56,7 +87,10 @@
5687
},
5788
"overrides": [
5889
{
59-
"files": ["**/__integ__/**"],
90+
"files": [
91+
"**/__integ__/**",
92+
"./test/**"
93+
],
6094
"rules": {
6195
// useBrowser is not a React hook
6296
"react-hooks/rules-of-hooks": "off",
@@ -65,6 +99,15 @@
6599
"env": {
66100
"jest": true
67101
}
102+
},
103+
{
104+
"files": [
105+
"./pages/**"
106+
],
107+
"rules": {
108+
"react/react-in-jsx-scope": 2,
109+
"react/jsx-uses-react": 2
110+
}
68111
}
69112
]
70-
}
113+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Visual Regressions
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
env:
12+
VISUAL_REGRESSION_SNAPSHOT_DIRECTORY: '__image_snapshots__'
13+
14+
jobs:
15+
test:
16+
name: Run Tests
17+
runs-on: ubuntu-latest
18+
if: github.event.ref != 'refs/head/main'
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-node@v3
22+
with:
23+
node-version: 14
24+
cache: 'npm'
25+
- name: "Download artifacts"
26+
# Turns out you can not use artifacts from a previous workflow run.
27+
# I'm reluctant to check in the resulting screenshots into the repository,
28+
# which is why we use the following hack, until it's solved on Github side:
29+
# https://github.com/actions/download-artifact/issues/3
30+
run: |
31+
RUN_ID=`gh run --repo $GITHUB_REPOSITORY --branch main list --workflow "Visual Regressions" --json databaseId --jq .[0].databaseId`
32+
echo "Downloading snapshots created in run ${RUN_ID}"
33+
gh run --repo $GITHUB_REPOSITORY download ${RUN_ID} -n "visual-regression-snapshots" -D ${{ env.VISUAL_REGRESSION_SNAPSHOT_DIRECTORY }}
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
- run: npm install
37+
- run: npm run build
38+
- run: npm run test:e2e
39+
- uses: actions/upload-artifact@v3
40+
with:
41+
name: visual-regression-snapshots-results
42+
path: ${{ env.VISUAL_REGRESSION_SNAPSHOT_DIRECTORY }}
43+
update:
44+
name: Update Snapshots
45+
runs-on: ubuntu-latest
46+
if: github.event.ref == 'refs/head/main'
47+
steps:
48+
- uses: actions/checkout@v3
49+
- uses: actions/setup-node@v3
50+
with:
51+
node-version: 14
52+
cache: 'npm'
53+
- run: npm install
54+
- run: npm run build
55+
- run: npm run test:e2e:update
56+
- uses: actions/upload-artifact@v3
57+
with:
58+
name: visual-regression-snapshots
59+
path: ${{ env.VISUAL_REGRESSION_SNAPSHOT_DIRECTORY }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
coverage
33
lib
4+
/__image_snapshots__
5+
/pages/dist

0 commit comments

Comments
 (0)