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
Branch merging broken when multiple files source-map to same origin file #233
Comments
Do you know if the underlying v8 coverage says it's covered? |
When I split out the two covered files and remove the SourceMappingURL comments, I see this for the commonjs file: And this for the ESM: When they're source mapped and merged together, the statements are being properly recorded, but instead of merging the covered branches, it's merging the uncovered branches or something? Note the The relevant blocks from V8's coverage output: {
"result": [
{
"scriptId": "134",
"url": "file:///Users/isaacs/dev/isaacs/c8-merge-issue/src/esm.index.js",
"functions": [
{
"functionName": "",
"ranges": [{ "startOffset": 0, "endOffset": 447, "count": 1 }],
"isBlockCoverage": true
},
{
"functionName": "x",
"ranges": [
{ "startOffset": 99, "endOffset": 380, "count": 1 },
{ "startOffset": 198, "endOffset": 274, "count": 0 }
],
"isBlockCoverage": true
}
]
},
{
"scriptId": "138",
"url": "file:///Users/isaacs/dev/isaacs/c8-merge-issue/src/commonjs.index.js",
"functions": [
{
"functionName": "",
"ranges": [{ "startOffset": 0, "endOffset": 552, "count": 1 }],
"isBlockCoverage": true
},
{
"functionName": "x",
"ranges": [
{ "startOffset": 189, "endOffset": 470, "count": 1 },
{ "startOffset": 364, "endOffset": 416, "count": 0 }
],
"isBlockCoverage": true
}
]
}
]
} |
So, according to v8, these are the uncovered blocks:
Looking those positions up in the source map, they correspond to:
So, according to v8 and the source maps, the |
Ok, digging through this, I think the issue might actually not be v8-to-istanbul, but rather istanbul-lib-coverage. In the
It seems like, when merging, it needs to determine if a range in one of the sets is fully contained by a range in the other. If so, add 1 to the hit count, rather than recording it as a new range with the original hit count. Ie, the expected hit-count in the result should be |
Demonstrated here: https://github.com/isaacs/c8-merge-issue/
The source, clearly showing that the branches get covered:
The test, covering all branches in the origin by loading the file from two different modules that sourcemap to the same origin:
Result:
It's clear that all branches in the origin are being covered, but when v8-to-istanbul merges them together, it reports missing branches.
The HTML report looks like this:
Explicitly ignoring the
{
in the first branch and theelse {
in the second makes it pass, but this should not be necessary.The text was updated successfully, but these errors were encountered: