Testing Strategy
Cal.com uses a comprehensive testing strategy:- Unit Tests - Vitest for business logic and utilities
- Integration Tests - Testing API endpoints and services
- E2E Tests - Playwright for end-to-end user flows
- Type Checking - TypeScript compiler for type safety
Unit Testing with Vitest
Running Unit Tests
Always set
TZ=UTC to ensure consistent timezone behavior across environments.Writing Unit Tests
Create test files with.test.ts or .spec.ts suffix:
Mocking Prisma
Use Prismock for Prisma mocking:Mocking Fetch
Use vitest-fetch-mock:E2E Testing with Playwright
Running E2E Tests
Installing Playwright Browsers
If you encounter browser errors:Writing E2E Tests
Create test files with.e2e.ts suffix:
E2E Test Configuration
Set environment variables in.env:
E2E Test Utilities
Cal.com provides E2E test utilities inpackages/testing/:
Type Checking
Running Type Checks
Fixing Type Errors
- Run
yarn prisma generateif you see missing enum/type errors - Fix type errors before test failures - they’re often the root cause
- Never use
as anyto bypass type errors
Integration Testing
Testing tRPC Endpoints
Testing API Routes
Database Testing
Using Test Database
Set up a separate test database:Database Seeding
Seed the database for testing:Reset Database Between Tests
Testing Commands Reference
Unit Tests
E2E Tests
Type Checking
Linting & Formatting
Test Coverage
Generate test coverage reports:coverage/index.html.
Continuous Integration
Cal.com uses GitHub Actions for CI/CD:CI Workflow
- Lint - Check code formatting and style
- Type Check - Verify TypeScript types
- Unit Tests - Run Vitest tests
- E2E Tests - Run Playwright tests
- Build - Ensure production build succeeds
Local Pre-Push Checks
Run these commands before pushing:Testing Best Practices
Test Organization
Test Naming
Arrange-Act-Assert Pattern
Test Independence
Each test should be independent:Debugging Tests
Playwright Debug Mode
Playwright Inspector
Vitest Debug Mode
Testing Checklist
Before committing:Common Testing Issues
Issue: Timezone Inconsistencies
Solution: Always setTZ=UTC when running tests:
Issue: Prisma Client Not Generated
Solution: Regenerate Prisma types:Issue: Playwright Browsers Not Installed
Solution: Install browsers:Issue: Port Already in Use
Solution: Kill process on port 3000:Resources
Next Steps
- Review Coding Guidelines
- Explore Architecture Overview
- Set up your Development Environment