Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add visual regression testing #132

Merged
merged 6 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text eol=lf
* text eol=lf
*.png binary
43 changes: 43 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,46 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build

visual-regression-tests:
name: visual-regression-tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node JS 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install jq
run: |
sudo apt-get -qq update
sudo apt-get install -y jq

- name: Build Docker Image
run: docker build . -t squint-local

- name: Start Squint Container
run: docker run -d -p 3001:3001 --name local-squint-container squint-local

- name: Install testing packages
run: |
cd visual_regression_testing
npm ci

- name: Run Visual Regression Tests
run: |
cd visual_regression_testing
./compare.sh

- name: Archive diffs
if: always()
uses: actions/upload-artifact@v3
with:
name: diffs
path: visual_regression_testing/diffs

- name: Stop Squint Container
run: docker stop local-squint-container
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/target
ra-*.log
rls*.log
visual_regression_testing/diffs
visual_regression_testing/node_modules
visual_regression_testing/test_images
33 changes: 33 additions & 0 deletions visual_regression_testing/compare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -euo pipefail

rm -rf test_images
mkdir -p test_images

rm -rf diffs
mkdir -p diffs

readarray -t test_cases < <(jq -c '.[]' test_cases.json)

# from this point on, continue even if something fails
# we want to continue testing further reference_images, even if one fails
set +e

exitcode=0
for test_case in "${test_cases[@]}"; do
url=$(jq -r '.url' <<< "$test_case")
filename=$(jq -r '.filename' <<< "$test_case")
echo "Testing: $filename";
curl "$url" --silent -o "test_images/$filename"
if ./node_modules/.bin/pixelmatch "test_images/$filename" "reference_images/$filename" "diffs/$filename"; then
# if the images were exactly the same, discard the diff
rm "diffs/$filename"
else
# one or more images has failed
exitcode=1
fi
echo ""
done

exit $exitcode
46 changes: 46 additions & 0 deletions visual_regression_testing/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions visual_regression_testing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"pixelmatch": "^5.3.0"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions visual_regression_testing/test_cases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"url": "http://localhost:3001/badge/build-passing-brightgreen.png",
"filename": "build-passing-brightgreen.png"
},
{
"url": "http://localhost:3001/badge/emoji-%E2%9D%A4%EF%B8%8F-blue.png",
"filename": "emoji-❤️-blue.png"
},
{
"url": "http://localhost:3001/badge/emoji-%F0%9F%87%B3%F0%9F%87%B4-blue.png",
"filename": "emoji-🇳🇴-blue.png"
},
{
"url": "http://localhost:3001/badge/emoji-%F0%9F%91%8D-blue.png",
"filename": "emoji-👍-blue.png"
},
{
"url": "http://localhost:3001/badge/emoji-%F0%9F%99%82-blue.png",
"filename": "emoji-🙂-blue.png"
},
{
"url": "http://localhost:3001/badge/%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%A1%E3%83%83%E3%82%BB%E3%83%BC%E3%82%B8-lightgrey.png",
"filename": "ラベル-メッセージ-lightgrey.png"
},
{
"url": "http://localhost:3001/badge/foo-barfffffffffffffffffffffffffffffffffffffjfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-orange.png?style=for-the-badge",
"filename": "FTB-foo-barfffffffffffffffffffffffffffffffffffffjfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-orange.png"
}
]