Skip to content

[Bug]: Node 20.10.0 V8 coverage incorrect when file tested by multiple test files #14764

Closed as not planned
@kwmhp

Description

@kwmhp

Version

29.7.0

Steps to reproduce

  1. install node v20.10.0
  2. clone https://github.com/kwmhp/jest-v8-coverage-bug.git
  3. install packages
  4. run 'npm run test'
  5. check coverage report

Line 4-5 are marked as uncovered, although this is covered in test2.spec.ts

Expected behavior

100% code coverage. Code coverage when run from multiple test files is the same as if code is tested in a single test file.

Actual behavior

Code covered by tests in test2.spec.ts is not recognized as covered

Additional context

This issue started to appear on node 20.10.0. Node 20.9.0 runs correctly. I've also tested the jest 30 alpha2 version and the result is the same. I think this might be actually more of a nodejs bug than a jest issue. But I don't really know what happens between jest reporting the coverage and v8 reporting numbers for the lines.

I became aware of this issue because our CI delivered different coverage numbers than we saw locally. I isolated the issue down to being caused by the maxWorkers=2 setting we use in CI. We get different results locally as well, when running with runInBand or just 2 workers. It seemed like the order of execution is relevant for the coverage.
The code example is extracted from one file which reported different numbers based in the worker count and simplified slightly.

Sorry for editing this issue multiple times. I've not provided correct reproduction steps

Environment

Node: v20.10.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions