From d34981c8131e2ecbff6fc02ffd8702fd9808e241 Mon Sep 17 00:00:00 2001 From: Florian Dubois Date: Thu, 23 Sep 2021 23:05:24 +0200 Subject: [PATCH] fix: lcov reporter crash when missing branches (#613) Co-authored-by: Benjamin E. Coe --- packages/istanbul-reports/lib/lcovonly/index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/istanbul-reports/lib/lcovonly/index.js b/packages/istanbul-reports/lib/lcovonly/index.js index 7aa2a866..809cfd73 100644 --- a/packages/istanbul-reports/lib/lcovonly/index.js +++ b/packages/istanbul-reports/lib/lcovonly/index.js @@ -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(',')); @@ -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);