Overview
Been uses a comprehensive testing strategy with two complementary testing frameworks:- Vitest for unit and component tests
- Playwright for end-to-end (E2E) tests
Unit & Component Testing with Vitest
Running Tests
Run all unit tests with coverage:Test Configuration
Vitest is configured invite.config.ts:
Key Features
- Browser mode: Tests run in a real Chromium browser using Playwright
- Coverage: Istanbul-based code coverage with reports in
coverage/ - Setup file:
vitest-setup.tsimports@testing-library/jest-dommatchers - JUnit reports: Test results exported to
reports/test.xmlfor CI/CD
Writing Unit Tests
Tests use Vitest with React Testing Library. Here’s an example of a custom hook test:Writing Component Tests
Example component test with snapshot testing:Test File Location
- Unit tests: Place
.spec.tsor.spec.tsxfiles next to the source files they test - E2E tests: Place in
src/__e2e-test__/directory (excluded from unit tests)
Available Matchers
The project includes@testing-library/jest-dom which provides additional matchers:
toBeInTheDocument()toHaveClass()toBeVisible()toHaveTextContent()- And many more
End-to-End Testing with Playwright
Running E2E Tests
Run all E2E tests:- Starts the preview server (builds the app first if needed)
- Runs all tests in
src/__e2e-test__/ - Captures traces for debugging
Playwright Configuration
Configured inplaywright.config.ts:
Key Features
- Automatic server: Playwright starts and stops the web server automatically
- Trace collection: Full traces captured for debugging failed tests
- CI-ready: Uses production build in CI environments
- Server reuse: Reuses existing dev server in local development
Writing E2E Tests
Example E2E test:E2E Best Practices
- Use data-testid attributes: For reliable element selection
- Wait for states: Use
waitForLoadState(),waitForSelector(), etc. - Test user flows: Focus on complete user journeys, not implementation details
- Keep tests independent: Each test should run in isolation
Coverage Reports
After runningpnpm test, coverage reports are generated in the coverage/ directory:
coverage/index.html: Interactive HTML report- Various formats for CI integration
Excluded from Coverage
src/index.tsx(application entry point)- All test files (
*.spec.ts,*.spec.tsx)
Continuous Integration
The test setup is optimized for CI/CD:- JUnit reports:
reports/test.xmlfor CI dashboards - Environment detection: Uses production build and preview server in CI
- No server reuse in CI: Ensures clean test environment
Testing Tips
Running Specific Tests
Vitest supports filtering:Debugging Tests
Vitest: Use browser DevTools when running withbrowser.headless: false
Playwright: View traces after test runs: