Open-Source Wikis

/

Cal.com

/

How to contribute

/

Testing

calcom/cal.com

Testing

Cal.diy ships three test runners. Knowing which to reach for is mostly about which app or package you are touching.

Vitest — unit and component tests

  • Config: vitest.config.mts and vitest.workspace.ts at the repo root.
  • Global setup: setupVitest.ts.
  • Mocks: vitest-mocks/ plus per-package __mocks__ directories.
  • Coverage: @vitest/coverage-v8 (run via yarn vitest run --coverage).
  • Watch: yarn tdd (alias for vitest watch) or yarn test:ui.
TZ=UTC yarn test                       # one-shot
TZ=UTC yarn vitest run path/to/file    # specific file
yarn test:ui                           # Vitest UI on http://localhost:51204

Always run with TZ=UTC (the npm scripts already set this). Day.js + timezone tests assume UTC.

Mocks of note:

  • Prisma is mocked via prismock (an in-memory Prisma double) configured in vitest-mocks/.
  • HTTP fetch is mocked with vitest-fetch-mock.
  • The next router is mocked by next-router-mock.
  • Prisma utilities have a hand-rolled mock under packages/prisma/__mocks__.

Playwright — end-to-end

  • Config: playwright.config.ts.
  • Specs: apps/web/playwright/, packages/embeds/embed-core/playwright/, plus per-app-store specs under packages/app-store/*/playwright.
  • Workflows: .github/workflows/e2e.yml, e2e-app-store.yml, e2e-embed.yml, e2e-embed-react.yml, e2e-atoms.yml, e2e-api-v2.yml.
yarn db-seed     # seed the database first
yarn e2e         # main web e2e suite
yarn e2e:embed   # embed-core suite
yarn e2e:embed-react
yarn e2e:app-store
yarn test-e2e    # = db-seed + e2e

Playwright projects are scoped: --project=@calcom/web, --project=@calcom/app-store, --project=@calcom/embed-core, --project=@calcom/embed-react. NEXT_PUBLIC_IS_E2E=1 is set so the app can short-circuit external service calls in test mode.

Jest — apps/api/v2

The NestJS service uses Jest, configured in apps/api/v2/jest.config.ts and apps/api/v2/jest-e2e.ts. Run from the workspace root:

yarn workspace @calcom/api-v2 test
yarn workspace @calcom/api-v2 test:e2e

The CI pipeline .github/workflows/api-v2-unit-tests.yml runs the unit suite; e2e-api-v2.yml runs the end-to-end suite against a Postgres container.

Test infrastructure

  • packages/testing/ — shared test fixtures and helpers, including the booking scenario builder at packages/testing/src/lib/bookingScenario/bookingScenario.ts (used by every booking test).
  • packages/features/bookings/lib/handleNewBooking/test/ — the largest test directory in the project; covers the booking pipeline.
  • __mocks__/ directories sit alongside each package's source.

The booking test suite relies on a fluent builder pattern. A typical test wires up a user, an event type, calendars, and a booking via bookingScenario, then runs the booking handler and asserts on database state.

Synthetic monitoring

Production health is monitored by Checkly (checkly.config.ts + __checks__/). These are not run in the local dev loop; they execute against a staging URL on a schedule.

What to test

AGENTS.md says:

  • Run type check on changed files before committing.
  • Run relevant tests before pushing.
  • Run Biome before pushing.

Concretely: if you touched a service or repository, add a Vitest unit test next to it. If you changed a user-visible flow, add or extend an E2E test. If you changed an apps/api/v2 controller, add an e2e spec — most of the API v2 controllers already have a *.e2e-spec.ts neighbor (e.g., apps/api/v2/src/platform/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts).

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Testing – Cal.com wiki | Factory