Skip to content

Commit

Permalink
fix: add missing code coverage ranges that span only a single charact…
Browse files Browse the repository at this point in the history
…er (#8911)
  • Loading branch information
smithc committed Sep 7, 2022
1 parent 260e428 commit 0c577b9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/common/Coverage.ts
Expand Up @@ -484,6 +484,6 @@ function convertToDisjointRanges(
}
// Filter out empty ranges.
return results.filter(range => {
return range.end - range.start > 1;
return range.end - range.start > 0;
});
}
1 change: 1 addition & 0 deletions test/assets/jscoverage/involved.html
Expand Up @@ -6,6 +6,7 @@
console.log(2);
let x = 1 > 2 ? 'foo' : 'bar';
let y = 1 < 2 ? 'foo' : 'bar';
let p = {a:1 > 2?function(){console.log('unused');}:function(){console.log('unused');}};
let z = () => {};
let q = () => {};
q();
Expand Down
16 changes: 12 additions & 4 deletions test/golden-chromium/jscoverage-involved.txt
Expand Up @@ -16,13 +16,21 @@
},
{
"start": 148,
"end": 160
"end": 168
},
{
"start": 168,
"end": 207
"start": 203,
"end": 204
},
{
"start": 238,
"end": 251
},
{
"start": 259,
"end": 298
}
],
"text": "\nfunction foo() {\n if (1 > 2)\n console.log(1);\n if (1 < 2)\n console.log(2);\n let x = 1 > 2 ? 'foo' : 'bar';\n let y = 1 < 2 ? 'foo' : 'bar';\n let z = () => {};\n let q = () => {};\n q();\n}\n\nfoo();\n"
"text": "\nfunction foo() {\n if (1 > 2)\n console.log(1);\n if (1 < 2)\n console.log(2);\n let x = 1 > 2 ? 'foo' : 'bar';\n let y = 1 < 2 ? 'foo' : 'bar';\n let p = {a:1 > 2?function(){console.log('unused');}:function(){console.log('unused');}};\n let z = () => {};\n let q = () => {};\n q();\n}\n\nfoo();\n"
}
]
8 changes: 5 additions & 3 deletions test/src/coverage.spec.ts
Expand Up @@ -104,9 +104,11 @@ describe('Coverage specs', function () {
const coverage = await page.coverage.stopJSCoverage();
expect(coverage.length).toBe(1);
const entry = coverage[0]!;
expect(entry.ranges.length).toBe(1);
const range = entry.ranges[0]!;
expect(entry.text.substring(range.start, range.end)).toBe(
expect(entry.ranges.length).toBe(2);
const range1 = entry.ranges[0]!;
expect(entry.text.substring(range1.start, range1.end)).toBe('\n');
const range2 = entry.ranges[1]!;
expect(entry.text.substring(range2.start, range2.end)).toBe(
`console.log('used!');`
);
});
Expand Down

0 comments on commit 0c577b9

Please sign in to comment.