Skip to content

fix: show changed files without coverage data as 0% covered - #72

Closed
aGallea wants to merge 3 commits into
masterfrom
fix/diffcover-missing-files
Closed

fix: show changed files without coverage data as 0% covered#72
aGallea wants to merge 3 commits into
masterfrom
fix/diffcover-missing-files

Conversation

@aGallea

@aGallea aGallea commented Feb 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • Bug: Changed files in a PR that had no matching entry in the coverage report were silently ignored. The getDiff function iterated over coverage entries (outer loop) and checked against changed files (inner loop), so files with zero coverage data were never visited.
  • Fix: Inverted the loop — changedFiles is now the driver. For each changed file, we look up coverage data. If none exists, all changed lines are reported as missed (0% covered). This also reduces git blame calls from O(coverage × changed) to O(changed).
  • Tests: Added 3 new test cases covering: files absent from coverage, mixed (some covered, some not), and empty coverage array with changed files. Updated existing test for new iteration order.

Changes

File What
src/diffCover.ts Rewrote getDiff — changedFiles as outer loop, coverage lookup per file
test/diffCover.test.ts 3 new tests + updated assertion order in existing test
dist/index.js Rebuilt via npm run package

Verification

  • All 12 test suites pass (npm test)
  • Lint clean (npm run lint)
  • TypeScript build clean (npm run build)
  • Pre-commit hooks pass

Changed files in a PR that have no matching entry in the coverage report
(lcov/cobertura/clover/jacoco) were silently ignored because the outer
loop in getDiff iterated over coverage entries, not changed files.

Invert the loop structure so changedFiles drives iteration. For each
changed file, look up a matching coverage entry. If none exists, treat
all changed lines as missed (0% coverage). This also reduces git blame
calls from O(coverageFiles * changedFiles) to O(changedFiles).

Add three tests covering: files with no coverage data, mixed coverage
scenarios, and empty coverage arrays with changed files.
@github-actions

github-actions Bot commented Feb 25, 2026

Copy link
Copy Markdown

Tests Report 📄

Tests Success ✅

JUnit Details

Total Tests Failures Errors Skipped Time ⏳
91 0 0 0 21.35s

Coverage Details (100% >= 80%) ✅

Diff Cover Details
FileCovered LinesMissing Lines
src/diffCover.ts102/102100%
Total102/102100%

@aGallea aGallea closed this Feb 25, 2026
@aGallea
aGallea deleted the fix/diffcover-missing-files branch February 25, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant