Quick reference
Run all tests
Generate coverage
Test a package
Watch mode
Running tests
All packages
Run the complete test suite:core→ Business logic and use casesbackground→ Service implementationsdesign-system→ UI component testspopup→ React component and integration tests
What pnpm test does
What pnpm test does
The root
package.json defines:run-p (from npm-run-all) runs all test scripts in parallel for faster execution.Tests run in Node.js environment via Vitest. No browser is required.
Individual packages
Run tests for a specific package:Use
pnpm --filter to run any script in a workspace package without navigating to its directory.Coverage reporting
Generate coverage
Run tests with coverage collection:- Runs each package’s test suite with coverage enabled
- Generates JSON summary reports
- Combines coverage from all packages
- Creates
coverage-badge.svgin the repository root
Coverage output
Coverage output
After running coverage, you’ll find:Open any
index.html file in a browser to explore line-by-line coverage.The
coverage/ directories are git-ignored. Only coverage-badge.svg is committed to the repository.Individual coverage reports
Generate coverage for a specific package:coverage/ directory in the respective package.
Coverage badge
The coverage badge is automatically generated by:- Reads combined coverage from all packages
- Calculates overall percentage
- Generates
coverage-badge.svgusingbadge-maker
Testing framework
Vitest configuration
Each package has a Vitest configuration in itsvite.config.ts or vitest.config.ts:
Configuration options
Configuration options
- globals: Enables
describe,it,expectwithout imports - environment:
nodefor non-browser code,jsdomfor React components - coverage.provider:
v8for fast, native coverage collection - coverage.reporter: Output formats (JSON, text, HTML)
Test file organization
Test files are co-located with source files or in dedicated test directories:File naming convention:
*.test.ts or *.test.tsx for test files. Vitest automatically discovers them.Writing tests
Unit tests (Core package)
Test pure business logic:Core testing patterns
Core testing patterns
Use cases: Test input/output behaviorEpics: Test observable streams
Service tests (Background package)
Test implementations with mocks:Background testing patterns
Background testing patterns
Service implementations:Extension API mocks:
Component tests (Design System & Popup)
Test React components:React testing patterns
React testing patterns
User interactions:Redux-connected components:
Watch mode
Run tests continuously during development:Watch mode features
Watch mode features
When in watch mode, Vitest offers:
- Automatic re-run: Tests re-run when files change
- Interactive CLI: Press keys to filter tests, update snapshots, etc.
- Fast feedback: Only related tests run on change
- Press
ato run all tests - Press
fto run only failed tests - Press
tto filter by test name pattern - Press
qto quit
Test organization guidelines
Follow these practices for maintainable tests:
- One concern per test: Each test should verify a single behavior
- Descriptive names: Use
it('should ...')format - Arrange-Act-Assert: Structure tests clearly
- Avoid implementation details: Test behavior, not internals
- Use factories: Create test data with helper functions
Continuous integration
In CI/CD pipelines:
- Run
pnpm install --frozen-lockfilefor reproducible dependencies - Execute
pnpm testto run all tests - Run
pnpm test:coverageto generate coverage reports - Fail the build if coverage drops below threshold
Troubleshooting
Tests failing with import errors
Tests failing with import errors
Ensure the core package is built:The core package compiles TypeScript to
lib/, which other packages import.Coverage reports missing
Coverage reports missing
Make sure you’re using the coverage scripts:Not:
Flaky tests in popup package
Flaky tests in popup package
React component tests may be flaky due to async rendering. Use
waitFor or findBy* queries:IndexedDB tests failing
IndexedDB tests failing
Ensure Or configure it globally in
fake-indexeddb is imported before tests:vitest.config.ts:Next steps
Contributing
Learn how to submit changes with tests
Architecture
Understand where to add tests for new features