Skip to content

Commit

Permalink
fix: lcov reporter crash when missing branches (#613)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
Cairon and bcoe committed Sep 23, 2021
1 parent 4690531 commit d34981c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/istanbul-reports/lib/lcovonly/index.js
Expand Up @@ -29,7 +29,8 @@ class LcovOnlyReport extends ReportBase {
const path = require('path');

writer.println('TN:'); //no test nam
writer.println('SF:' + path.relative(this.projectRoot, fc.path));
const fileName = path.relative(this.projectRoot, fc.path);
writer.println('SF:' + fileName);

Object.values(functionMap).forEach(meta => {
writer.println('FN:' + [meta.decl.start.line, meta.name].join(','));
Expand All @@ -50,10 +51,14 @@ class LcovOnlyReport extends ReportBase {

Object.entries(branches).forEach(([key, branchArray]) => {
const meta = branchMap[key];
const { line } = meta.loc.start;
branchArray.forEach((b, i) => {
writer.println('BRDA:' + [line, key, i, b].join(','));
});
if (meta) {
const { line } = meta.loc.start;
branchArray.forEach((b, i) => {
writer.println('BRDA:' + [line, key, i, b].join(','));
});
} else {
console.warn('Missing coverage entries in', fileName, key);
}
});
writer.println('BRF:' + summary.branches.total);
writer.println('BRH:' + summary.branches.covered);
Expand Down

0 comments on commit d34981c

Please sign in to comment.