From 9163fb08877d4d21b9aef367e5b81d24c0d75ed4 Mon Sep 17 00:00:00 2001 From: AriPerkkio Date: Tue, 28 Feb 2023 20:00:38 +0200 Subject: [PATCH] test: empty coverage --- test/fixtures/scripts/uncovered.js | 7 +++++++ test/v8-to-istanbul.js | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/fixtures/scripts/uncovered.js diff --git a/test/fixtures/scripts/uncovered.js b/test/fixtures/scripts/uncovered.js new file mode 100644 index 00000000..9f94e563 --- /dev/null +++ b/test/fixtures/scripts/uncovered.js @@ -0,0 +1,7 @@ +function uncoveredFunction() { + return "Hello world"; +} + +if ("Branches here" === false) { + uncoveredFunction(); +} diff --git a/test/v8-to-istanbul.js b/test/v8-to-istanbul.js index 7a2c6938..b776ce00 100644 --- a/test/v8-to-istanbul.js +++ b/test/v8-to-istanbul.js @@ -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