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.
Unit tests
Section titled “Unit tests”Fast (~10 s). Covers library functions, security logic, and component behaviour in isolation.
npm testUnit tests do not start a dev server, do not make HTTP requests, and do not depend on a browser.
E2E tests
Section titled “E2E tests”Playwright-based. Spins up an isolated test dev server on port 3001
backed by data/test.db, then drives a real Chromium browser.
First-time setup
Section titled “First-time setup”npx playwright install chromiumcp .env.test.example .env.testDefaults work out of the box.
npm run test:e2e # full suitenpm run test:e2e -- posts # only posts.spec.tsnpm run test:e2e:quick -- posts # reuse existing server (after a full run)global-setup.ts runs automatically and:
- Cleans
data/test.db - Generates a random admin secret path (written to
.test-output/test-config.json) - Starts the test dev server on port 3001 with
DATABASE_URL=file:data/test.db - Creates a test admin account and saves the authenticated state
Your real .env.local and data/app.db are never modified.
Admin pages smoke test
Section titled “Admin pages smoke test”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.
npm run test:e2e -- admin-pages-smokeStatus 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 devcache clear, to verify routes still resolve.
If a fork adds, removes, or renames an admin page, update
ADMIN_PAGES in the spec to match.
Common pitfalls
Section titled “Common pitfalls”Port 3001 already in use
Section titled “Port 3001 already in use”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 usedStop the conflicting process, or change the test port via
TEST_BASE_URL and the corresponding Playwright webServer.port.
Quick mode prerequisites
Section titled “Quick mode prerequisites”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 must not modify production code
Section titled “Tests must not modify production code”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.