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 3616adf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 190 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
184 changes: 0 additions & 184 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 Expand Up @@ -1870,168 +1848,6 @@ Object {
}
`

exports['test/v8-to-istanbul.js TAP > must match shebang snapshot 1'] = `
Object {
"all": false,
"b": Object {
"0": Array [
1,
],
"1": Array [
1,
],
},
"branchMap": Object {
"0": Object {
"line": 2,
"loc": Object {
"end": Object {
"column": 7,
"line": 8,
},
"start": Object {
"column": -1,
"line": 2,
},
},
"locations": Array [
Object {
"end": Object {
"column": 7,
"line": 8,
},
"start": Object {
"column": -1,
"line": 2,
},
},
],
"type": "branch",
},
"1": Object {
"line": 2,
"loc": Object {
"end": Object {
"column": 7,
"line": 8,
},
"start": Object {
"column": 0,
"line": 2,
},
},
"locations": Array [
Object {
"end": Object {
"column": 7,
"line": 8,
},
"start": Object {
"column": 0,
"line": 2,
},
},
],
"type": "branch",
},
},
"f": Object {},
"fnMap": Object {},
"s": Object {
"0": 1,
"1": 1,
"2": 1,
"3": 1,
"4": 1,
"5": 1,
"6": 1,
"7": 1,
},
"statementMap": Object {
"0": Object {
"end": Object {
"column": 19,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"1": Object {
"end": Object {
"column": 12,
"line": 2,
},
"start": Object {
"column": 0,
"line": 2,
},
},
"2": Object {
"end": Object {
"column": 0,
"line": 3,
},
"start": Object {
"column": 0,
"line": 3,
},
},
"3": Object {
"end": Object {
"column": 19,
"line": 4,
},
"start": Object {
"column": 0,
"line": 4,
},
},
"4": Object {
"end": Object {
"column": 25,
"line": 5,
},
"start": Object {
"column": 0,
"line": 5,
},
},
"5": Object {
"end": Object {
"column": 1,
"line": 6,
},
"start": Object {
"column": 0,
"line": 6,
},
},
"6": Object {
"end": Object {
"column": 0,
"line": 7,
},
"start": Object {
"column": 0,
"line": 7,
},
},
"7": Object {
"end": Object {
"column": 7,
"line": 8,
},
"start": Object {
"column": 0,
"line": 8,
},
},
},
}
`

exports['test/v8-to-istanbul.js TAP > must match source-map and minified source snapshot 1'] = `
Object {
"all": false,
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 3616adf

Please sign in to comment.