Testing Guide
HostMetrics uses Vitest for unit and integration tests and Playwright for end-to-end browser tests.Test Stack
Directory Structure
Running Tests
Unit Tests
End-to-End Tests
Vitest Configuration
Key settings fromvitest.config.ts:
- Environment:
jsdom(simulates browser DOM) - Coverage thresholds: 80% for branches, functions, lines, and statements
- Path aliases:
@/maps tosrc/(mirrors the app’s tsconfig) - Setup files: Global test setup for mocks and environment
Test File Naming
Mock Patterns
Mocking the Supabase Client
The shared Supabase mock lives atsrc/__tests__/mocks/supabase.ts. Use it in unit tests:
Mocking Hooks in Component Tests
When testing components, mock the hooks they depend on:Mocking Next.js Router
Writing Unit Tests
Follow this structure for hook tests:Playwright E2E Tests
Browser Projects
Playwright is configured with 5 browser projects:Auth Setup
E2E tests authenticate before running specs usingauth.setup.ts: