diff-coverage
v0.1.6
Published
Git差分に対するJestテストカバレッジを計測するCLIツール
Readme
diff-coverage
A CLI tool that measures Jest/Vitest test coverage only for files changed in a git diff.
Instead of measuring whole-project coverage, diff-coverage focuses on the lines you actually changed — giving you actionable, targeted feedback.
Features
- Measures coverage only for changed files (not the entire codebase)
- Supports both Jest and Vitest (auto-detected)
- Per-file coverage breakdown with uncovered line numbers
- Configurable pass/fail threshold (exits with code 1 on failure)
- JSON output for programmatic use
- GitHub PR review comments with coverage gaps (
reviewcommand)
Installation
npm install -g diff-coverageOr run without installing via npx:
npx diff-coverage measure --cwd /path/to/your/projectCLI Usage
Basic — compare against main
diff-coverage measure --cwd /path/to/your/projectAll options
diff-coverage measure \
--cwd /path/to/project \ # project root (default: cwd)
--base main \ # base branch to diff against (default: merge-base of HEAD and main)
--runner jest \ # test runner: jest | vitest | auto (default: auto)
--cmd "npx jest" \ # override test runner command
--ext "ts,tsx" \ # file extensions to include (default: ts,tsx,js,jsx)
--threshold 80 \ # fail if line coverage is below this % (exit code 1)
--exclude "*.mocks.ts,src/fixtures/**" # glob patterns to exclude
--json # output results as JSON
--diff-only # show changed files only, skip running testsList changed files without running tests
diff-coverage measure --diff-only --cwd /path/to/projectExample output
=== Diff Coverage Report ===
Files changed: 3
Lines: 72.5% (58/80)
Statements: 70.0% (56/80)
Functions: 66.7% (4/6)
Branches: 50.0% (6/12)
Threshold: 80% → ❌ FAIL
--- Per File ---
✅ src/services/bookService.ts
Lines: 90% Stmts: 88% Fns: 100% Branches: 75%
⚠️ src/resolvers/bookResolver.ts
Lines: 60% Stmts: 58% Fns: 50% Branches: 40%
Uncovered lines: 45, 67, 89, 102
❌ src/utils/parser.ts
Lines: 30% Stmts: 28% Fns: 0% Branches: 0%
Uncovered lines: 12, 15, 18, 23, 34 ... (+8)CI Usage
# .github/workflows/coverage.yml
- name: Check diff coverage
run: |
npx diff-coverage measure \
--cwd . \
--base ${{ github.base_ref }} \
--threshold 80Jest / Vitest Configuration
diff-coverage works with your existing config with no changes required. For Jest, make sure coverageDirectory points to coverage/ (the default):
// jest.config.js
module.exports = {
coverageDirectory: "coverage", // default — usually no change needed
}Contributing
git clone https://github.com/ksugawara61/diff-coverage
cd diff-coverage
pnpm install
pnpm build
pnpm testLicense
MIT
