Overview
folksbase uses two testing layers:- Vitest for unit tests — fast, focused tests for business logic
- Playwright for E2E tests — browser-based tests against the full running app
Unit Tests (Vitest)
Where Tests Live
Tests go in__tests__/ directories next to the file being tested:
Running Tests
Writing Tests
Mock all external dependencies. Tests should be fast and isolated — no real database, Redis, or API calls.What to Test
- Business logic in services (happy path + error cases)
- Repository query behavior (mocked DB responses)
- Edge cases: empty inputs, missing data, concurrent operations
- Error handling: verify errors propagate correctly
What NOT to Test
- Drizzle query builder syntax — trust the ORM
- Zod schema validation — trust Zod
- Framework internals — trust Next.js and Hono
Test Configuration
Vitest config lives in each app’svitest.config.ts. The API config sets up path aliases so imports like @/lib/logger.js and @folksbase/db resolve correctly in tests:
Important: Use Valid UUIDs in Tests
Route param validators enforce UUID format. Always use valid UUIDs in test fixtures, not arbitrary strings:E2E Tests (Playwright)
Where Tests Live
E2E tests live inapps/web/e2e/ with config in apps/web/playwright.config.ts.
Test Projects
Playwright is configured with three projects:| Project | Purpose |
|---|---|
setup | Authenticates once, stores session in e2e/.auth/user.json |
no-auth | Runs auth.spec.ts with empty storage (tests login flow) |
chromium | Runs all other specs with stored auth (depends on setup) |
Running E2E Tests
Environment Variables
E2E tests require real Supabase credentials:| Variable | Purpose |
|---|---|
E2E_USER_EMAIL | Test user email for authentication |
E2E_USER_PASSWORD | Test user password |
PLAYWRIGHT_BASE_URL | App URL (defaults to http://localhost:3000) |
apps/web/.env.example and read via process.env in the Playwright config.
Test Files
The E2E suite covers:auth, dashboard, navigation, contacts, imports, exports, tags, settings, and accessibility.
CI Integration
In CI, E2E tests run against the Vercel preview URL generated for each PR. ThePLAYWRIGHT_BASE_URL is overridden to point to the preview deployment.
Storybook
UI components are documented with Storybook 8. Stories live alongside their components as*.stories.tsx files.
main when component or config files change.