Skip to content

Commit

Permalink
fix: ignore hint to mark uncovered files statements and lines
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jul 5, 2023
1 parent fca5e6a commit 4b68f64
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 38 deletions.
4 changes: 3 additions & 1 deletion lib/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ module.exports = class V8ToIstanbul {
s: {}
}
source.lines.forEach((line, index) => {
const srcLine = source.lines[line.startLine - 1]
const ignore = srcLine === undefined ? true : srcLine.ignore
statements.statementMap[`${index}`] = line.toIstanbul()
statements.s[`${index}`] = line.count
statements.s[`${index}`] = ignore ? 1 : line.count
})
return statements
}
Expand Down
74 changes: 37 additions & 37 deletions tap-snapshots/test/v8-to-istanbul.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ Object {
"0": 1,
"1": 1,
"10": 1,
"11": 0,
"12": 0,
"11": 1,
"12": 1,
"13": 1,
"14": 1,
"15": 1,
Expand Down Expand Up @@ -1256,14 +1256,14 @@ Object {
"30": 1,
"31": 1,
"32": 1,
"33": 0,
"34": 0,
"35": 0,
"33": 1,
"34": 1,
"35": 1,
"36": 1,
"37": 0,
"37": 1,
"38": 1,
"39": 1,
"4": 0,
"4": 1,
"40": 1,
"41": 1,
"42": 1,
Expand All @@ -1272,10 +1272,10 @@ Object {
"45": 1,
"46": 1,
"47": 1,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"5": 1,
"6": 1,
"7": 1,
"8": 1,
"9": 1,
},
"statementMap": Object {
Expand Down Expand Up @@ -2330,16 +2330,16 @@ Object {
},
},
"s": Object {
"0": 0,
"0": 1,
"1": 1,
"10": 1,
"11": 1,
"12": 1,
"13": 1,
"14": 0,
"15": 0,
"16": 0,
"17": 0,
"14": 1,
"15": 1,
"16": 1,
"17": 1,
"18": 1,
"19": 1,
"2": 1,
Expand All @@ -2351,7 +2351,7 @@ Object {
"25": 1,
"26": 1,
"27": 1,
"28": 0,
"28": 1,
"29": 1,
"3": 1,
"30": 1,
Expand Down Expand Up @@ -2936,7 +2936,7 @@ Object {
"22": 1,
"23": 1,
"24": 1,
"25": 0,
"25": 1,
"26": 1,
"27": 1,
"28": 1,
Expand All @@ -2948,18 +2948,18 @@ Object {
"33": 1,
"34": 1,
"35": 1,
"36": 0,
"37": 0,
"36": 1,
"37": 1,
"38": 1,
"39": 1,
"4": 1,
"40": 1,
"41": 1,
"42": 1,
"43": 0,
"44": 0,
"45": 0,
"46": 0,
"43": 1,
"44": 1,
"45": 1,
"46": 1,
"47": 1,
"48": 1,
"49": 1,
Expand All @@ -2969,25 +2969,25 @@ Object {
"52": 1,
"53": 1,
"54": 1,
"55": 0,
"56": 0,
"57": 0,
"58": 0,
"59": 0,
"55": 1,
"56": 1,
"57": 1,
"58": 1,
"59": 1,
"6": 1,
"60": 0,
"61": 0,
"62": 0,
"60": 1,
"61": 1,
"62": 1,
"63": 1,
"64": 1,
"65": 1,
"66": 1,
"67": 0,
"68": 0,
"69": 0,
"67": 1,
"68": 1,
"69": 1,
"7": 1,
"70": 0,
"71": 0,
"70": 1,
"71": 1,
"72": 1,
"73": 1,
"74": 1,
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/scripts/ignored.lines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* c8 ignore next 3 */
function sum(a, b) {
return a + b;
};
26 changes: 26 additions & 0 deletions test/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
}])
Object.keys(v8ToIstanbul.toIstanbul()).should.eql(['/src/index.ts', '/src/utils.ts'].map(path.normalize))
})

it('ignore hint marks statements of uncovered file as covered', async () => {
const filename = require.resolve('./fixtures/scripts/ignored.lines.js')
const source = readFileSync(filename, 'utf-8')
const v8ToIstanbul = new V8ToIstanbul(pathToFileURL(filename).href)
await v8ToIstanbul.load()

v8ToIstanbul.applyCoverage([
{
functionName: '(empty-report)',
ranges: [
{
startOffset: 0,
endOffset: source.length,
count: 0
}
],
isBlockCoverage: true
}
])

const coverageMap = v8ToIstanbul.toIstanbul()
const { s } = coverageMap[filename]

assert.deepStrictEqual(s, { 0: 1, 1: 1, 2: 1, 3: 1 })
})
})

describe('source map format edge cases', () => {
Expand Down

0 comments on commit 4b68f64

Please sign in to comment.