fix: add missing code coverage ranges that span only a single character (#8911)

This commit is contained in:
smithc 2022-09-07 03:10:07 -04:00 committed by GitHub
parent 260e428227
commit 0c577b9bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 8 deletions

View File

@ -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;
});
}

View File

@ -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();

View File

@ -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"
}
]

View File

@ -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!');`
);
});