Overview
All packages in the Happy Development monorepo use Vitest as the testing framework. Tests are colocated with source files for better maintainability.Test File Naming
Tests use two naming conventions:*.test.ts- Standard unit tests*.spec.ts- Specification tests*.integration.test.ts- Integration tests
Running Tests
All Tests
From any package directory:Watch Mode
For test-driven development:Specific Test Files
Using Vitest CLI:Package-Specific Testing
happy-cli
Test Approach: Real integration tests without mocking- API integration tests (make real server calls)
- Claude session scanner tests
- Daemon lifecycle tests
- Sandbox network isolation tests
happy-app
Test Approach: Unit tests for utilities and logic- Vitest for most tests
- Jest-Expo preset available but Vitest preferred
happy-server
Test Approach: Specification-style tests with focus on behavior- API route validation tests
- Database operation specs
- Image processing utilities
- Social features (friend notifications)
happy-agent
Test Approach: Unit and integration testshappy-wire
Test Approach: Schema validation testsWriting Tests
Test Structure
Follow this pattern:Testing Async Code
Integration Tests
Integration tests make real API calls:Test Coverage
Current test file counts by package:- happy-cli: 67 test files
- happy-app: 14 test files
- happy-agent: 10 test files
- happy-server: 13 test files
- happy-wire: 2 test files
Testing Best Practices
General Guidelines
- Colocate tests with source files
- Write tests before implementation for utilities (TDD)
- Test behavior, not implementation details
- Use descriptive test names that explain the scenario
- Avoid mocking when possible (prefer real integration tests)
happy-cli Specific
- Tests make real API calls (no mocking)
- Build before testing (
yarn testdoes this automatically) - Test files use both
.test.tsand.spec.tsconventions - Daemon tests use real process spawning
happy-app Specific
- Focus on utility and reducer logic
- UI components tested through manual QA
- Sync engine has comprehensive test coverage
- Use Vitest (not Jest) for consistency
happy-server Specific
- Write specs for all utility functions BEFORE implementation
- Use
.spec.tssuffix for specification tests - Test idempotency of operations
- Verify transaction behavior
Running Tests in CI
All packages include pre-publish hooks:- Code type-checks successfully
- All tests pass
- Build completes without errors
Debugging Tests
Vitest UI
Debug Specific Test
VSCode Debugging
Add to.vscode/launch.json:
Common Testing Issues
Tests Fail After Dependency Updates
Reinstall and rebuild:Integration Tests Fail
Check if services are running:TypeScript Errors in Tests
Ensure Vitest types are available:Next Steps
- Review building to understand the build process
- Study project structure to navigate the codebase
- Complete setup for local development environment