Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support merging MappedCoverage with FileCoverage from the same files #783

Open
mgfalzon opened this issue May 16, 2024 · 0 comments

Comments

@mgfalzon
Copy link

mgfalzon commented May 16, 2024

Various test runners (Jest, Vitest, Playwright) support a sharding option with --shard. When test runners run in this mode coverage is generated differently in each shard.

Example:
If A.ts is a dependency of the tests in --shard=1/2 and not a dependency of the tests in --shard=2/2 then the first shard's coverage report will reference a MappedCoverage instance of A.ts but the second shard will reference a FileCoverage instance.

Attempting to merge these files using istanbuljs will lead to inaccurate coverage. Presumably due to the mismatch in line numbers.

Workaround / Potential Solution
To work around this issue we can apply patches to istanbul-lib-coverage and istanbul-lib-source-maps which adds a new isMapped property denoting whether or not a file is an instance of MappedCoverage. We then prefer MappedCoverage over FileCoverage and prevent merges of MappedCoverage with FileCoverage for the same file.

istanbul-lib-coverage+3.2.2.patch
istanbul-lib-source-maps+4.0.0.patch

These patches only work when using the same TestRunner across merges! Solving for differing test-runners is a more complicated issue due to differences in transformation

Related Issues

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

No branches or pull requests

1 participant