๐งช Testing Overview
An introduction to testing strategies and tools in NestFlux applications.
๐ฏ Testing Philosophyโ
NestFlux embraces comprehensive testing to ensure code quality and reliability:
- Test-Driven Development: Writing tests alongside or before implementation
- Fast Feedback: Quick test execution for immediate developer feedback
- Comprehensive Coverage: Unit, integration, and end-to-end testing
- Maintainable Tests: Clear, readable tests that serve as living documentation
๐ ๏ธ Testing Stackโ
Vitest - Core Testing Frameworkโ
NestFlux uses Vitest as the primary testing framework across the entire monorepo:
- Lightning Fast: Native ESM support with instant hot module replacement
- TypeScript Native: First-class TypeScript support without additional setup
- Jest Compatible: Familiar API for developers coming from Jest
- Vite Integration: Leverages Vite's transformation and bundling capabilities
Vitest Workspaceโ
The monorepo uses Vitest Workspace for coordinated testing:
- Unified Configuration: Shared testing setup across all packages and applications
- Parallel Execution: Run tests across multiple projects simultaneously
- Selective Testing: Target specific packages or applications
- Consistent Tooling: Same testing experience everywhere in the monorepo
๐๏ธ Testing Architectureโ
Workspace Structureโ
The testing setup is organized across the monorepo:
vitest.config.ts # Shared test utilities and setup
โโโ tests/ # Global tests
โโโ apps/
โ โโโ client/
โ โ โโโ vitest.config.ts # Client-specific test config
โ โโโ server/
โ โโโ vitest.config.ts # Server-specific test config
โโโ packages/
โโโ api-definition/
โโโ constants/
โโโ models/
โโโ types/
โโโ utils/
โโโ vitest.config.ts # Package-specific configs
Testing Typesโ
Unit Testingโ
- Pure Functions: Business logic and utility functions
- Components: React components in isolation
- Services: NestJS services and controllers
- Utilities: Shared package functions
Component Testingโ
- React Components: User interface components with user interactions
- Integration: Component interactions with services and state
- Accessibility: Ensuring components meet accessibility standards
Integration Testingโ
- API Endpoints: Testing server routes and middleware
- Database Operations: Testing data layer interactions
- Service Integration: Testing service-to-service communication
๐ Running Testsโ
All Testsโ
Run tests across the entire monorepo:
pnpm test
Watch Modeโ
Run tests in watch mode for development:
pnpm test:dev
UI Modeโ
Run tests with Vitest's interactive UI:
pnpm test:ui
๐ง Test Configurationโ
Shared Configurationโ
Common test setup is defined in vitest.shared.ts
:
- Global test utilities
- Mock configurations
- Common matchers and helpers
- Environment setup
Project-Specific Configurationโ
Each application and package can have its own vitest.config.ts
:
- Custom test environment settings
- Project-specific mocks
- Specialized testing utilities
- Coverage configuration
๐ Test Coverageโ
Vitest provides built-in coverage reporting:
- Line Coverage: Percentage of code lines executed
- Branch Coverage: Percentage of code branches tested
- Function Coverage: Percentage of functions called
- Statement Coverage: Percentage of statements executed
Coverage reports help identify untested code and maintain quality standards.
๐งฉ Testing Ecosystemโ
CI/CD Integrationโ
Tests are automatically run in the CI/CD pipeline:
- Pull Request Validation: All tests must pass before merging
- Coverage Reporting: Track coverage trends over time
- Parallel Execution: Fast test feedback in automated workflows
Good tests are an investment in code quality, developer confidence, and long-term maintainability.