Skip to content

Commit

Permalink
fix: handle reports with "loc" but no "decl" (#637)
Browse files Browse the repository at this point in the history
Fixes #322
  • Loading branch information
bcoe committed Oct 12, 2021
1 parent ca8ec8a commit cdc28f3
Show file tree
Hide file tree
Showing 6 changed files with 1,723 additions and 6 deletions.
11 changes: 7 additions & 4 deletions packages/istanbul-reports/lib/html/annotator.js
Expand Up @@ -86,10 +86,13 @@ function annotateFunctions(fileCoverage, structuredText) {
Object.entries(fnStats).forEach(([fName, count]) => {
const meta = fnMeta[fName];
const type = count > 0 ? 'yes' : 'no';
const startCol = meta.decl.start.column;
let endCol = meta.decl.end.column + 1;
const startLine = meta.decl.start.line;
const endLine = meta.decl.end.line;
// Some versions of the instrumenter in the wild populate 'func'
// but not 'decl':
const decl = meta.decl || meta.loc;
const startCol = decl.start.column;
let endCol = decl.end.column + 1;
const startLine = decl.start.line;
const endLine = decl.end.line;
const openSpan =
lt +
'span class="' +
Expand Down
8 changes: 6 additions & 2 deletions packages/istanbul-reports/lib/lcovonly/index.js
Expand Up @@ -8,6 +8,7 @@ const { ReportBase } = require('istanbul-lib-report');
class LcovOnlyReport extends ReportBase {
constructor(opts) {
super();
opts = opts || {};
this.file = opts.file || 'lcov.info';
this.projectRoot = opts.projectRoot || process.cwd();
this.contentWriter = null;
Expand All @@ -28,12 +29,15 @@ class LcovOnlyReport extends ReportBase {
const summary = node.getCoverageSummary();
const path = require('path');

writer.println('TN:'); //no test nam
writer.println('TN:');
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(','));
// Some versions of the instrumenter in the wild populate 'loc'
// but not 'decl':
const decl = meta.decl || meta.loc;
writer.println('FN:' + [decl.start.line, meta.name].join(','));
});
writer.println('FNF:' + summary.functions.total);
writer.println('FNH:' + summary.functions.covered);
Expand Down
28 changes: 28 additions & 0 deletions packages/istanbul-reports/test/fixtures/github-322.json
@@ -0,0 +1,28 @@
{
"statementMap": {
},
"fnMap": {
"0": {
"name": "test",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
}
}
},
"branchMap": {
},
"s": {
},
"f": {
"0": 0
},
"b": {
}
}

0 comments on commit cdc28f3

Please sign in to comment.