Skip to main content

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’s vitest.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 in apps/web/e2e/ with config in apps/web/playwright.config.ts.

Test Projects

Playwright is configured with three projects:

Running E2E Tests

Environment Variables

E2E tests require real Supabase credentials: These are defined in 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. The PLAYWRIGHT_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.
When adding a new UI component, include a story file covering its variants and states. Storybook auto-deploys to Netlify on pushes to main when component or config files change.