Testing
Unit, integration, and E2E testing patterns
Vezta has three subprojects with different test setups. All use TypeScript and share common patterns for mocking external APIs.
Frontend (Vitest)
The frontend uses Vitest with jsdom environment and globals enabled.
cd vezta-fe
pnpm test # Run all tests
pnpm test -- --testPathPattern=navbar # Run a specific test
pnpm test -- --coverage # Run with v8 coverageCoverage thresholds: 80% statements/lines/functions, 75% branches. Coverage includes lib/, hooks/, features/, components/, and middleware.ts -- but excludes lib/api/gen/ and lib/mock/.
Test Utilities
- Query wrapper (
test-utils/query-wrapper.tsx) -- creates a freshQueryClientper test for TanStack Query - Jotai wrapper (
test-utils/jotai-wrapper.tsx) --Providerwrapper for testing Jotai atoms - Zustand auto-reset (
__mocks__/zustand.ts) -- all Zustand stores reset between tests viavitest.setup.ts
MSW Mocking
MSW v2 intercepts all network requests during tests. Handlers are organized by domain in src/mocks/handlers/: alerts, comments, events, leaderboard, markets, notifications, portfolio, rewards, user. The MSW server is configured with onUnhandledRequest: 'error', meaning any unmocked API call will fail the test.
Playwright E2E
End-to-end tests live in e2e/ and run with Playwright (Chromium only). The dev server must be started manually before running tests -- Playwright does not start it.
pnpm dev # Start dev server first
npx playwright test # Then run E2E testsBackend (Jest)
The backend uses Jest with ts-jest transform. Unit tests are co-located as *.spec.ts files in src/.
cd vezta-be
pnpm test # Run all unit tests
pnpm test -- --testPathPattern=order # Run a specific test
pnpm test:watch # Watch mode
pnpm test:cov # With coverage
pnpm test:e2e # E2E testsE2E tests must use --runInBand (already configured). Running them concurrently causes database and Redis conflicts.
Test Utilities
| Helper | Location | Purpose |
|---|---|---|
createTestApp() | test/helpers/test-app.helper.ts | Builds a full NestJS test app with Fastify, global pipes, and filters |
| Auth helper | test/helpers/auth.helper.ts | JWT token generation for authenticated requests |
| Postgres helper | test/helpers/postgres.helper.ts | Testcontainers PostgreSQL setup/teardown |
| Redis helper | test/helpers/redis.helper.ts | Testcontainers Redis setup/teardown |
| Supertest helper | test/helpers/supertest.helper.ts | Typed HTTP request helpers for E2E tests |
| MSW server | test/mocks/server.ts | Intercepts external API calls (passes through localhost) |
Factories
Test data factories in test/factories/ generate realistic objects for tests:
order.factory-- creates Order objects with valid state machine transitionsmarket.factory-- creates Market objects with Polymarket or Kalshi source datauser.factory-- creates User objects with wallet addressesposition.factory-- creates Position objects with PnL calculationsjob.factory-- creates BullMQ Job mocks
Unit Test Pattern
import { Test } from '@nestjs/testing';
import { mock, MockProxy } from 'jest-mock-extended';
describe('OrderService', () => {
let service: OrderService;
let prisma: MockProxy<PrismaService>;
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [
OrderService,
{ provide: PrismaService, useValue: mock<PrismaService>() },
],
}).compile();
service = module.get(OrderService);
prisma = module.get(PrismaService);
});
});E2E Test Infrastructure
E2E tests use Docker service containers to avoid conflicts with development databases:
| Service | Test Port | Purpose |
|---|---|---|
| PostgreSQL | 5433 | Isolated test database |
| Redis | 6380 | Isolated test cache/queues |
The E2E config is in test/jest-e2e.json with a 30-second timeout.
Mobile (Jest + RNTL)
The mobile app uses Jest 30 with React Native Testing Library.
cd vezta-mobile
pnpm test # Run all tests
pnpm tsc # TypeScript type check (not tests, but catches type errors)CI/CD Integration
All three subprojects have CI workflows that run on pull requests to main:
| Subproject | CI Workflow | What Runs |
|---|---|---|
| Frontend | test.yml | Vitest (unit + coverage) and Playwright (E2E) |
| Backend | test.yml | Jest unit tests with coverage, then E2E with Docker services |
| Mobile | test.yml | pnpm tsc, pnpm lint, pnpm test |
The backend test CI is currently manual-only (workflow_dispatch). Frontend and mobile CI run automatically on push/PR to main.