Testing a Nuxt App with Vitest and Playwright
The starter kit has three kinds of tests. The core flows run against a real production server and a real PostgreSQL database. Only external services (Polar and the email API) are mocked.
| Kind | File name | Runner | What it covers |
|---|---|---|---|
| Unit | *.test.ts | Vitest | Pure functions, e.g. admin access rules, upload validation and i18n key parity |
| API | *.api.ts | Playwright, no browser | HTTP endpoints: auth flows, permissions, CRUD, emails |
| e2e | *.e2e.ts | Playwright, Chromium | Critical user flows in the browser, including a passkey sign-in and a cross-tab sign-out |
Every layer keeps its tests in its own test/ folder, so deleting a feature also deletes its tests. Shared fixtures and helpers are in apps/web/test/.
Running the Tests
pnpm test:unit # Vitest, no server or database needed
pnpm test:api # Playwright API tests only
pnpm test:e2e # Playwright API and browser tests
pnpm test:e2e:ui # Playwright UI mode
pnpm test # Unit tests, then API and e2e tests
Run a single file or test:
pnpm --filter web exec playwright test layers/waitlist/test/waitlist.api.ts
pnpm --filter web exec playwright test --grep "password reset"
PostgreSQL
API and e2e tests need PostgreSQL. Start one locally with Docker:
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:17
The global setup creates the test database from apps/web/.env.test if needed and applies the migrations.
Production Build
Playwright tests a production build on port 9009 with the values from apps/web/.env.test. Locally it runs pnpm build first. With CI=true it reuses the existing .output.
Writing Tests
- Mocked services:
apps/web/test/mock-services.mjsreplaces Polar and the Plunk email API. Read sent emails withwaitForEmail()fromapps/web/test/support/mail.ts. - Fixtures from
apps/web/test/fixtures.ts:api: an anonymous API clientcreateUser({ role }): a verified, signed-in user with its ownapiclientloginAs(user): puts the session into the browser
- Parallel runs: tests run in parallel against one database. Use
uniqueEmail()for new data. - Rate limits: better-auth rate-limits per client IP. The fixtures give every client its own
x-forwarded-forIP, so send requests through them. - Unit tests: keep logic that needs a unit test free of Nuxt auto-imports, e.g. in
server/lib/.
Continuous Integration (CI)
GitHub Actions runs on pushes to main and on pull requests against main (.github/workflows/ci.yml):
- lint, typecheck, unit tests and build
- API and e2e tests against a PostgreSQL service
- a
feature-removalmatrix that deletes each optional layer once and runs typecheck, unit tests and the build without it
docker-image.yml builds and smoke-tests the Docker image.
Overview
Security headers and CSP with Nuxt Security, its default rate limiter and what to check behind a proxy, protected admin APIs and file upload validation.
Help
Get help with Nuxt Starter Kit: ask the AI chat, join the private Discord for customers, use GitHub Discussions and Issues, or email me directly.