From 18fc6146c4e8a95662517b039ea8e99afb991e77 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Wed, 5 Jan 2022 15:16:20 +0200 Subject: [PATCH 1/7] Roll back to the prev. branch on implicit else. --- .../lib/html-spa/assets/sort-arrow-sprite.png | Bin 209 -> 208 bytes .../istanbul-reports/lib/html/annotator.js | 9 ++ .../lib/html/assets/favicon.png | Bin 540 -> 539 bytes .../lib/html/assets/sort-arrow-sprite.png | Bin 209 -> 208 bytes .../test/fixtures/github-649.json | 127 ++++++++++++++++++ .../istanbul-reports/test/html/annotator.js | 20 +++ 6 files changed, 156 insertions(+) create mode 100644 packages/istanbul-reports/test/fixtures/github-649.json diff --git a/packages/istanbul-reports/lib/html-spa/assets/sort-arrow-sprite.png b/packages/istanbul-reports/lib/html-spa/assets/sort-arrow-sprite.png index 03f704a609c6fd0dbfdac63466a7d7c958b5cbf3..795a9936e2c9532e64bc5b447054d0ab33965beb 100644 GIT binary patch delta 12 Tcmcb}c!80nGr-S%BI_9d9QFiw delta 13 Ucmcb>c#)B{Gr-TCcOuIf03byKg#Z8m diff --git a/packages/istanbul-reports/lib/html/annotator.js b/packages/istanbul-reports/lib/html/annotator.js index be8a4534..7770aeb5 100644 --- a/packages/istanbul-reports/lib/html/annotator.js +++ b/packages/istanbul-reports/lib/html/annotator.js @@ -164,6 +164,14 @@ function annotateBranches(fileCoverage, structuredText) { gt; closeSpan = lt + '/span' + gt; + if (count === 0 && startLine === undefined && branchMeta[branchName].type === 'if') { + let 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) { @@ -173,6 +181,7 @@ function annotateBranches(fileCoverage, structuredText) { } text = structuredText[startLine].text; if (branchMeta[branchName].type === 'if') { + debugger; // 'if' is a special case // since the else branch might not be visible, being non-existent text.insertAt( diff --git a/packages/istanbul-reports/lib/html/assets/favicon.png b/packages/istanbul-reports/lib/html/assets/favicon.png index 6691817834a957c938e7f09640a37a645fb31457..f676979c4b5c01dae604824d63975af34cb2c71f 100644 GIT binary patch delta 13 UcmbQkGMj~^Gr-S%Bda(Q02|N)fdBvi delta 14 VcmbQuGKYn=Gr-TCcO#296968_1C9Uy diff --git a/packages/istanbul-reports/lib/html/assets/sort-arrow-sprite.png b/packages/istanbul-reports/lib/html/assets/sort-arrow-sprite.png index 03f704a609c6fd0dbfdac63466a7d7c958b5cbf3..795a9936e2c9532e64bc5b447054d0ab33965beb 100644 GIT binary patch delta 12 Tcmcb}c!80nGr-S%BI_9d9QFiw delta 13 Ucmcb>c#)B{Gr-TCcOuIf03byKg#Z8m diff --git a/packages/istanbul-reports/test/fixtures/github-649.json b/packages/istanbul-reports/test/fixtures/github-649.json new file mode 100644 index 00000000..078b36fa --- /dev/null +++ b/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" +} diff --git a/packages/istanbul-reports/test/html/annotator.js b/packages/istanbul-reports/test/html/annotator.js index 78cc5331..07aa3a78 100644 --- a/packages/istanbul-reports/test/html/annotator.js +++ b/packages/istanbul-reports/test/html/annotator.js @@ -81,5 +81,25 @@ describe('annotator', () => { ' function test () {};' ); }); + + // see: https://github.com/istanbuljs/istanbuljs/issues/649 + it('handles implicit else branches', () => { + 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( + ' E if (!a) {' + ); + }); }); }); From a266b0ea40cb626d1e440d202d5b1dac823dca25 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Wed, 5 Jan 2022 15:18:42 +0200 Subject: [PATCH 2/7] Revert asset changes :S This partially reverts commit 18fc6146c4e8a95662517b039ea8e99afb991e77. --- .../lib/html-spa/assets/sort-arrow-sprite.png | Bin 208 -> 209 bytes .../lib/html/assets/favicon.png | Bin 539 -> 540 bytes .../lib/html/assets/sort-arrow-sprite.png | Bin 208 -> 209 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/packages/istanbul-reports/lib/html-spa/assets/sort-arrow-sprite.png b/packages/istanbul-reports/lib/html-spa/assets/sort-arrow-sprite.png index 795a9936e2c9532e64bc5b447054d0ab33965beb..03f704a609c6fd0dbfdac63466a7d7c958b5cbf3 100644 GIT binary patch delta 13 Ucmcb>c#)B{Gr-TCcOuIf03byKg#Z8m delta 12 Tcmcb}c!80nGr-S%BI_9d9QFiw diff --git a/packages/istanbul-reports/lib/html/assets/favicon.png b/packages/istanbul-reports/lib/html/assets/favicon.png index f676979c4b5c01dae604824d63975af34cb2c71f..6691817834a957c938e7f09640a37a645fb31457 100644 GIT binary patch delta 14 VcmbQuGKYn=Gr-TCcO#296968_1C9Uy delta 13 UcmbQkGMj~^Gr-S%Bda(Q02|N)fdBvi diff --git a/packages/istanbul-reports/lib/html/assets/sort-arrow-sprite.png b/packages/istanbul-reports/lib/html/assets/sort-arrow-sprite.png index 795a9936e2c9532e64bc5b447054d0ab33965beb..03f704a609c6fd0dbfdac63466a7d7c958b5cbf3 100644 GIT binary patch delta 13 Ucmcb>c#)B{Gr-TCcOuIf03byKg#Z8m delta 12 Tcmcb}c!80nGr-S%BI_9d9QFiw From 4d8649cbd7a2d6cf74c35327903cf43d8a0ba408 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Wed, 5 Jan 2022 15:20:09 +0200 Subject: [PATCH 3/7] Debugger statement :) --- packages/istanbul-reports/lib/html/annotator.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/istanbul-reports/lib/html/annotator.js b/packages/istanbul-reports/lib/html/annotator.js index 7770aeb5..e6deb42d 100644 --- a/packages/istanbul-reports/lib/html/annotator.js +++ b/packages/istanbul-reports/lib/html/annotator.js @@ -181,7 +181,6 @@ function annotateBranches(fileCoverage, structuredText) { } text = structuredText[startLine].text; if (branchMeta[branchName].type === 'if') { - debugger; // 'if' is a special case // since the else branch might not be visible, being non-existent text.insertAt( From 405fcd632ce0306ae078854e42c91ef7e2c3a85f Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Wed, 5 Jan 2022 15:27:37 +0200 Subject: [PATCH 4/7] Spacing. --- .../istanbul-reports/lib/html/annotator.js | 10 ++++-- .../istanbul-reports/test/html/annotator.js | 36 +++++++++---------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/istanbul-reports/lib/html/annotator.js b/packages/istanbul-reports/lib/html/annotator.js index e6deb42d..9ee77639 100644 --- a/packages/istanbul-reports/lib/html/annotator.js +++ b/packages/istanbul-reports/lib/html/annotator.js @@ -164,14 +164,18 @@ function annotateBranches(fileCoverage, structuredText) { gt; closeSpan = lt + '/span' + gt; - if (count === 0 && startLine === undefined && branchMeta[branchName].type === 'if') { - let prevMeta = metaArray[i - 1]; + if ( + 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) { diff --git a/packages/istanbul-reports/test/html/annotator.js b/packages/istanbul-reports/test/html/annotator.js index 07aa3a78..6c03efd6 100644 --- a/packages/istanbul-reports/test/html/annotator.js +++ b/packages/istanbul-reports/test/html/annotator.js @@ -82,24 +82,24 @@ describe('annotator', () => { ); }); - // see: https://github.com/istanbuljs/istanbuljs/issues/649 - it('handles implicit else branches', () => { - const annotated = annotator(getFixture('github-649'), { - getSource() { - return `exports.testy = function () { - let a = 0; - - if (!a) { - a = 3; - } - - return a; - };`; - } + // see: https://github.com/istanbuljs/istanbuljs/issues/649 + it('handles implicit else branches', () => { + 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( + ' E if (!a) {' + ); }); - annotated.annotatedCode[3].should.equal( - ' E if (!a) {' - ); - }); }); }); From 7ebd37b07b0d04d95cfc71de33c999cff928aeaf Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Wed, 5 Jan 2022 15:30:34 +0200 Subject: [PATCH 5/7] Spacing. --- packages/istanbul-reports/lib/html/annotator.js | 2 +- packages/istanbul-reports/test/html/annotator.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/istanbul-reports/lib/html/annotator.js b/packages/istanbul-reports/lib/html/annotator.js index 9ee77639..8cc38c42 100644 --- a/packages/istanbul-reports/lib/html/annotator.js +++ b/packages/istanbul-reports/lib/html/annotator.js @@ -168,7 +168,7 @@ function annotateBranches(fileCoverage, structuredText) { count === 0 && startLine === undefined && branchMeta[branchName].type === 'if' - ) { + ) { const prevMeta = metaArray[i - 1]; startCol = prevMeta.start.column; endCol = prevMeta.end.column + 1; diff --git a/packages/istanbul-reports/test/html/annotator.js b/packages/istanbul-reports/test/html/annotator.js index 6c03efd6..f958d0fd 100644 --- a/packages/istanbul-reports/test/html/annotator.js +++ b/packages/istanbul-reports/test/html/annotator.js @@ -81,7 +81,7 @@ describe('annotator', () => { ' function test () {};' ); }); - + // see: https://github.com/istanbuljs/istanbuljs/issues/649 it('handles implicit else branches', () => { const annotated = annotator(getFixture('github-649'), { @@ -98,7 +98,7 @@ describe('annotator', () => { } }); annotated.annotatedCode[3].should.equal( - ' E if (!a) {' + ' E if (!a) {' ); }); }); From 99b1aa9be077555fced32ad395651831adc877c9 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Wed, 5 Jan 2022 15:34:01 +0200 Subject: [PATCH 6/7] Spacing. --- packages/istanbul-reports/test/html/annotator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/istanbul-reports/test/html/annotator.js b/packages/istanbul-reports/test/html/annotator.js index f958d0fd..b55b072b 100644 --- a/packages/istanbul-reports/test/html/annotator.js +++ b/packages/istanbul-reports/test/html/annotator.js @@ -98,7 +98,7 @@ describe('annotator', () => { } }); annotated.annotatedCode[3].should.equal( - ' E if (!a) {' + ' E if (!a) {' ); }); }); From 610f763318cb8b92465868ab0ca628d83bd5b706 Mon Sep 17 00:00:00 2001 From: Adrian Burlacu Date: Fri, 14 Jan 2022 17:51:46 +0200 Subject: [PATCH 7/7] Add thoughtful comment to implicit else fix. --- packages/istanbul-reports/lib/html/annotator.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/istanbul-reports/lib/html/annotator.js b/packages/istanbul-reports/lib/html/annotator.js index 8cc38c42..84d8fc39 100644 --- a/packages/istanbul-reports/lib/html/annotator.js +++ b/packages/istanbul-reports/lib/html/annotator.js @@ -164,6 +164,10 @@ function annotateBranches(fileCoverage, structuredText) { gt; closeSpan = lt + '/span' + gt; + // If the branch is an implicit else from an if statement, + // then the coverage report won't show a statistic. + // Therefore, the previous branch will be used to report that + // there is no coverage on that implicit branch. if ( count === 0 && startLine === undefined &&