diff --git a/.gitattributes b/.gitattributes index 07764a7..d0c0c4c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -* text eol=lf \ No newline at end of file +* text eol=lf +*.png binary diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 1e1201e..1165ccf 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 diff --git a/.gitignore b/.gitignore index a9758f9..04a0b4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /target ra-*.log rls*.log +visual_regression_testing/diffs +visual_regression_testing/node_modules +visual_regression_testing/test_images diff --git a/visual_regression_testing/compare.sh b/visual_regression_testing/compare.sh new file mode 100755 index 0000000..03d1259 --- /dev/null +++ b/visual_regression_testing/compare.sh @@ -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 diff --git a/visual_regression_testing/package-lock.json b/visual_regression_testing/package-lock.json new file mode 100644 index 0000000..19cbc71 --- /dev/null +++ b/visual_regression_testing/package-lock.json @@ -0,0 +1,46 @@ +{ + "name": "pixelmatch", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "pixelmatch": "^5.3.0" + } + }, + "node_modules/pixelmatch": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/pixelmatch/-/pixelmatch-5.3.0.tgz", + "integrity": "sha512-o8mkY4E/+LNUf6LzX96ht6k6CEDi65k9G2rjMtBe9Oo+VPKSvl+0GKHuH/AlG+GA5LPG/i5hrekkxUc3s2HU+Q==", + "dependencies": { + "pngjs": "^6.0.0" + }, + "bin": { + "pixelmatch": "bin/pixelmatch" + } + }, + "node_modules/pngjs": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-6.0.0.tgz", + "integrity": "sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg==", + "engines": { + "node": ">=12.13.0" + } + } + }, + "dependencies": { + "pixelmatch": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/pixelmatch/-/pixelmatch-5.3.0.tgz", + "integrity": "sha512-o8mkY4E/+LNUf6LzX96ht6k6CEDi65k9G2rjMtBe9Oo+VPKSvl+0GKHuH/AlG+GA5LPG/i5hrekkxUc3s2HU+Q==", + "requires": { + "pngjs": "^6.0.0" + } + }, + "pngjs": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-6.0.0.tgz", + "integrity": "sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg==" + } + } +} diff --git a/visual_regression_testing/package.json b/visual_regression_testing/package.json new file mode 100644 index 0000000..d40d4b3 --- /dev/null +++ b/visual_regression_testing/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "pixelmatch": "^5.3.0" + } +} diff --git a/visual_regression_testing/reference_images/FTB-foo-barfffffffffffffffffffffffffffffffffffffjfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-orange.png b/visual_regression_testing/reference_images/FTB-foo-barfffffffffffffffffffffffffffffffffffffjfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-orange.png new file mode 100644 index 0000000..f10d9ac Binary files /dev/null and b/visual_regression_testing/reference_images/FTB-foo-barfffffffffffffffffffffffffffffffffffffjfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-orange.png differ diff --git a/visual_regression_testing/reference_images/build-passing-brightgreen.png b/visual_regression_testing/reference_images/build-passing-brightgreen.png new file mode 100644 index 0000000..7356a38 Binary files /dev/null and b/visual_regression_testing/reference_images/build-passing-brightgreen.png differ diff --git "a/visual_regression_testing/reference_images/emoji-\342\235\244\357\270\217-blue.png" "b/visual_regression_testing/reference_images/emoji-\342\235\244\357\270\217-blue.png" new file mode 100644 index 0000000..a69537f Binary files /dev/null and "b/visual_regression_testing/reference_images/emoji-\342\235\244\357\270\217-blue.png" differ diff --git "a/visual_regression_testing/reference_images/emoji-\360\237\207\263\360\237\207\264-blue.png" "b/visual_regression_testing/reference_images/emoji-\360\237\207\263\360\237\207\264-blue.png" new file mode 100644 index 0000000..547f0d3 Binary files /dev/null and "b/visual_regression_testing/reference_images/emoji-\360\237\207\263\360\237\207\264-blue.png" differ diff --git "a/visual_regression_testing/reference_images/emoji-\360\237\221\215-blue.png" "b/visual_regression_testing/reference_images/emoji-\360\237\221\215-blue.png" new file mode 100644 index 0000000..11f3bd3 Binary files /dev/null and "b/visual_regression_testing/reference_images/emoji-\360\237\221\215-blue.png" differ diff --git "a/visual_regression_testing/reference_images/emoji-\360\237\231\202-blue.png" "b/visual_regression_testing/reference_images/emoji-\360\237\231\202-blue.png" new file mode 100644 index 0000000..e7b0fc7 Binary files /dev/null and "b/visual_regression_testing/reference_images/emoji-\360\237\231\202-blue.png" differ diff --git "a/visual_regression_testing/reference_images/\343\203\251\343\203\231\343\203\253-\343\203\241\343\203\203\343\202\273\343\203\274\343\202\270-lightgrey.png" "b/visual_regression_testing/reference_images/\343\203\251\343\203\231\343\203\253-\343\203\241\343\203\203\343\202\273\343\203\274\343\202\270-lightgrey.png" new file mode 100644 index 0000000..91648e5 Binary files /dev/null and "b/visual_regression_testing/reference_images/\343\203\251\343\203\231\343\203\253-\343\203\241\343\203\203\343\202\273\343\203\274\343\202\270-lightgrey.png" differ diff --git a/visual_regression_testing/test_cases.json b/visual_regression_testing/test_cases.json new file mode 100644 index 0000000..eecd24c --- /dev/null +++ b/visual_regression_testing/test_cases.json @@ -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" + } +]