Testing Philosophy
Our testing approach:- Unit tests — Test individual functions and components in isolation
- Integration tests — Test how components work together
- E2E tests — Test complete user workflows in a real browser
- Test coverage — Aim for high coverage on critical business logic
Unit & Integration Tests (Vitest)
Overview
We use Vitest for fast, modern JavaScript testing:- Fast — Powered by Vite’s transformation pipeline
- ESM-first — Native ES modules support
- TypeScript — First-class TypeScript support
- React Testing Library — For component testing
Configuration
Vitest is configured invitest.config.ts:
Running Tests
Test Scripts Reference
| Script | Command | Description |
|---|---|---|
test | vitest | Run tests in watch mode |
test:run | vitest run | Run tests once and exit |
test:coverage | vitest run --coverage | Generate coverage report |
test:ui | vitest --ui | Open Vitest UI dashboard |
Writing Unit Tests
Test files should be placed intests/unit/ and named *.test.ts or *.spec.ts.
Testing Utility Functions
Testing React Components
Testing Hooks
Test Setup
The test setup file (tests/setup.ts) configures mocks for Next.js and Supabase:
End-to-End Tests (Playwright)
Overview
We use Playwright for browser-based E2E testing:- Multi-browser — Test on Chromium and mobile Chrome
- Reliable — Auto-waiting and web-first assertions
- Fast — Parallel execution
- Debugging — UI mode, trace viewer, screenshots
Configuration
Playwright is configured inplaywright.config.ts:
Running E2E Tests
E2E Test Scripts Reference
| Script | Command | Description |
|---|---|---|
test:e2e | playwright test | Run E2E tests headless |
test:e2e:ui | playwright test --ui | Interactive UI mode |
test:e2e:headed | playwright test --headed | Run with visible browser |
test:e2e:report | playwright show-report | View HTML test report |
Writing E2E Tests
E2E test files go ine2e/ directory:
E2E Testing Patterns
Page Object Model
Page Object Model
Organize selectors and actions into page objects:
Test Data Management
Test Data Management
Use fixtures for consistent test data:
Visual Testing
Visual Testing
Take screenshots for visual regression testing:
Testing Best Practices
General Guidelines
- Test behavior, not implementation — Focus on what users see and do
- Use descriptive test names — Clearly state what is being tested
- Arrange-Act-Assert — Structure tests clearly
- Avoid testing implementation details — Don’t test internal state
- Keep tests independent — Each test should run in isolation
What to Test
Critical User Flows
Critical User Flows
- User authentication (login, logout, registration)
- Customer creation and editing
- Campaign creation and sending
- Reservation import and sync
- Loyalty tier upgrades
Business Logic
Business Logic
- RFM score calculation
- Loyalty points calculation
- Revenue analytics
- Customer segmentation
- Campaign audience filtering
Edge Cases
Edge Cases
- Empty states (no customers, no campaigns)
- Error handling (network failures, invalid data)
- Permission boundaries (RLS policies)
- Data validation
What NOT to Test
- Third-party libraries (React, Next.js internals)
- Trivial getters/setters
- External API integrations (mock these)
- Styling details (use visual regression sparingly)
Coverage Reports
Generate and view coverage reports:- Business logic — 80%+ coverage
- UI components — 60%+ coverage
- Utility functions — 90%+ coverage
Continuous Integration
Tests run automatically on CI for every pull request:Debugging Tests
Vitest Debugging
Playwright Debugging
Next Steps
Code Standards
Review coding conventions
Development Setup
Set up your environment
