This repository follows a specific testing convention to distinguish between different types of tests:
- Purpose: Test individual functions, classes, or modules in isolation
- Naming: Should match the file being tested (e.g.,
auth.spec.tstestsauth.ts) - Characteristics:
- Heavy use of mocks and stubs
- Test individual functions/methods
- Fast execution
- No external dependencies
Examples:
src/utils/auth.spec.ts- Testssrc/utils/auth.tssrc/cli/cli-functions.spec.ts- Testssrc/cli/cli-functions.tssrc/utils/token-storage.spec.ts- Testssrc/utils/token-storage.ts
- Purpose: Test multiple components working together or end-to-end functionality
- Naming: Descriptive of the integration being tested
- Characteristics:
- Test component interactions
- May use real implementations
- Test CLI commands end-to-end
- Test SDK integration with external APIs
Examples:
src/cli/cli.test.ts- Tests CLI command integrationsrc/platform-sdk.test.ts- Tests SDK integration with external APIssrc/index.test.ts- Tests main SDK exports and integration
The project is configured to run both types of tests:
include: ['src/**/*.{test,spec}.ts']invitest.config.ts- Both file patterns are excluded from coverage calculations
- TypeScript type checking is enabled for all test files
# Run all tests (both unit and integration)
npm test
# Run only unit tests
npm test -- --run src/**/*.spec.ts
# Run only integration tests
npm test -- --run src/**/*.test.ts
# Run with coverage
npm run test:coverage- Testing individual functions or methods
- Testing error handling and edge cases
- Testing business logic in isolation
- When you need fast, focused tests
- Testing CLI commands end-to-end
- Testing API integrations
- Testing multiple modules working together
- Testing user workflows
- Each source file should have a corresponding
.spec.tsfile for unit tests - Integration tests can test multiple files together
- Group related tests in
describeblocks - Use descriptive test names that explain the behavior being tested
- Overall coverage: 85% minimum
- Per-file coverage: 70% minimum for individual files
- Unit tests should achieve high coverage of individual modules
- Integration tests ensure components work together correctly