# tOS Test Infrastructure ## Frontend (apps/web) - Vitest ### Configuration - `vitest.config.ts` at project root of apps/web - Uses `@vitejs/plugin-react` for JSX transform - jsdom environment for DOM testing - `globals: true` so `describe/it/expect` are global - Path alias `@` -> `./src` matching tsconfig - CSS disabled in tests (`css: false`) - Setup file: `src/test/setup.ts` imports `@testing-library/jest-dom/vitest` ### Dependencies (devDependencies) - vitest ^2.1.8 - @testing-library/react ^16.1.0 - @testing-library/jest-dom ^6.6.3 - @testing-library/user-event ^14.5.2 - @vitejs/plugin-react ^4.3.4 - jsdom ^25.0.1 ### Test Files - `src/lib/utils.test.ts` - Tests for cn(), getInitials(), capitalize(), truncate(), safeJsonParse(), generateId(), isServer(), isClient() - `src/components/ui/badge.test.tsx` - Badge component rendering with all variants - `src/hooks/use-toast.test.ts` - Tests reducer logic and toast() function ### Run Commands ```bash pnpm --filter web test # vitest run pnpm --filter web test:watch # vitest (watch mode) ``` ## Backend (apps/api) - Jest ### Configuration - Inline in `package.json` under `"jest"` key - ts-jest transform for TypeScript - Node test environment - Module alias: `@/` -> `/` (rootDir = src) - Test regex: `.*\.spec\.ts$` ### Dependencies (already present) - jest ^29.7.0 - ts-jest ^29.1.1 - @nestjs/testing ^10.3.0 - @types/jest ^29.5.11 - supertest ^6.3.3 ### Test Files - `src/health/health.controller.spec.ts` - Health controller (check, liveness, readiness) - `src/common/services/encryption.service.spec.ts` - EncryptionService (encrypt/decrypt, objects, empty strings, generateKey, init) ### Test Patterns for NestJS - Use `Test.createTestingModule()` for DI setup - Mock all dependencies with `{ provide: X, useValue: mockX }` - Call `module.get(T)` to get the instance under test - For services with `onModuleInit()`, call it manually in `beforeEach` - Use `jest.clearAllMocks()` in `afterEach` ### Run Commands ```bash pnpm --filter api test # jest pnpm --filter api test:watch # jest --watch pnpm --filter api test:cov # jest --coverage ```