Repository navigation
tests: e2e playwright - #439
Merged
Merged
Conversation
`just check::e2e` runs browser tests against whatever serves :8081, so `just start` locally and the seeded stack in CI. Each user logs in once through the real Keycloak form and the session is reused. The tests only read, against the seeded hackathons, so they hold on a fresh database and on a local one that has been clicked through. The browsers come from nixpkgs through a new `test-e2e` toolchain, the same build on a Mac and in CI. Playwright refuses browsers built for another version, so `@playwright/test` is pinned to exactly the nixpkgs version, and the recipe says so plainly when the two drift apart.
The Test job already starts the whole stack and seeds it, so the browser tests run right after, on every pull request. When they fail, the HTML report and the traces are uploaded for a week, without the saved logins. `deploy::up` returns once the backend is ready, which can be before the frontend answers, so `check::e2e` now waits up to two minutes for :8081 instead of giving up at once.
`check::e2e` only knew "nothing answered on :8081", so a frontend that was up but answered every page with a 500, because its backend was gone, was reported as a stack that was not started. It now tells the two apart, and for an error points at the backend and the frontend log. It also says that it is waiting, so the two minutes do not look like a hang. It deletes the previous report before it starts. A run that stopped before Playwright left the old report in place, where it read as a pass.
A failed test only reported the error and the line, never what the page looked like: traces were kept on a retry, and nothing is retried locally. Each failure now keeps a screenshot and a trace, in CI as locally. Passing tests keep neither. `just check::e2e-report` opens the report of the last run, and `check::e2e` names it when a test fails, or the report artifact in CI.
The frontend reads data/test/config/secrets.yaml, which is git-ignored, so a fresh checkout has none. Every developer copies it from the example once, as the frontend README says, but nothing did so in CI. Nothing there loaded a page until the browser tests, which found every page answering 500. CI now copies the example before it starts the stack. Its values do for a throwaway stack, and the copy also proves the example stays a working config. A failed run now also uploads the stack's logs with the report, so a stack that broke before the tests could start says why.
They test the whole stack, so their place under components/frontend reads like a mistake. The config now states the rule: a system test lives in the component whose interface it drives, so a page and its test change together.
The seed writes casbin rows straight into the database, but the backend loads its permission rules once, at startup. CI seeded a running backend and never restarted it, so it served the seeded data without the seeded roles. alice was not an organizer there, and the browser test that expects her to be offered `Create Hackathon` failed. CI now restarts the stack after seeding, as "Restart the backend after seeding" in cmd/seed/README.md prescribes. The data is kept.
The image build fetches the frontend's npm packages up front, pinned to vendorHash, and then installs offline. Adding @playwright/test changed the lockfile but not the hash, so the pinned fetch lacked it and the frontend image failed with ERR_PNPM_NO_OFFLINE_TARBALL. The test job did not notice: it installs with network access. Set by `just nix::fix`. The hash does not depend on the platform it is computed on: on a Mac, main's unchanged lockfile gives exactly the hash CI has built with since August.
The config said CI runs the tests after `deploy::up` and `db::seed`. Since CI also restarts the stack after seeding, so the backend sees the seed's roles, that description fell short of what a reader needs to reproduce a CI failure locally.
The frontend image installs its npm packages offline from a download pinned by `vendorHash`. A changed lockfile without a new hash passes every check and then fails the image build with ERR_PNPM_NO_OFFLINE_TARBALL, as adding @playwright/test did. The README now says what to run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every pull request is now tested in a real browser
Before, CI started the whole app and filled it with test data, but nothing ever opened it in a browser. A broken login or a page showing the wrong things to the wrong person could merge unnoticed. Now every pull request logs in through the real login page as an organizer and as a participant, and checks what each of them sees.
just check::e2eruns the same tests against the app started withjust start.just check::e2e-reportthen shows each failure with a screenshot and a step-by-step trace.Seed. On a failure, the report and the app's logs can be downloaded from the run for a week.@playwright/testmust match the Nix version exactly, andcheck::e2esays so when it doesn't.Left out: only five smoke tests so far, Chromium only, and the frontend runs in dev mode. The backend still needs a restart after every seed, locally too. Making it reload permissions by itself is a separate change.
Verified: locally on macOS, all tests pass after a restart done the way CI does it, and a broken test fails with a screenshot and a trace. Frontend lint and formatting pass. The CI fixes are confirmed only once this PR's run is green.