Skip to content

fix: include uncovered files in report when using --all with --include#589

Open
wellwelwel wants to merge 10 commits intobcoe:mainfrom
wellwelwel:all
Open

fix: include uncovered files in report when using --all with --include#589
wellwelwel wants to merge 10 commits intobcoe:mainfrom
wellwelwel:all

Conversation

@wellwelwel
Copy link
Copy Markdown

@wellwelwel wellwelwel commented Apr 1, 2026

Checklist
  • npm test, tests passing
  • npm run test:snap (to update the snapshot)
  • tests and/or benchmarks are included
  • documentation is changed or added

Fixes #588.

In lib/report.js, the _normalizeProcessCov method adds files to fileIndex before checking shouldInstrument():

if (/^file:\/\//.test(v8ScriptCov.url)) {
  // ...
    v8ScriptCov.url = fileURLToPath(v8ScriptCov.url)
    fileIndex.add(v8ScriptCov.url) //    added unconditionally
  // ...
if ((!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
  if (this.excludeAfterRemap || this._shouldInstrument(v8ScriptCov.url)) {
    result.push(v8ScriptCov) //          only added to result if passes filter
  }
}

Then:

  • V8 loads, for example, lib/results_stream.js during execution (via require() chain)
  • fileIndex.add(v8ScriptCov.url) is called unconditionally
  • shouldInstrument() returns false, so the file is not added to result
  • _includeUncoveredFiles finds the file via glob, but fileIndex.has() is true, so it's skipped
  • The file is absent from both V8 results and uncovered files

The fix moves fileIndex.add() to inside the shouldInstrument block, so only files that actually pass the filter are tracked.


About the test approach

The test uses createReport and _normalizeProcessCov directly instead of the spawnSync + matchSnapshot pattern used in most integration tests.

Since test-exclude's globSync internally calls shouldInstrument on every file it returns, the paths that fail shouldInstrument in _normalizeProcessCov won't collide with the paths from globSync in _includeUncoveredFiles. Because of that, a regular integration test would pass with or without the fix, so I couldn't find a way to catch a regression through the CLI alone, for example: wellwelwel#1 (comment).

By calling _normalizeProcessCov directly with fake V8 coverage entries, we can verify that fileIndex is only populated with files that pass shouldInstrument.

Note

I can also move this test to a separate file for unit tests if that makes more sense 🙋🏻‍♂️

@wellwelwel
Copy link
Copy Markdown
Author

Just as a proof of concept, here is the current test failure without the fix applied:

2 failing

1) c8
     --all
       should only track files that pass shouldInstrument in fileIndex:

    AssertionError: expected true to equal false
    + expected - actual

    -true
    +false
    
    at Context.<anonymous> (test/integration.js:543:44)
    at process.processImmediate (node:internal/timers:504:21)

2) c8 mergeAsync
     --all
       should only track files that pass shouldInstrument in fileIndex:

    AssertionError: expected true to equal false
    + expected - actual

    -true
    +false
    
    at Context.<anonymous> (test/integration.js:543:44)
    at process.processImmediate (node:internal/timers:504:21)

@wellwelwel wellwelwel changed the title All fix: include uncovered files in report when using --all with --include Apr 1, 2026
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.

Coverage report is missing uncovered files when using --all with --include

1 participant