Test Suites
Unit Tests (Vitest)
Vitest runs unit tests for core utilities undertests/unit/.
Coverage output: test-results/unit/coverage
Run all unit tests:
E2E Tests (Playwright)
Playwright tests walk through the landing page and confidential chat flow with mocked provider responses. Test file:tests/e2e/secure-chat.spec.ts
Run E2E tests:
Required Environment Variables
Unit Tests
Unit tests requireFORM_TOKEN_SECRET to test form token generation and validation:
E2E Tests
E2E tests require additional variables:NEXT_PUBLIC_ATTESTATION_TEST_MODE=true- Skips real DCAP verification (attestation verification is mocked)FORM_TOKEN_SECRET- Required for form token validationNEXT_PUBLIC_SUPABASE_ANON_KEY- Required for Supabase client initialization
The
make test target automatically sets required env flags for both unit and E2E tests.Full Test Suite
Run all tests (unit + E2E) with a single command:- Vitest unit tests with coverage
- Playwright E2E suite with test mode flags
Test Configuration
Vitest Configuration
Config file:vitest.config.ts (or inline in package.json)
Key settings:
- Coverage provider: v8
- Coverage output:
test-results/unit/coverage - Test environment: Node.js (default)
Playwright Configuration
Config file:playwright.config.ts
Key settings:
- Base URL:
http://127.0.0.1:3000 - Browsers: Chromium (default)
- Test directory:
tests/e2e
Coverage Reports
Unit test coverage is generated intest-results/unit/coverage/ with HTML, JSON, and text reports.
View HTML coverage:
Writing Tests
Unit Test Example
E2E Test Example
Debugging Tests
Vitest Debug
Run with verbose output:Playwright Debug
Run in debug mode with inspector:playwright.config.ts:
Test Best Practices
- Isolate tests - Each test should be independent and not rely on others
- Mock external services - Use
NEXT_PUBLIC_ATTESTATION_TEST_MODE=truefor E2E tests - Use data attributes - Prefer
data-testidover fragile CSS selectors - Test user flows - E2E tests should simulate real user interactions
- Keep unit tests focused - Test single functions/modules in isolation
- Clean up state - Reset localStorage/sessionStorage between E2E tests
- Use assertions liberally - Better to over-assert than miss bugs
CI Integration
GitHub Actions runs the full test suite on every PR:Linting
Run ESLint with Next.js rules:Pre-commit Checklist
Before opening a PR:- ✅ Run
pnpm lint- No ESLint errors - ✅ Run
pnpm test:unit- All unit tests pass - ✅ Run
pnpm test:e2e- E2E tests pass with test mode - ✅ Verify coverage - Check
test-results/unit/coverage - ✅ Add tests for new features - Maintain high coverage
