Testing Guide
This document provides a comprehensive guide to testing in the Rin project.
Overview
Rin uses one test runner across the repository:
- Runner: Bun's native test runner and the
bun:testAPI - Client environment: React component tests import the shared jsdom setup
- Server environment: Worker-compatible globals and an in-memory SQLite database
Running Tests
All Tests
Client Tests
Server Tests
Test Structure
Client Tests
Location: client/src/**/__tests__/*.test.ts
Server Tests
Locations:
- Unit tests:
server/src/**/__tests__/*.test.ts - Integration tests:
server/tests/integration/*.test.ts - Security tests:
server/tests/security/*.test.ts
Writing Tests
Client Testing
- Component Tests: Test React components in isolation
- API Client Tests: Test the HTTP client and API calls
- Utility Tests: Test helper functions
Example:
Server Testing
- Service Tests: Test business logic in services
- Router Tests: Test API endpoints
- Utility Tests: Test helper functions
Example with database:
Test Fixtures
Server tests use fixtures for mock data:
server/tests/fixtures/index.ts- Mock database and environment setupserver/tests/test-api-client.ts- Type-safe API client for tests
Coverage
The root command generates one combined coverage report:
The combined report is generated in coverage/. Package-level coverage commands still write to client/coverage/ or server/coverage/ when run from those directories.
CI/CD Integration
Tests run automatically on:
- Every push to
mainortrunkbranches - Every Pull Request
- Before deployment (blocking)
See GitHub Actions Workflows for details.
Best Practices
- Write tests for new features: Every new feature should include tests
- Test edge cases: Include tests for error conditions and boundary cases
- Use descriptive names: Test descriptions should clearly state what is being tested
- Keep tests independent: Each test should be able to run independently
- Mock external dependencies: Use mocks for external APIs and services
- Use one runner: Import test APIs only from
bun:test; do not add Vitest or another runner
Troubleshooting
Client Tests Failing
Server Tests Failing
Coverage Not Generated
Make sure you have the coverage reporter configured in your test config.