Skip to main content

Overview

T3 Code uses Vitest for all testing across the monorepo. The test suite includes unit tests, integration tests, and browser tests for React components.
NEVER run bun test. Always use bun run test which properly runs Vitest.

Running Tests

All Tests

Run the entire test suite across all packages:
This uses Turbo to run tests in parallel across all workspace packages.

Package-Specific Tests

Watch Mode

Run tests in watch mode during development:

Browser Tests (Web)

The web app includes browser-based component tests:

Test Structure

Unit Tests

Most files have corresponding .test.ts files in the same directory:

Integration Tests

Integration tests live in dedicated directories:

Test File Naming

Writing Tests

Basic Test Structure

T3 Code uses Effect-TS with Vitest, providing enhanced testing capabilities:
example.test.ts

Testing with Effect Services

Use test layers to provide mock services:
service.test.ts

Testing React Components

Web components use standard Vitest + React Testing Library patterns:
Component.test.tsx

Testing WebSocket Communication

Use MSW (Mock Service Worker) for WebSocket mocking:
wsTransport.test.ts

Test Utilities

Effect Test Utilities

Common patterns for Effect-based tests:

Mock Factories

Create reusable mock factories for common types:
testUtils.ts

Test Fixtures

Store test data in __fixtures__ directories:
provider.test.ts

Test Configuration

Root vitest.config.ts

vitest.config.ts

Package-Specific Config

Packages can override the root config:
apps/web/vitest.browser.config.ts

Testing Patterns

Testing Provider Adapters

CodexAdapter.test.ts

Testing Event Sourcing

OrchestrationEngine.test.ts

Testing WebSocket Protocol

wsServer.test.ts

Coverage

Generate coverage reports:
Coverage is configured in each package’s vitest.config.ts:

CI Integration

Tests run automatically in CI:
.github/workflows/test.yml

Best Practices

Test Behavior

Test behavior, not implementation details

Mock Layers

Use Effect layers for clean dependency injection in tests

Descriptive Names

Use clear, descriptive test names that explain intent

Fast Tests

Keep unit tests fast; use integration tests for E2E flows
Both bun lint and bun typecheck must pass before tasks are considered complete.

Debugging Tests

Debug Individual Tests

VS Code Debugging

Add to .vscode/launch.json:

Next Steps

Building

Learn how to build for production

Architecture

Review the system architecture