diff --git a/packages/istanbul-reports/lib/text/index.js b/packages/istanbul-reports/lib/text/index.js index 450013dc..d87ba298 100644 --- a/packages/istanbul-reports/lib/text/index.js +++ b/packages/istanbul-reports/lib/text/index.js @@ -67,33 +67,39 @@ function nodeMissing(node) { const isEmpty = metrics.isEmpty(); const lines = isEmpty ? 0 : metrics.lines.pct; - let missingLines; + let coveredLines; const fileCoverage = node.getFileCoverage(); if (lines === 100) { const branches = fileCoverage.getBranchCoverageByLine(); - missingLines = Object.keys(branches).filter( - key => branches[key].coverage < 100 - ); + coveredLines = Object.entries(branches).map(([key, { coverage }]) => [ + key, + coverage === 100 + ]); } else { - missingLines = fileCoverage.getUncoveredLines(); + coveredLines = Object.entries(fileCoverage.getLineCoverage()); } - const ranges = missingLines - .reduce((acum, line) => { - line = parseInt(line); - const range = acum[acum.length - 1]; - if (range && range[range.length - 1] === line - 1) range.push(line); - else acum.push([line]); + let newRange = true; + const ranges = coveredLines + .reduce((acum, [line, hit]) => { + if (hit) newRange = true; + else { + line = parseInt(line); + if (newRange) { + acum.push([line]); + newRange = false; + } else acum[acum.length - 1][1] = line; + } return acum; }, []) .map(range => { const { length } = range; - if (length <= 2) return range; + if (length === 1) return range[0]; - return `${range[0]}-${range[length - 1]}`; + return `${range[0]}-${range[1]}`; }); return [].concat(...ranges).join(','); diff --git a/packages/istanbul-reports/test/fixtures/specs/coalescence.json b/packages/istanbul-reports/test/fixtures/specs/coalescence.json index 736cfa5b..db972eb9 100644 --- a/packages/istanbul-reports/test/fixtures/specs/coalescence.json +++ b/packages/istanbul-reports/test/fixtures/specs/coalescence.json @@ -3,7 +3,7 @@ "opts": { "maxCols": 80 }, - "textReportExpected": "----------|---------|----------|---------|---------|----------------------------\nFile | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n----------|---------|----------|---------|---------|----------------------------\n\u001b[31;1mAll files\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[31;1m \u001b[0m \n\u001b[31;1m index.js\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[31;1m...21-24,28,29,32,33,35-37\u001b[0m \n----------|---------|----------|---------|---------|----------------------------\n", + "textReportExpected": "----------|---------|----------|---------|---------|----------------------\nFile | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n----------|---------|----------|---------|---------|----------------------\n\u001b[31;1mAll files\u001b[0m | \u001b[31;1m 30\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 33.33\u001b[0m | \u001b[31;1m \u001b[0m \n\u001b[31;1m index.js\u001b[0m | \u001b[31;1m 30\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 33.33\u001b[0m | \u001b[31;1m2,4,9,21-28,32,35-37\u001b[0m \n----------|---------|----------|---------|---------|----------------------\n", "htmlSpaFiles": ["index.js.html", "index.html"], "htmlSpaCoverageData": { "file": "", @@ -11,9 +11,9 @@ "metrics": { "statements": { "total": 20, - "covered": 0, + "covered": 6, "skipped": 0, - "pct": 0, + "pct": 30, "classForPercent": "low" }, "branches": { @@ -32,9 +32,9 @@ }, "lines": { "total": 18, - "covered": 0, + "covered": 6, "skipped": 0, - "pct": 0, + "pct": 33.33, "classForPercent": "low" } }, @@ -45,9 +45,9 @@ "metrics": { "statements": { "total": 20, - "covered": 0, + "covered": 6, "skipped": 0, - "pct": 0, + "pct": 30, "classForPercent": "low" }, "branches": { @@ -66,9 +66,9 @@ }, "lines": { "total": 18, - "covered": 0, + "covered": 6, "skipped": 0, - "pct": 0, + "pct": 33.33, "classForPercent": "low" } }, @@ -284,13 +284,13 @@ "fnMap": {}, "branchMap": {}, "s": { - "0": 0, + "0": 1, "1": 0, - "2": 0, + "2": 1, "3": 0, - "4": 0, + "4": 1, "5": 0, - "6": 0, + "6": 1, "7": 0, "8": 0, "9": 0, @@ -298,9 +298,9 @@ "11": 0, "12": 0, "13": 0, - "14": 0, + "14": 1, "15": 0, - "16": 0, + "16": 1, "17": 0, "18": 0, "19": 0 diff --git a/packages/istanbul-reports/test/fixtures/specs/maxcols.json b/packages/istanbul-reports/test/fixtures/specs/maxcols.json index 1d677437..8b7c49f4 100644 --- a/packages/istanbul-reports/test/fixtures/specs/maxcols.json +++ b/packages/istanbul-reports/test/fixtures/specs/maxcols.json @@ -3,7 +3,7 @@ "opts": { "maxCols": 80 }, - "textReportExpected": "----------|---------|----------|---------|---------|----------------------------\nFile | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n----------|---------|----------|---------|---------|----------------------------\n\u001b[31;1mAll files\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[31;1m \u001b[0m \n\u001b[31;1m index.js\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 0\u001b[0m | \u001b[31;1m...25,28,29,32,33,35,38,39\u001b[0m \n----------|---------|----------|---------|---------|----------------------------\n", + "textReportExpected": "----------|---------|----------|---------|---------|----------------------------\nFile | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n----------|---------|----------|---------|---------|----------------------------\n\u001b[31;1mAll files\u001b[0m | \u001b[31;1m 40\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 40\u001b[0m | \u001b[31;1m \u001b[0m \n\u001b[31;1m index.js\u001b[0m | \u001b[31;1m 40\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[32;1m 100\u001b[0m | \u001b[31;1m 40\u001b[0m | \u001b[31;1m...11,15,19,23,27,31,35,39\u001b[0m \n----------|---------|----------|---------|---------|----------------------------\n", "htmlSpaFiles": ["index.js.html", "index.html"], "htmlSpaCoverageData": { "file": "", @@ -11,9 +11,9 @@ "metrics": { "statements": { "total": 20, - "covered": 0, + "covered": 8, "skipped": 0, - "pct": 0, + "pct": 40, "classForPercent": "low" }, "branches": { @@ -31,10 +31,10 @@ "classForPercent": "empty" }, "lines": { - "total": 18, - "covered": 0, + "total": 20, + "covered": 8, "skipped": 0, - "pct": 0, + "pct": 40, "classForPercent": "low" } }, @@ -45,9 +45,9 @@ "metrics": { "statements": { "total": 20, - "covered": 0, + "covered": 8, "skipped": 0, - "pct": 0, + "pct": 40, "classForPercent": "low" }, "branches": { @@ -65,10 +65,10 @@ "classForPercent": "empty" }, "lines": { - "total": 18, - "covered": 0, + "total": 20, + "covered": 8, "skipped": 0, - "pct": 0, + "pct": 40, "classForPercent": "low" } }, @@ -132,11 +132,11 @@ }, "5": { "start": { - "line": 9, + "line": 11, "column": 2 }, "end": { - "line": 9, + "line": 11, "column": 11 } }, @@ -146,57 +146,57 @@ "column": 2 }, "end": { - "line": 19, + "line": 13, "column": 10 } }, "7": { "start": { - "line": 21, + "line": 15, "column": 2 }, "end": { - "line": 21, + "line": 15, "column": 81 } }, "8": { "start": { - "line": 21, + "line": 17, "column": 40 }, "end": { - "line": 21, + "line": 17, "column": 81 } }, "9": { "start": { - "line": 22, + "line": 19, "column": 2 }, "end": { - "line": 22, + "line": 19, "column": 69 } }, "10": { "start": { - "line": 22, + "line": 21, "column": 40 }, "end": { - "line": 22, + "line": 21, "column": 69 } }, "11": { "start": { - "line": 24, + "line": 23, "column": 2 }, "end": { - "line": 26, + "line": 23, "column": 3 } }, @@ -212,11 +212,11 @@ }, "13": { "start": { - "line": 28, + "line": 27, "column": 2 }, "end": { - "line": 30, + "line": 27, "column": 3 } }, @@ -232,11 +232,11 @@ }, "15": { "start": { - "line": 32, + "line": 31, "column": 2 }, "end": { - "line": 36, + "line": 31, "column": 3 } }, @@ -262,11 +262,11 @@ }, "18": { "start": { - "line": 38, + "line": 37, "column": 2 }, "end": { - "line": 40, + "line": 37, "column": 3 } }, @@ -288,21 +288,21 @@ "1": 0, "2": 0, "3": 0, - "4": 0, + "4": 1, "5": 0, - "6": 0, + "6": 1, "7": 0, - "8": 0, + "8": 1, "9": 0, - "10": 0, + "10": 1, "11": 0, - "12": 0, + "12": 1, "13": 0, - "14": 0, + "14": 1, "15": 0, - "16": 0, + "16": 1, "17": 0, - "18": 0, + "18": 1, "19": 0 }, "f": {},