The codebase maintains high test coverage with comprehensive test suites for all major functionality. Current coverage levels as of the latest test run:
- Statements: ~95%
- Branches: ~88%
- Functions: ~94%
- Lines: ~95%
This project uses /* v8 ignore next -- @preserve */ comments to mark code that cannot be tested without external dependencies (DCM, dart format, melos, Claude CLI). This approach:
- Clearly documents WHY certain code paths are intentionally untested
- Excludes marked code from coverage calculations
- Maintains high standards for testable code (94%+ coverage)
- Prevents false positives by not counting untestable external tool integration code
- Statements: 94%
- Branches: 87%
- Functions: 93%
- Lines: 94%
These high thresholds are achievable because external tool integration code is properly marked with v8 ignore comments.
External tool integration code is marked with the --@preserve flag to ensure comments are preserved in compiled JavaScript:
/* v8 ignore next -- @preserve */
try {
execSync(`dcm fix ${fileArgs}`, { cwd, stdio: 'pipe' });
} catch (error) {
console.error('Error: Failed to run dcm fix');
process.exit(1);
}The /* v8 ignore next -- @preserve */ comment tells vitest's v8 coverage provider to skip the next statement/block and preserve the comment in the transpiled code.
The following files integrate with external CLI tools and use v8 ignore comments to mark untestable code:
- Integrates with: DCM (Dart Code Metrics) CLI
- Marked with v8 ignore: External tool execution and result checking code
- Well-tested: Precondition checks, file filtering, error handling flows
- Manual testing: Actual DCM integration tested via lefthook pre-push hooks
- Integrates with:
dart formatCLI - Marked with v8 ignore: External tool execution and result checking code
- Well-tested: Precondition checks, file filtering
- Manual testing: Actual formatting tested via lefthook pre-push hooks
- Integrates with:
melosCLI for GraphQL code generation - Marked with v8 ignore: External tool execution and git status comparison code
- Well-tested: Precondition checks, file detection
- Manual testing: Actual codegen tested via lefthook pre-push hooks
- Integrates with:
dart fixand handles user interaction - Marked with v8 ignore: Some error handling blocks
- Well-tested: Core logic and non-interactive paths
- Integrates with: Claude CLI for AI-powered features
- Marked with c8/v8 ignore:
generateCommitMessage()functiongeneratePRDescription()function
- Well-tested: Core git operations
- Manual testing: Claude CLI integration
- Lower coverage reason: Simple utility functions with formatting logic that's less critical
- Well-tested:
logIfVerbosehelper function which reduces verbose code duplication
To reduce code duplication and improve coverage, use the logIfVerbose helper from src/utils/logger.ts:
import { logIfVerbose } from './utils/logger.js';
// Instead of:
if (verbose) {
console.error('✓ Operation completed');
}
// Use:
logIfVerbose(verbose, '✓ Operation completed');This helper is marked with /* v8 ignore next -- @preserve */ so the verbose check doesn't count against coverage, while keeping the calling code clean and testable.
-
Core business logic
- Dart package detection and import resolution (96% coverage)
- File filtering and dependency graph building (100% coverage)
- Command helper utilities (100% coverage)
-
Error handling flows
- Not in git repo → proper exit codes and messages
- Not in Dart package → proper error messages
- Invalid input → null returns or appropriate errors
-
Integration with fixtures
- Real Dart package fixtures
- Dart monorepo structures
- Non-standard package layouts
The test suite was improved in 2024 by:
- Removing 600 lines (17%) of low-quality tests that only verified mocking infrastructure
- Adding
/* v8 ignore next -- @preserve */comments to properly mark untestable code - Introducing
logIfVerbosehelper to reduce verbose code duplication
Result: High coverage (94%+) that accurately reflects testable business logic.
The /* v8 ignore next -- @preserve */ syntax:
v8 ignore next: Tells v8 coverage provider to skip the next statement/block--@preserve: Ensures the comment is preserved in transpiled JavaScript (TypeScript feature)
This is superior to lowering global thresholds because:
- ✅ Maintains high standards for testable code
- ✅ Clearly documents why specific code isn't tested
- ✅ Prevents false positives from untestable external tool code
- ✅ Works correctly with vitest 4.0.6+ and v8 coverage provider
See Vitest Coverage Documentation for more details.
Current coverage is at the practical maximum for this codebase. Further improvements would require:
- External tool integrations: Set up real integration test environments with Dart, DCM, melos installed (beyond unit test scope)
- Claude CLI functions: Requires external API access, best tested manually
- Logger formatting: Consider testing timestamp formatting if it becomes critical
The current approach balances test quality, CI reliability, and clear documentation of what is/isn't testable.