Skip to main content

Testing Strategy

Cal.com uses a comprehensive testing strategy:
  1. Unit Tests - Vitest for business logic and utilities
  2. Integration Tests - Testing API endpoints and services
  3. E2E Tests - Playwright for end-to-end user flows
  4. 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:
Error example:

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 in packages/testing/:

Type Checking

Running Type Checks

Always run yarn type-check:ci --force before concluding that CI failures are unrelated to your changes.

Fixing Type Errors

  1. Run yarn prisma generate if you see missing enum/type errors
  2. Fix type errors before test failures - they’re often the root cause
  3. Never use as any to 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:
View coverage report in coverage/index.html.

Continuous Integration

Cal.com uses GitHub Actions for CI/CD:

CI Workflow

  1. Lint - Check code formatting and style
  2. Type Check - Verify TypeScript types
  3. Unit Tests - Run Vitest tests
  4. E2E Tests - Run Playwright tests
  5. Build - Ensure production build succeeds

Local Pre-Push Checks

Run these commands before pushing:

Testing Best Practices

Test Organization

Place test files next to the code they test for better discoverability.

Test Naming

Arrange-Act-Assert Pattern

Test Independence

Each test should be independent:

Debugging Tests

Playwright Debug Mode

Playwright Inspector

Vitest Debug Mode

Run with Node inspector:

Testing Checklist

Before committing:

Common Testing Issues

Issue: Timezone Inconsistencies

Solution: Always set TZ=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