This project uses Vitest as the testing framework with React Testing Library for component testing.
- Node.js 20+
- npm 10+
__tests__/
├── indexeddb.test.ts # IndexedDB manager unit tests
├── team-context.test.tsx # React context provider tests
├── timer.test.ts # Timer functionality tests
└── utils.test.ts # Utility function tests
# Run all tests across the monorepo
npm run test
# Run tests once (CI mode)
npm run test:run
# Run tests with coverage
npm run test:coverage
# Run type checking
npm run typecheck
# Run linting
npm run lint# Run tests in watch mode
npm run test
# Run tests once
npm run test:run
# Run tests with UI
npm run test:ui
# Run tests with coverage
npm run test:coverage- Environment: jsdom (for DOM testing)
- Setup files:
vitest.setup.ts - Global test functions enabled
- Path aliases configured (@, @workspace/ui)
- Coverage with v8 provider
- Jest DOM matchers
- IndexedDB mocking
- localStorage mocking
- IDBKeyRange mocking
The IndexedDB API is mocked in the setup file to provide:
- Mock database operations
- Consistent test environment
- No actual browser storage usage
Components are tested using React Testing Library with:
- Render utilities
- User event simulation
- Async testing support
- Screen queries
- IndexedDB Manager: Database operations, data validation
- Utility Functions: Time formatting, color validation, ID generation
- Timer Logic: Time calculations, state management
- Team Context: Provider functionality, state management
- Component Interactions: User events, state updates
Coverage is configured to track:
- Statement coverage
- Branch coverage
- Function coverage
- Line coverage
Coverage reports are generated in multiple formats:
- Text (console output)
- HTML (browsable report)
- LCOV (CI integration)
- JSON (programmatic access)
The project includes a GitHub Action (.github/workflows/test.yml) that:
- Runs on push to main/develop branches
- Runs on pull requests
- Executes linting, type checking, and tests
- Generates coverage reports
- Builds the project
- Setup: Checkout code, setup Node.js and npm
- Dependencies: Install with frozen lockfile
- Quality Checks: Linting and type checking
- Testing: Run test suite
- Coverage: Generate and upload coverage reports
- Build: Verify project builds successfully
# Install dependencies
npm install
# Run all tests
npm run test:run
# Run with coverage
npm run test:coverage# Start tests in watch mode
cd apps/web
npm run testAfter running npm run test:coverage, coverage reports are available:
- Text output in terminal
- HTML report in
coverage/index.html - LCOV file for CI integration
- Descriptive Names: Use clear, descriptive test names
- Arrange-Act-Assert: Structure tests clearly
- Isolated Tests: Each test should be independent
- Mock External Dependencies: Mock APIs, databases, etc.
- User-Centric: Test from user perspective
- Async Handling: Use waitFor for async operations
- Accessibility: Test with screen reader queries
- State Management: Test state changes and side effects
- Update Dependencies: Keep testing libraries current
- Review Coverage: Aim for meaningful coverage
- Refactor Tests: Keep tests maintainable
- Document Changes: Update this README for changes
If tests fail with IndexedDB errors, ensure the mock is properly configured in vitest.setup.ts.
For "not wrapped in act()" warnings, wrap state updates in act() or use waitFor() for async operations.
If imports fail, check the path aliases in vitest.config.ts match your project structure.
If coverage seems incorrect, check the exclude patterns in the Vitest configuration.