VeztaVezta
Guides

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 coverage

Coverage 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 fresh QueryClient per test for TanStack Query
  • Jotai wrapper (test-utils/jotai-wrapper.tsx) -- Provider wrapper for testing Jotai atoms
  • Zustand auto-reset (__mocks__/zustand.ts) -- all Zustand stores reset between tests via vitest.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 tests

Backend (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 tests

E2E tests must use --runInBand (already configured). Running them concurrently causes database and Redis conflicts.

Test Utilities

HelperLocationPurpose
createTestApp()test/helpers/test-app.helper.tsBuilds a full NestJS test app with Fastify, global pipes, and filters
Auth helpertest/helpers/auth.helper.tsJWT token generation for authenticated requests
Postgres helpertest/helpers/postgres.helper.tsTestcontainers PostgreSQL setup/teardown
Redis helpertest/helpers/redis.helper.tsTestcontainers Redis setup/teardown
Supertest helpertest/helpers/supertest.helper.tsTyped HTTP request helpers for E2E tests
MSW servertest/mocks/server.tsIntercepts 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 transitions
  • market.factory -- creates Market objects with Polymarket or Kalshi source data
  • user.factory -- creates User objects with wallet addresses
  • position.factory -- creates Position objects with PnL calculations
  • job.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:

ServiceTest PortPurpose
PostgreSQL5433Isolated test database
Redis6380Isolated 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:

SubprojectCI WorkflowWhat Runs
Frontendtest.ymlVitest (unit + coverage) and Playwright (E2E)
Backendtest.ymlJest unit tests with coverage, then E2E with Docker services
Mobiletest.ymlpnpm 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.

On this page