Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "E" is not showing in the HTML reporter for "implicit else" branches after pull 633 #663

Merged
merged 7 commits into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/istanbul-reports/lib/html/annotator.js
Expand Up @@ -164,6 +164,18 @@ function annotateBranches(fileCoverage, structuredText) {
gt;
closeSpan = lt + '/span' + gt;

if (
adrian-burlacu-software marked this conversation as resolved.
Show resolved Hide resolved
count === 0 &&
startLine === undefined &&
branchMeta[branchName].type === 'if'
) {
const prevMeta = metaArray[i - 1];
startCol = prevMeta.start.column;
endCol = prevMeta.end.column + 1;
startLine = prevMeta.start.line;
endLine = prevMeta.end.line;
}

if (count === 0 && structuredText[startLine]) {
//skip branches taken
if (endLine !== startLine) {
Expand Down
127 changes: 127 additions & 0 deletions packages/istanbul-reports/test/fixtures/github-649.json
@@ -0,0 +1,127 @@
{
"path": "/Users/benjamincoe/bcoe/istanbul-lib-instrument/src/index.js",
"statementMap": {
"0": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 2
}
},
"1": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 11
}
},
"2": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 6,
"column": 5
}
},
"3": {
"start": {
"line": 5,
"column": 6
},
"end": {
"line": 5,
"column": 12
}
},
"4": {
"start": {
"line": 8,
"column": 4
},
"end": {
"line": 8,
"column": 13
}
}
},
"fnMap": {
"0": {
"name": "(anonymous_0)",
"decl": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 17
}
},
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 9,
"column": 1
}
},
"line": 1
}
},
"branchMap": {
"0": {
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 6,
"column": 5
}
},
"type": "if",
"locations": [{
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 6,
"column": 5
}
}, {
"start": {
},
"end": {
}
}
],
"line": 4
}
},
"s": {
"0": 1,
"1": 1,
"2": 1,
"3": 1,
"4": 1
},
"f": {
"0": 1
},
"b": {
"0": [1, 0]
},
"hash": "edc1f904dd2d4c7214941451a07aabfc0aee6ec0"
}
20 changes: 20 additions & 0 deletions packages/istanbul-reports/test/html/annotator.js
Expand Up @@ -81,5 +81,25 @@ describe('annotator', () => {
'<span class="fstat-no" title="function not covered" > function test () {};</span>'
);
});

// see: https://github.com/istanbuljs/istanbuljs/issues/649
it('handles implicit else branches', () => {
adrian-burlacu-software marked this conversation as resolved.
Show resolved Hide resolved
const annotated = annotator(getFixture('github-649'), {
getSource() {
return `exports.testy = function () {
let a = 0;

if (!a) {
a = 3;
}

return a;
};`;
}
});
annotated.annotatedCode[3].should.equal(
' <span class="missing-if-branch" title="else path not taken" >E</span> if (!a) {'
);
});
});
});