Skip to content

Commit

Permalink
test: empty coverage (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Sep 29, 2023
1 parent 1e820ef commit fa421e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/fixtures/scripts/uncovered.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function uncoveredFunction() {
return "Hello world";
}

if ("Branches here" === false) {
uncoveredFunction();
}
26 changes: 26 additions & 0 deletions test/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
assert(v8ToIstanbul.sourceMap !== undefined)
})

it('empty coverage marks all lines uncovered', async () => {
const filename = require.resolve('./fixtures/scripts/uncovered.js')
const v8ToIstanbul = new V8ToIstanbul(filename)

await v8ToIstanbul.load()
v8ToIstanbul.applyCoverage([{
functionName: '(empty-report)',
ranges: [{
startOffset: 0,
endOffset: lstatSync(filename).size,
count: 0
}],
isBlockCoverage: true
}])

v8ToIstanbul.toIstanbul()[filename].s.should.eql({
0: 0,
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0
})
})

// execute JavaScript files in fixtures directory; these
// files contain the raw v8 output along with a set of
// assertions. the original scripts can be found in the
Expand Down

0 comments on commit fa421e7

Please sign in to comment.