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

Ignore insignificant lines when coalesce #525

Merged
merged 33 commits into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f76180a
Remove whitespace on `DELIM`, PCT headers and remaining, and final delim
piranna Mar 25, 2019
4cbd57b
Set `PCT_COLS` to 7 characters except for `branches` column
piranna Mar 25, 2019
cf3b5db
Adjust `missing lines` column between header length and `maxCols`
piranna Mar 25, 2019
65f3062
[reports] Fixed tests
piranna Mar 26, 2019
91d570a
Fixed linting
piranna Mar 26, 2019
17dbcba
Added missing truncate of `missingWidth` when `nameWidth` gets truncated
piranna Mar 26, 2019
08db1ca
Added missing test for `maxCols` option
piranna Mar 26, 2019
c306a0a
Merge remote-tracking branch 'istanbuljs/master'
piranna May 11, 2019
892736c
Fix alignment of JSON fixtures
piranna May 11, 2019
e8282a6
Update `maxcols` fixture to new data format
piranna May 11, 2019
82600f8
[text reporter] Restore padding in columns delimiter
piranna May 12, 2019
ee8710a
[text reporter] adjust to terminal width
piranna May 12, 2019
3aca064
[test reporter] fix destructure from undefined options
piranna May 12, 2019
0633575
[text report] Short-circuit for summary lines
piranna May 13, 2019
d8e7643
[text reporter] Unified `missingLines`, `missingBranches` and `nodeMi…
piranna May 13, 2019
79dae9f
[text reporter] unified `findMissingWidth()` and `findNameWidth()`
piranna May 13, 2019
71e867f
[text report] Fixed tests fixtures
piranna May 13, 2019
d15eb21
[test reporter] Fixed linting
piranna May 13, 2019
5abd59d
[text reporter] Left align "Uncovered lines #s" column
piranna May 22, 2019
c26ef2a
[text reporter] Continuation dots at right side for left aligned tests
piranna May 22, 2019
4db79e5
Merge remote-tracking branch 'istanbuljs/master'
piranna May 26, 2019
1667c94
[text reporter] Left align with continuation dots on left side
piranna May 26, 2019
bc0d1cf
[text reporter] Remove useless `.map()` & move common `getFileCoverag…
piranna May 26, 2019
9eb9561
[text reporter] Updated fixtures for left align with left side dots
piranna May 26, 2019
755b13a
[text reporter] add right padding for `missing lines #s` column
piranna May 26, 2019
1eb1d3e
Merge remote-tracking branch 'istanbuljs/master'
piranna May 27, 2019
34b5b30
Merge branch 'master' of github.com:istanbuljs/istanbuljs
piranna Dec 11, 2019
b15bec4
[text report] Coalesce ranges of lines
piranna Dec 11, 2019
67d3510
[text report] Remove usage of `flatMap()` to be compatible with Node.…
piranna Dec 12, 2019
59dbe06
[Text report] Test for "coalescense ranges of missing lines"
piranna Dec 12, 2019
6fe668a
Merge remote-tracking branch 'istanbuljs/master'
piranna Feb 3, 2020
8fecd2d
[text report] Include empty lines in uncovered ranges
piranna Feb 3, 2020
4e56b41
[reports text] Fixed specs (they are re-used by `html-spa` report)
piranna Feb 3, 2020
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
32 changes: 19 additions & 13 deletions packages/istanbul-reports/lib/text/index.js
Expand Up @@ -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(',');
Expand Down
30 changes: 15 additions & 15 deletions packages/istanbul-reports/test/fixtures/specs/coalescence.json
Expand Up @@ -3,17 +3,17 @@
"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": "",
"isEmpty": false,
"metrics": {
"statements": {
"total": 20,
"covered": 0,
"covered": 6,
"skipped": 0,
"pct": 0,
"pct": 30,
"classForPercent": "low"
},
"branches": {
Expand All @@ -32,9 +32,9 @@
},
"lines": {
"total": 18,
"covered": 0,
"covered": 6,
"skipped": 0,
"pct": 0,
"pct": 33.33,
"classForPercent": "low"
}
},
Expand All @@ -45,9 +45,9 @@
"metrics": {
"statements": {
"total": 20,
"covered": 0,
"covered": 6,
"skipped": 0,
"pct": 0,
"pct": 30,
"classForPercent": "low"
},
"branches": {
Expand All @@ -66,9 +66,9 @@
},
"lines": {
"total": 18,
"covered": 0,
"covered": 6,
"skipped": 0,
"pct": 0,
"pct": 33.33,
"classForPercent": "low"
}
},
Expand Down Expand Up @@ -284,23 +284,23 @@
"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,
"10": 0,
"11": 0,
"12": 0,
"13": 0,
"14": 0,
"14": 1,
"15": 0,
"16": 0,
"16": 1,
"17": 0,
"18": 0,
"19": 0
Expand Down
76 changes: 38 additions & 38 deletions packages/istanbul-reports/test/fixtures/specs/maxcols.json
Expand Up @@ -3,17 +3,17 @@
"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": "",
"isEmpty": false,
"metrics": {
"statements": {
"total": 20,
"covered": 0,
"covered": 8,
"skipped": 0,
"pct": 0,
"pct": 40,
"classForPercent": "low"
},
"branches": {
Expand All @@ -31,10 +31,10 @@
"classForPercent": "empty"
},
"lines": {
"total": 18,
"covered": 0,
"total": 20,
"covered": 8,
"skipped": 0,
"pct": 0,
"pct": 40,
"classForPercent": "low"
}
},
Expand All @@ -45,9 +45,9 @@
"metrics": {
"statements": {
"total": 20,
"covered": 0,
"covered": 8,
"skipped": 0,
"pct": 0,
"pct": 40,
"classForPercent": "low"
},
"branches": {
Expand All @@ -65,10 +65,10 @@
"classForPercent": "empty"
},
"lines": {
"total": 18,
"covered": 0,
"total": 20,
"covered": 8,
"skipped": 0,
"pct": 0,
"pct": 40,
"classForPercent": "low"
}
},
Expand Down Expand Up @@ -132,11 +132,11 @@
},
"5": {
"start": {
"line": 9,
"line": 11,
"column": 2
},
"end": {
"line": 9,
"line": 11,
"column": 11
}
},
Expand All @@ -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
}
},
Expand All @@ -212,11 +212,11 @@
},
"13": {
"start": {
"line": 28,
"line": 27,
"column": 2
},
"end": {
"line": 30,
"line": 27,
"column": 3
}
},
Expand All @@ -232,11 +232,11 @@
},
"15": {
"start": {
"line": 32,
"line": 31,
"column": 2
},
"end": {
"line": 36,
"line": 31,
"column": 3
}
},
Expand All @@ -262,11 +262,11 @@
},
"18": {
"start": {
"line": 38,
"line": 37,
"column": 2
},
"end": {
"line": 40,
"line": 37,
"column": 3
}
},
Expand All @@ -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": {},
Expand Down