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 exec vitest run navbar # Run a specific test file (pnpm test -- <path> does NOT filter)
pnpm test -- -t "test name" # Run tests matching a name
pnpm test -- --coverage # Run with v8 coverageCoverage thresholds: 80% statements/lines/functions, 75% branches. Coverage includes lib/, hooks/, features/, components/, and proxy.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
The mobile app is planned but not yet implemented. The intended testing stack is Jest 30 + React Native Testing Library, matching the rest of the ecosystem.
CI/CD Integration
CI workflows run on pull requests to dev / staging / main:
| Subproject | CI Workflow | What Runs |
|---|---|---|
| Frontend | vezta-fe/.github/workflows/frontend-ci.yml | Vitest (unit + coverage) and Playwright (E2E) |
| Backend | vezta-be/.github/workflows/test.yml | Jest unit tests with coverage, then E2E with Docker services |
| Each subproject | .github/workflows/security.yml | CodeQL, dependency audit, secret scan |
| Each subproject | .github/workflows/governance.yml | Branch promotion policy enforcement |
Backend test CI runs automatically on PRs to main / staging and pushes to staging. Frontend CI runs on push/PR to main / staging / dev.