Skip to content

Commit

Permalink
chore: generate snapshots in CI (#190)
Browse files Browse the repository at this point in the history
Closes #189

- Integration tests now run on `ubuntu-latest`.
- We run Playwright with the `--update-snapshots` flag.
- If the UI is updated it will automatically generate the new snapshot
and if the tests passed a Github bot will commit those new snapshots to
the PR, that way we can review UI changes together with the code.
- Also added a new
[`--reporter=list`](https://playwright.dev/docs/test-reporters#list-reporter)
flag so we can see the status of each test as they run in the CI logs.
- Updated `package.json` so when we run `npm test` locally we use the
`--ignore-snapshots` flag, otherwise our local tests will always fail
due to the differences between macOS and Linux renderers.

This workflow may have have some unexpected behaviors but I'm willing to
give it a shot and see how it plays out. One, potentially annoying,
thing is that after you commit your changes to the branch, you will then
have to pull the new snapshots once the tests are finished.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
fmaclen and github-actions[bot] authored Sep 23, 2024
1 parent 1e567bd commit 783e407
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: ESLint

on:
pull_request:
Expand Down
29 changes: 26 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
name: Test
name: Playwright

on:
pull_request:

jobs:
integration-tests:
name: Integration tests
runs-on: macos-latest
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
# REF https://github.com/ad-m/github-push-action?tab=readme-ov-file#example-workflow-file
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.

- uses: actions/setup-node@v4
with:
node-version: '20'
Expand All @@ -20,7 +30,7 @@ jobs:
run: npx playwright install --with-deps chromium

- name: Run Playwright tests
run: npm test
run: npx playwright test --update-snapshots --reporter=list
env:
CI: true

Expand All @@ -29,3 +39,16 @@ jobs:
with:
name: test-results
path: test-results/

- name: Commit updated snapshots
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -m "Update snapshots" || echo "No new snapshots to commit"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev": "concurrently \"typesafe-i18n\" \"vite dev --host\"",
"build": "vite build",
"preview": "vite preview",
"test": "playwright test --trace on",
"test": "playwright test --trace on --ignore-snapshots ",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
Expand Down
Binary file modified tests/docs.test.ts-snapshots/knowledge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/docs.test.ts-snapshots/motd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/docs.test.ts-snapshots/session-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/docs.test.ts-snapshots/session.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/docs.test.ts-snapshots/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 783e407

Please sign in to comment.