HenniOKF
Documentation

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

CommandWhatWhen
npm run checkPrettier, ESLint, types (next typegen && tsc --noEmit), Vitest, in this order; stops at the first errorbefore every commit; on GitHub in the workflow "Check"
npm run test:e2ebrowser tests with Playwright and axe against a production buildafter 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.

FileWhat it checks
access.test.tswhich paths are open, what the matcher leaves out, which request counts as a page, and the proxy itself with and without configuration
users.test.tsthe 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.tsroot directory without a default path, ensureDirs, token, address, sign-in limit, secret, the prefix of all variables
version.test.tsVERSION equal to package.json, commit and build time from the environment, the same names in the Dockerfile
security-headers.test.tsheaders, order of the rules, standalone without sharp
i18n.test.tsthe dictionaries: same keys, no empty text, same placeholders; the helpers; the default language
docs.test.tsthe rules of the bundle docs/, see Writing documentation
docs-pages.test.tsaddresses, 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.tsnpm 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:

WhatHow
servernpm run build, then next start on port 3371. A running development server does not disturb
root directory.data-e2e, fresh on every run
environmenta token only for the tests, sign-in limit 100000, main address http://localhost:3371
projectssetup, then desktop (Desktop Chrome) and mobile (Pixel 5), both signed in as reviewer unless a test says otherwise
retrieson 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.

FileWhat it checks
access.spec.tspublic reading as guest, redirect and way back, 401 without a page, open paths, headers, pages with an API key
users.spec.tssign 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.tsconfiguration and version without the token, the way through footer and tile, not for reviewer, editor and LLM
docs.spec.tsmenu item, way through the areas, tables and code blocks, table of contents, 404
i18n.spec.tsEnglish by default, German through the switch and back, without JavaScript, axe in German, messages of server actions in German
shell.spec.tsheader 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

WorkflowWhat
"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_PAGES or ADMIN_PAGES in e2e/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. desktop and mobile run in parallel against the same instance.
  • On mobile the table of contents of /docs is behind a button; a test that reads it clicks the button first.

Next: Pitfalls.