Skip to content

Testing

Baan ships with two test suites: Vitest unit tests and Playwright E2E tests. Both run against an isolated test database — your local dev environment is never touched.

Fast (~10 s). Covers library functions, security logic, and component behaviour in isolation.

Terminal window
npm test

Unit tests do not start a dev server, do not make HTTP requests, and do not depend on a browser.

Playwright-based. Spins up an isolated test dev server on port 3001 backed by data/test.db, then drives a real Chromium browser.

Terminal window
npx playwright install chromium
cp .env.test.example .env.test

Defaults work out of the box.

Terminal window
npm run test:e2e # full suite
npm run test:e2e -- posts # only posts.spec.ts
npm run test:e2e:quick -- posts # reuse existing server (after a full run)

global-setup.ts runs automatically and:

  1. Cleans data/test.db
  2. Generates a random admin secret path (written to .test-output/test-config.json)
  3. Starts the test dev server on port 3001 with DATABASE_URL=file:data/test.db
  4. Creates a test admin account and saves the authenticated state

Your real .env.local and data/app.db are never modified.

tests/e2e/admin-pages-smoke.spec.ts loads every admin page (depth-1 and depth-2 under the authenticated layout) and asserts each returns HTTP 200. It catches whole-route-subtree regressions where a single upstream change silently breaks many pages at once — for example a turbopack manifest desync that drops every nested admin route.

Terminal window
npm run test:e2e -- admin-pages-smoke

Status code only. Per-page rendering details live in the focused *.spec.ts files (e.g. security-settings.spec.ts, bot-management.spec.ts).

When to run it:

  • Before merging any change that touches proxy.ts, the admin layout, routing, or framework upgrades.
  • After a next dev cache clear, to verify routes still resolve.

If a fork adds, removes, or renames an admin page, update ADMIN_PAGES in the spec to match.

If your local npm run dev is using port 3001, the E2E runner will refuse to start its own server:

Error: http://127.0.0.1:3001/api/health is already used

Stop the conflicting process, or change the test port via TEST_BASE_URL and the corresponding Playwright webServer.port.

npm run test:e2e:quick reuses the dev server and authenticated state from the previous full run. Run npm run test:e2e once first.

Tests that drive the real code path are preferred over refactoring production code to make it testable. If a behaviour is hard to reach from the outside, prefer integration coverage (real HTTP, real env vars) over splitting modules just to inject mocks.