Skip to main content

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 from vitest.config.ts:
  • Environment: jsdom (simulates browser DOM)
  • Coverage thresholds: 80% for branches, functions, lines, and statements
  • Path aliases: @/ maps to src/ (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 at src/__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 using auth.setup.ts:

Writing E2E Specs

Pre-Commit Test Commands

Before creating a PR, always run:
See the PR Checklist for the full verification workflow.