fix: add missing code coverage ranges that span only a single character (#8911)
This commit is contained in:
parent
260e428227
commit
0c577b9bf8
@ -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;
|
||||
});
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ function foo() {
|
||||
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();
|
||||
|
@ -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"
|
||||
}
|
||||
]
|
@ -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!');`
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user