Skip to content

Commit

Permalink
feat(text): Coalesce ranges of missing lines (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
piranna authored and coreyfarrell committed Dec 12, 2019
1 parent 9546946 commit 54636fc
Show file tree
Hide file tree
Showing 2 changed files with 331 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/istanbul-reports/lib/text/index.js
Expand Up @@ -78,7 +78,25 @@ function nodeMissing(node) {
} else {
missingLines = fileCoverage.getUncoveredLines();
}
return missingLines.join(',');

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]);

return acum;
}, [])
.map(range => {
const { length } = range;

if (length <= 2) return range;

return `${range[0]}-${range[length - 1]}`;
});

return [].concat(...ranges).join(',');
}

function nodeName(node) {
Expand Down
312 changes: 312 additions & 0 deletions packages/istanbul-reports/test/fixtures/specs/coalescence.json
@@ -0,0 +1,312 @@
{
"title": "coalescense ranges of missing lines",
"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",
"htmlSpaFiles": ["index.js.html", "index.html"],
"htmlSpaCoverageData": {
"file": "",
"isEmpty": false,
"metrics": {
"statements": {
"total": 20,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "low"
},
"branches": {
"total": 0,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "empty"
},
"functions": {
"total": 0,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "empty"
},
"lines": {
"total": 18,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "low"
}
},
"children": [
{
"file": "index.js",
"isEmpty": false,
"metrics": {
"statements": {
"total": 20,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "low"
},
"branches": {
"total": 0,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "empty"
},
"functions": {
"total": 0,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "empty"
},
"lines": {
"total": 18,
"covered": 0,
"skipped": 0,
"pct": 0,
"classForPercent": "low"
}
},
"children": false
}
]
},
"map": {
"/index.js": {
"path": "/index.js",
"statementMap": {
"0": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 39
}
},
"1": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 32
}
},
"2": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 40
}
},
"3": {
"start": {
"line": 4,
"column": 13
},
"end": {
"line": 4,
"column": 28
}
},
"4": {
"start": {
"line": 5,
"column": 18
},
"end": {
"line": 5,
"column": 40
}
},
"5": {
"start": {
"line": 9,
"column": 2
},
"end": {
"line": 9,
"column": 11
}
},
"6": {
"start": {
"line": 13,
"column": 2
},
"end": {
"line": 19,
"column": 10
}
},
"7": {
"start": {
"line": 21,
"column": 2
},
"end": {
"line": 21,
"column": 81
}
},
"8": {
"start": {
"line": 21,
"column": 40
},
"end": {
"line": 21,
"column": 81
}
},
"9": {
"start": {
"line": 22,
"column": 2
},
"end": {
"line": 22,
"column": 69
}
},
"10": {
"start": {
"line": 22,
"column": 40
},
"end": {
"line": 22,
"column": 69
}
},
"11": {
"start": {
"line": 23,
"column": 2
},
"end": {
"line": 25,
"column": 3
}
},
"12": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 24,
"column": 63
}
},
"13": {
"start": {
"line": 28,
"column": 2
},
"end": {
"line": 30,
"column": 3
}
},
"14": {
"start": {
"line": 29,
"column": 4
},
"end": {
"line": 29,
"column": 54
}
},
"15": {
"start": {
"line": 32,
"column": 2
},
"end": {
"line": 36,
"column": 3
}
},
"16": {
"start": {
"line": 33,
"column": 4
},
"end": {
"line": 33,
"column": 57
}
},
"17": {
"start": {
"line": 35,
"column": 4
},
"end": {
"line": 35,
"column": 24
}
},
"18": {
"start": {
"line": 36,
"column": 2
},
"end": {
"line": 28,
"column": 3
}
},
"19": {
"start": {
"line": 37,
"column": 4
},
"end": {
"line": 37,
"column": 43
}
}
},
"fnMap": {},
"branchMap": {},
"s": {
"0": 0,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
"10": 0,
"11": 0,
"12": 0,
"13": 0,
"14": 0,
"15": 0,
"16": 0,
"17": 0,
"18": 0,
"19": 0
},
"f": {},
"b": {}
}
}
}

0 comments on commit 54636fc

Please sign in to comment.