vitest-coverage-report-action icon indicating copy to clipboard operation
vitest-coverage-report-action copied to clipboard

feat: add configurable comparison options for coverage reports

Open Copilot opened this issue 6 months ago • 0 comments

Overview

This PR adds three new configuration options to enhance the coverage comparison functionality, addressing the feature requests in #532.

Motivation

On large projects, the current comparison behavior has limitations:

  1. Precision Loss: Small percentage changes (±0.01%) can represent significant coverage differences (entire test files added/deleted), but they show as ±0.00% when rounded to 2 decimal places
  2. Limited Visibility: Comparison data only shows on changed files, making it hard to spot coverage changes in unchanged files
  3. No Impact Grouping: When coverage changes ripple through unchanged files (e.g., from integration tests), there's no easy way to identify which files were affected

New Features

1. Configurable Decimal Places (comparison-decimal-places)

Control the precision of comparison percentages to see exact coverage changes:

- uses: davelosert/vitest-coverage-report-action@v2
  with:
    json-summary-compare-path: ./coverage/coverage-summary-base.json
    comparison-decimal-places: 4  # default: 2

Before (2 decimal places): +0.12%
After (4 decimal places): +0.1235%

2. Show All File Comparisons (show-all-file-comparisons)

Display comparison data for all files, not just changed ones:

- uses: davelosert/vitest-coverage-report-action@v2
  with:
    file-coverage-mode: all
    json-summary-compare-path: ./coverage/coverage-summary-base.json
    show-all-file-comparisons: true  # default: false

This reveals coverage changes across the entire codebase, helping identify unexpected impacts.

3. Affected Files Grouping (show-affected-files)

Automatically group unchanged files by coverage impact:

- uses: davelosert/vitest-coverage-report-action@v2
  with:
    file-coverage-mode: all
    json-summary-compare-path: ./coverage/coverage-summary-base.json
    show-affected-files: true  # default: false

Files are now categorized as:

  • Changed Files: Files modified in the PR
  • Affected Files: Unchanged files with coverage changes
  • Unaffected Files: Unchanged files with no coverage changes

Usage Example

These features work well together for comprehensive coverage analysis:

- uses: davelosert/vitest-coverage-report-action@v2
  with:
    file-coverage-mode: all
    json-summary-compare-path: ./coverage/coverage-summary-base.json
    comparison-decimal-places: 4
    show-all-file-comparisons: true
    show-affected-files: true

Technical Details

  • Backward Compatible: All features are opt-in with sensible defaults
  • Well Tested: Added 12 new tests (89 total, all passing ✅)
  • Type Safe: Full TypeScript type checking passes
  • Clean Code: All linting and formatting checks pass

Implementation

  • Modified getCompareString() to accept configurable decimal places
  • Extended generateFileCoverageHtml() with conditional comparison logic
  • Added splitFilesByCoverageChange() helper to identify coverage-affected files
  • Updated options parsing to support the new input parameters

Resolves #532

Original prompt

This section details on the original issue you should resolve

<issue_title>feature request: add more options to the comparison</issue_title> <issue_description>thank you for this very handy gh action!

It would be useful to have the ability when using json-summary-compare-path to:

  1. configure the summary comparison rounding decimal places of the percentages. That's because on large projects, those 2 decimal places that are rounded off currently in the delta comparison percentages, can be even whole test suite files added/deleted/etc. And as it is today, the delta appears to be ±0% which is not really true
  2. configure the option to show the comparison on each file and not just on the summary
  3. maybe even add one more group in the files list for "affected" (only when comparing) to show which files' coverage got affected by changes;

Thanks again!</issue_description>

Comments on the Issue (you are @copilot in this section)

@davelosert Hi @AntoniosHF , thank you very much for those suggestions, which are all valid and would be very nice additions.

If you want to have a stab at it and open a PR, I'll gladly accept it. Else, I will hand this to Copilot Coding Agent 🙂

Fixes davelosert/vitest-coverage-report-action#522

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Sep 30 '25 04:09 Copilot