Skip to content

Commit

Permalink
fix: ignore hint to exclude lines
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Mar 23, 2024
1 parent fcc2e35 commit 43c85d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
6 changes: 4 additions & 2 deletions lib/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,10 @@ module.exports = class V8ToIstanbul {
s: {}
}
source.lines.forEach((line, index) => {
statements.statementMap[`${index}`] = line.toIstanbul()
statements.s[`${index}`] = line.ignore ? 1 : line.count
if (!line.ignore) {
statements.statementMap[`${index}`] = line.toIstanbul()
statements.s[`${index}`] = line.count
}
})
return statements
}
Expand Down
22 changes: 0 additions & 22 deletions tap-snapshots/test/v8-to-istanbul.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,6 @@ Object {
"31": 1,
"32": 1,
"33": 1,
"34": 1,
"35": 1,
"36": 1,
"37": 1,
"4": 1,
Expand Down Expand Up @@ -677,26 +675,6 @@ Object {
"line": 34,
},
},
"34": Object {
"end": Object {
"column": 22,
"line": 35,
},
"start": Object {
"column": 0,
"line": 35,
},
},
"35": Object {
"end": Object {
"column": 28,
"line": 36,
},
"start": Object {
"column": 0,
"line": 36,
},
},
"36": Object {
"end": Object {
"column": 1,
Expand Down
13 changes: 11 additions & 2 deletions test/fixtures/scripts/ignored.lines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/* c8 ignore next 3 */
function sum(a, b) {
if(a === 2 && b === 2) {
return 4;
}

/* v8 ignore start */ // Line 6
if (a === '10') {
return add(a, b)
}
/* v8 ignore stop */ // Line 10

return a + b;
};
};
16 changes: 14 additions & 2 deletions test/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ ${'//'}${'#'} 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 () => {
it('ignore hint marks statements of uncovered file as excluded', async () => {
const filename = require.resolve('./fixtures/scripts/ignored.lines.js')
const source = readFileSync(filename, 'utf-8')
const v8ToIstanbul = new V8ToIstanbul(pathToFileURL(filename).href)
Expand All @@ -163,7 +163,19 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
const coverageMap = v8ToIstanbul.toIstanbul()
const { s } = coverageMap[filename]

assert.deepStrictEqual(s, { 0: 1, 1: 1, 2: 1, 3: 1 })
assert.equal(s[0], 0)
assert.equal(s[1], 0)
assert.equal(s[2], 0)
assert.equal(s[3], 0)
assert.equal(s[4], 0)
assert.equal(s[5], undefined) // Line 6
assert.equal(s[6], undefined)
assert.equal(s[7], undefined)
assert.equal(s[8], undefined)
assert.equal(s[9], undefined) // Line 10
assert.equal(s[10], 0)
assert.equal(s[11], 0)
assert.equal(s[12], 0)
})
})

Expand Down

0 comments on commit 43c85d1

Please sign in to comment.