Skip to content

Backend Testing

Ankit Upadhyay edited this page Aug 25, 2026 · 3 revisions

Backend: Testing

How the backend is tested. General strategy: Testing Strategy. Part of Backend Overview.

Runner and layout

  • Jest via ts-jest, testEnvironment: node, config apps/backend/jest.config.cjs (isolatedModules: true, diagnostics: false for speed). Scripts: pnpm test (jest), pnpm test:coverage.
  • Tests live under apps/backend/test/ (roots: ["<rootDir>/test"]), mirroring src/: test/routers, test/controllers, test/services (the largest three), plus test/models, middlewares, config, auth, labs, integrations, queues, utils, pdf, scripts, types, and test/app.test.ts - ~437 test files as of 2026-08 (testMatch: **/?(*.)+(spec|test).ts).

Setup

test/jest.setup.ts (setupFilesAfterEnv) only stubs STREAM_API_KEY/STREAM_API_SECRET. The MongoDB migration scaffold this file used to neutralize — the DUAL_WRITE_*/READ_FROM_POSTGRES flags, the src/utils/dual-write mock, mongodb-memory-server, and config/db.ts — was removed with the scaffold itself in PR #1819 (merged 2026-07-18, fixes #1818); there are no MongoDB-backed tests anymore, and Prisma is mapped to the real package source.

Module mapping

moduleNameMapper points workspace packages at their source: @yosemite-crew/database → packages/database/src/client.ts, @yosemite-crew/lib → packages/lib/src/index.ts, other @yosemite-crew/* → packages/*/src, src/* → <rootDir>/src/*, and rewrites .js import specifiers to source.

Coverage

Provider v8, output coverage/. collectCoverageFrom = src/**/*.ts with an explicit exclusion list (e.g. middlewares/auth.ts, some lab/room/invite controllers). On --coverage runs, workerIdleMemoryLimit: 512MB avoids a known V8 coverage assertion on CI. SonarCloud config at sonar-project.properties — see Code Quality Gates.

Related

Product & Domain
Architecture
Applications
Design & Accessibility
Engineering Handbook
Decisions (ADRs)
Design Docs & Plans
Roadmap
Operations
Meta

Canonical code & docs: main repo · Auto-generated companion: DeepWiki

Clone this wiki locally