Reference
Tests
Vitest and Playwright: what each test file covers, how the browser tests are set up and what a new test needs.
Two kinds of checks
| Command | What | When |
|---|---|---|
npm run check | Prettier, ESLint, types (next typegen && tsc --noEmit), Vitest, in this order; stops at the first error | before every commit; on GitHub in the workflow "Check" |
npm run test:e2e | browser tests with Playwright and axe against a production build | after larger changes; on GitHub in the workflow "Browser tests" |
The browser tests are not part of check; they take longer. "Check" runs
npx next build after check. The build checks tests/ and e2e/ with
TypeScript too.
The tests need no other repository and no foreign data. They run after a fresh clone.
Vitest
The files under tests/, run with vitest run. Routes and functions are
called directly; no server runs.
| File | What it checks |
|---|---|
access.test.ts | which paths are open, what the matcher leaves out, which request counts as a page, and the proxy itself with and without configuration |
users.test.ts | the permissions per role and for a guest, the first admin, the rules of accounts, hashes, the last admin, keys only for the LLM, who sends a request, secret and main address |
env.test.ts | root directory without a default path, ensureDirs, token, address, sign-in limit, secret, the prefix of all variables |
version.test.ts | VERSION equal to package.json, commit and build time from the environment, the same names in the Dockerfile |
security-headers.test.ts | headers, order of the rules, standalone without sharp |
i18n.test.ts | the dictionaries: same keys, no empty text, same placeholders; the helpers; the default language |
docs.test.ts | the rules of the bundle docs/, see Writing documentation |
docs-pages.test.ts | addresses, pages, links, images and table of contents of the docs, on a small bundle in a temp directory and on the real one |
rename.test.ts | npm run rename on a copy of the repository |
tests/helpers.ts brings what the tests share: tempDir() and cleanUp(),
setEnv() for the variables of the instance, signIn() for the headers of
a signed-in request, idOf() and PASSWORD.
A single test:
npx vitest run tests/users.test.ts -t "the last admin"
Vitest bypasses proxy.ts, because it calls routes directly. The proxy
is therefore tested itself in access.test.ts with a NextRequest. Under
NODE_ENV=test Better Auth switches its origin check off; only a browser
test checks it.
Playwright
How playwright.config.ts is set up:
| What | How |
|---|---|
| server | npm run build, then next start on port 3371. A running development server does not disturb |
| root directory | .data-e2e, fresh on every run |
| environment | a token only for the tests, sign-in limit 100000, main address http://localhost:3371 |
| projects | setup, then desktop (Desktop Chrome) and mobile (Pixel 5), both signed in as reviewer unless a test says otherwise |
| retries | on GitHub once, otherwise none |
e2e/accounts.setup.ts runs before all others: it creates the first admin
through the sign-in page, first with a wrong, then with the right token,
then in the user management one account per role (lena reviewer, edda
editor, agent7 LLM, next to the admin ada) and an API key. It remembers
the sessions under .data-e2e/state/. A test chooses them with AS_ADMIN,
AS_REVIEWER, AS_EDITOR, AS_LLM or GUEST from e2e/helpers.ts.
| File | What it checks |
|---|---|
access.spec.ts | public reading as guest, redirect and way back, 401 without a page, open paths, headers, pages with an API key |
users.spec.ts | sign in and out, way back only to own addresses, no self-registration, what reviewer and editor see, management, last admin, password, keys, passkey with a virtual authenticator, origin |
status.spec.ts | configuration and version without the token, the way through footer and tile, not for reviewer, editor and LLM |
docs.spec.ts | menu item, way through the areas, tables and code blocks, table of contents, 404 |
i18n.spec.ts | English by default, German through the switch and back, without JavaScript, axe in German, messages of server actions in German |
shell.spec.ts | header with name, menu and language switch, content, footer and axe per page, menu at every width, noindex and app icon |
axe checks after WCAG 2.1 AA, contrast included. A single test:
npx playwright test e2e/users.spec.ts --project=desktop -g "last admin"
A session of its own a test opens with browser.newContext(). The
context does not take the storageState of the project; it is empty.
In a cloud session of Claude Code Playwright 1.62.1 may not find its
Chromium revision. Point PLAYWRIGHT_BROWSERS_PATH to a directory with
links under the expected names (chromium-<revision>,
chromium_headless_shell-<revision>) to the installed browser. Check first
that port 3371 is free.
On GitHub
| Workflow | What |
|---|---|
| "Check" | npm ci, npm run check, npx next build, at every push to main and every pull request |
| "Browser tests" | npm ci, Chromium, npm run test:e2e -- --trace off, likewise. On failure the report lies ready as an artifact for 7 days |
A red browser test does not stop the image. The image waits only for "Check".
What a new test needs
- A new page comes into
GUEST_PAGES,REVIEWER_PAGESorADMIN_PAGESine2e/shell.spec.ts. Then axe checks it. - A new route gets a test that calls its function directly.
- A new permission gets its row in "permissions" in
tests/users.test.ts. - A new open path gets a case in both tests of access.
- A new text must not contain a word that a test excludes with
not.toContainText. - A test that changes data creates its own.
desktopandmobilerun in parallel against the same instance. - On mobile the table of contents of
/docsis behind a button; a test that reads it clicks the button first.
Next: Pitfalls.