Add visual snapshot tests

We use the cache Github action to store snapshots when pushing to master and
then load them in pull requests and run the visual tests against it.

This way we don't have to commit the images to the repository and always
get diffs to the latest master.

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2022-12-16 15:06:05 +01:00
parent d5f690926e
commit 2c022a40df
7 changed files with 121 additions and 46 deletions
+53 -44
View File
@@ -2,57 +2,66 @@ name: check-e2e
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master
jobs:
check-e2e:
continue-on-error: true
strategy:
matrix:
browser: [chromium, firefox]
browser: [chromium, firefox, visual]
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.12.1'
- name: Install dependencies
run: npm ci
- name: Get npm cache directory
id: npm-cache-dir
run: |
echo "::set-output name=dir::$(npm config get cache)"
- name: Get Playwright version
id: playwright-version
run: |
echo "::set-output name=version::$(node -p "require('@playwright/test/package.json').version")"
- uses: actions/cache@v3
name: Check if Playwright browser is cached
id: playwright-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
- name: Install Playwright browser if not cached
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
env:
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
- name: Install OS dependencies of Playwright if cache hit
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps
- name: Start http-api test server
run: ./scripts/run-http-api-with-fixtures --non-interactive --detach
- name: Run Playwright tests
run: npm run test:e2e -- --project ${{ matrix.browser }}
env:
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-artifacts-${{ runner.os }}
retention-days: 30
path: |
tests/artifacts/**/*
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18.12.1"
- name: Install dependencies
run: npm ci
- name: Cache Playwright browsers
uses: actions/cache@v3
id: playwright-dep-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('package-lock.json') }}
- name: Cache snapshots (generate on master, load on pull_request)
uses: actions/cache@v3
id: playwright-snapshot-cache
with:
path: tests/visual/snapshots/**/*
key: ${{ runner.os }}-snapshots
- name: Install Playwright with deps unless cached
if: steps.playwright-dep-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
- name: Install only Playwright OS dependencies if cache hit
if: steps.playwright-dep-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps
- name: Start http-api test server
run: ./scripts/run-http-api-with-fixtures --non-interactive --detach
- name: Run Playwright tests
run: |
if [ ${{ matrix.browser }} = "visual" ] && [ ${{ github.ref }} = "refs/heads/master" ]; then
npm run test:e2e -- --project ${{ matrix.browser }} --update-snapshots;
else
npm run test:e2e -- --project ${{ matrix.browser }};
fi
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-artifacts-${{ runner.os }}
retention-days: 30
path: |
tests/artifacts/**/*