Skip to content

Commit

Permalink
add extras to snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 3, 2024
1 parent ef59d71 commit 58881cb
Show file tree
Hide file tree
Showing 24 changed files with 756 additions and 377 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- added new build-in report: `markdown-summary` (coverage-summary.md)
- added new build-in report: `markdown-details` (coverage-details.md)
- added new option: `dataDir` alternative to method `addFromDir()`
- added new data `extras` for blank/comment/ignored lines

- 2.8.7
- fixed OOM with better GC
Expand Down
4 changes: 2 additions & 2 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const getDetailsRows = (files, metrics, cdOptions, color) => {

const { sourcePath, summary } = file;
const fileRow = getRowData(sourcePath, summary, metrics, color);
fileRow.uncoveredLines = Util.getUncoveredLines(file, color);
fileRow.uncoveredLines = Util.getUncoveredLines(file.data.lines, color);
flatRows.push(fileRow);
});

Expand Down Expand Up @@ -431,7 +431,7 @@ const handleMarkdownDetailsReport = async (reportData, reportOptions, options) =
fileRow.name = `[${fileRow.name}](${baseUrl + sourcePath})`;
}

fileRow.uncoveredLines = Util.getUncoveredLines(file, color);
fileRow.uncoveredLines = Util.getUncoveredLines(file.data.lines, color);
rows.push(fileRow);
});

Expand Down
5 changes: 4 additions & 1 deletion lib/istanbul/istanbul-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ class IstanbulSummary extends ReportBase {

const fileCoverage = node.getFileCoverage();
const lines = fileCoverage.getLineCoverage();
// no extras for istanbul
const extras = {};

this.files.push({
sourcePath,
summary: fileSummary,
data: {
lines
lines,
extras
}
});
}
Expand Down
9 changes: 8 additions & 1 deletion lib/utils/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,14 @@ const getSnapshot = (reportData) => {
}
const fileSummary = {};
addPercent(fileSummary, file.summary);
fileSummary.uncoveredLines = Util.getUncoveredLines(file);
fileSummary.uncoveredLines = Util.getUncoveredLines(file.data.lines);

// no extras for istanbul
const extras = file.data.extras;
fileSummary.extras = Object.keys(extras).map((k) => {
return k + extras[k];
}).join(',');

snapshot.files[file.sourcePath] = fileSummary;
});

Expand Down
4 changes: 1 addition & 3 deletions lib/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,10 @@ const Util = {
return str;
},

getUncoveredLines: (file, color = '') => {
getUncoveredLines: (dataLines, color = '') => {

const lines = [];

const dataLines = file.data.lines;

let startLine;
let endLine;

Expand Down
9 changes: 6 additions & 3 deletions test/snapshot/anonymous.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@
"statements": "23.18 %",
"lines": "21.50 %",
"bytes": "26.51 %",
"uncoveredLines": "5-19,21,34-62,65,68-83,85,87,89,91-98,106-107,111-205,218,229-235,240,246-248,250-255,258-299"
"uncoveredLines": "5-19,21,34-62,65,68-83,85,87,89,91-98,106-107,111-205,218,229-235,240,246-248,250-255,258-299",
"extras": "1b,4b,23b,24b,25c,31b,32c,211b,212c,301b"
},
"anonymous-2.js": {
"functions": "100.00 %",
"branches": "",
"statements": "100.00 %",
"lines": "100.00 %",
"bytes": "100.00 %",
"uncoveredLines": ""
"uncoveredLines": "",
"extras": ""
},
"anonymous-3.js": {
"functions": "100.00 %",
"branches": "",
"statements": "100.00 %",
"lines": "100.00 %",
"bytes": "100.00 %",
"uncoveredLines": ""
"uncoveredLines": "",
"extras": ""
}
}
}
81 changes: 54 additions & 27 deletions test/snapshot/cli.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,215 +14,242 @@
"statements": "80.00 %",
"lines": "59.38 %",
"bytes": "70.64 %",
"uncoveredLines": "4-6,12-14,17,25-27,32-34"
"uncoveredLines": "4-6,12-14,17,25-27,32-34",
"extras": "3b,8b,11b,16b,18b,20b,24b,28b,36b,42b"
},
"test/mock/node/lib/koa.js": {
"functions": "0.00 %",
"branches": "0.00 %",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "1-23"
"uncoveredLines": "1-23",
"extras": "4b,10b,13b,15b,19b,24b"
},
"test/mock/node/lib/util.js": {
"functions": "0.00 %",
"branches": "0.00 %",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "6-18"
"uncoveredLines": "6-18",
"extras": "1c,2c,3c,4c,5b,11b,12b,14c,15b,17b,19b"
},
"test/mock/node/src/index.js": {
"functions": "",
"branches": "",
"statements": "100.00 %",
"lines": "100.00 %",
"bytes": "100.00 %",
"uncoveredLines": ""
"uncoveredLines": "",
"extras": "4b,10b"
},
"test/mock/src/async.js": {
"functions": "0.00 %",
"branches": "0.00 %",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "1-54"
"uncoveredLines": "1-54",
"extras": "4b,13b,14c,16b,18b,19c,21b,23b,27b,28b,35b,44b,53b,55b"
},
"test/mock/src/branch/assignment.js": {
"functions": "80.00 %",
"branches": "54.55 %",
"statements": "76.47 %",
"lines": "75.00 %",
"bytes": "78.10 %",
"uncoveredLines": "9-11,22-24"
"uncoveredLines": "9-11,22-24",
"extras": "1b,2c,3c,4b,13b,17b,21b,25b,28b,31b,32b,36b"
},
"test/mock/src/branch/branch.js": {
"functions": "70.00 %",
"branches": "65.85 %",
"statements": "84.72 %",
"lines": "73.87 %",
"bytes": "80.32 %",
"uncoveredLines": "9-19,27,53-56,70,77-79,104,115-120,132-135,140-142"
"uncoveredLines": "9-19,27,53-56,70,77-79,104,115-120,132-135,140-142",
"extras": "1c,2b,8b,14b,16c,20b,25b,26c,29b,30c,34b,35c,39b,41b,43b,52b,54c,57b,66b,68b,69c,72b,73c,81b,83b,94b,96b,101b,103c,107b,109b,111b,113b,114b,118c,121b,123b,130b,131b,133c,136b,137c,138c,146b,152b,154b,158b"
},
"test/mock/src/branch/conditional.js": {
"functions": "100.00 %",
"branches": "60.00 %",
"statements": "100.00 %",
"lines": "80.00 %",
"bytes": "94.35 %",
"uncoveredLines": "10,12,17,19,24,26,31,33"
"uncoveredLines": "10,12,17,19,24,26,31,33",
"extras": "1b,2c,37b,38b,40b,46b"
},
"test/mock/src/branch/if.js": {
"functions": "100.00 %",
"branches": "52.00 %",
"statements": "71.43 %",
"lines": "54.64 %",
"bytes": "67.31 %",
"uncoveredLines": "28-30,34-36,40-44,57-59,63-67,74-80,84-86,88-90,97-111"
"uncoveredLines": "28-30,34-36,40-44,57-59,63-67,74-80,84-86,88-90,97-111",
"extras": "1c,3b,7b,13b,21b,23b,25b,31b,37b,45b,47b,50b,54b,60b,68b,70b,73b,77b,83b,91b,93b,96b,100b,106b,114b,116b,118b,125b"
},
"test/mock/src/branch/logical.js": {
"functions": "100.00 %",
"branches": "74.07 %",
"statements": "100.00 %",
"lines": "82.14 %",
"bytes": "95.25 %",
"uncoveredLines": "22-23,33-34,38,45,48-49,59-60"
"uncoveredLines": "22-23,33-34,38,45,48-49,59-60",
"extras": "1c,2b,4b,10b,15b,19b,25b,29b,36b,40b,47b,51b,58b,62b,65b,66b,68b,73b,75b"
},
"test/mock/src/branch/switch.js": {
"functions": "100.00 %",
"branches": "40.91 %",
"statements": "70.00 %",
"lines": "67.06 %",
"bytes": "72.92 %",
"uncoveredLines": "22-24,30-32,37-38,44-47,51-52,58-64,72-78"
"uncoveredLines": "22-24,30-32,37-38,44-47,51-52,58-64,72-78",
"extras": "1c,2b,3c,82b,83b,91b"
},
"test/mock/src/closures.js": {
"functions": "0.00 %",
"branches": "0.00 %",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "1-44"
"uncoveredLines": "1-44",
"extras": "2b,7b,10b,12b,13c,17b,24c,26b,28b,31b,35b,40b,41b,45b"
},
"test/mock/src/comments.js": {
"functions": "",
"branches": "",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "4-46"
"uncoveredLines": "4-46",
"extras": "1c,2c,3b,5b,6c,8c,9c,11c,17b,18c,19c,20b,21c,22b,24b,26b,27c,28c,30c,31c,32b,34c,35b,36c,37b,39b,40c,41c,42c,43b,44c,45b,47c,48c,49b,50b,51b"
},
"test/mock/src/component.js": {
"functions": "50.00 %",
"branches": "50.00 %",
"statements": "72.73 %",
"lines": "31.25 %",
"bytes": "68.90 %",
"uncoveredLines": "4-6,12-22"
"uncoveredLines": "4-6,12-22",
"extras": "1b,3b,5b,7b,11b,15b,19b,23b,25b"
},
"test/mock/src/ignore/ignore.js": {
"functions": "100.00 %",
"branches": "60.00 %",
"statements": "83.33 %",
"lines": "78.95 %",
"bytes": "88.89 %",
"uncoveredLines": "9,33-35"
"uncoveredLines": "9,33-35",
"extras": "4b,6b,7c,8i,10c,11i,12b,13c,14i,15i,16i,17b,18b,20b,21i,22i,23i,24b,25b,27i,28i,29b,30c,31b,37b,45b,46b"
},
"test/mock/src/ignore/v8-ignore-next.js": {
"functions": "",
"branches": "75.00 %",
"statements": "100.00 %",
"lines": "75.00 %",
"bytes": "84.38 %",
"uncoveredLines": "20-22"
"uncoveredLines": "20-22",
"extras": "5c,6i,7i,8i,9b,10c,11i,12b,13c,14i,15b,16i,17b,21i,23b"
},
"test/mock/src/ignore/v8-ignore-return.js": {
"functions": "100.00 %",
"branches": "",
"statements": "100.00 %",
"lines": "100.00 %",
"bytes": "100.00 %",
"uncoveredLines": ""
"uncoveredLines": "",
"extras": "3c,4i,6b"
},
"test/mock/src/ignore/v8-ignore-start-stop.js": {
"functions": "",
"branches": "60.00 %",
"statements": "100.00 %",
"lines": "71.43 %",
"bytes": "85.30 %",
"uncoveredLines": "2,19"
"uncoveredLines": "2,19",
"extras": "5c,6i,7i,8i,9c,10b,11i,12i,13b,14i,15c,16b,20i,21i,22c,23c"
},
"test/mock/src/index.js": {
"functions": "0.00 %",
"branches": "0.00 %",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "1-123"
"uncoveredLines": "1-123",
"extras": "3b,5b,9b,11b,14b,17b,22b,25b,30b,33b,36b,39b,41b,44b,47b,52b,54b,58b,63b,67b,72b,79b,81b,85b,90b,94b,102b,105b,108b,110b,113b,115b,116b,117c,119b,120b,124b"
},
"test/mock/src/statement.js": {
"functions": "0.00 %",
"branches": "",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "1-32"
"uncoveredLines": "1-32",
"extras": "2b,7b,8c,12b,17b,22b,29b,33b"
},
"test/mock/src/statics.js": {
"functions": "0.00 %",
"branches": "0.00 %",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "1-32"
"uncoveredLines": "1-32",
"extras": "18b,20b,24b,29b,33b"
},
"test/mock/src/typescript.ts": {
"functions": "100.00 %",
"branches": "",
"statements": "100.00 %",
"lines": "100.00 %",
"bytes": "100.00 %",
"uncoveredLines": ""
"uncoveredLines": "",
"extras": "1c,6b,12b,13b,15c,16c,17c,22b,23c,24b,26b,28b,30b"
},
"test/mock/src/untest/empty.js": {
"functions": "",
"branches": "",
"statements": "",
"lines": "",
"bytes": "",
"uncoveredLines": ""
"uncoveredLines": "",
"extras": "1b"
},
"test/mock/src/untest/untest.js": {
"functions": "0.00 %",
"branches": "0.00 %",
"statements": "0.00 %",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "6-18"
"uncoveredLines": "6-18",
"extras": "1c,2c,3c,4c,5b,11b,12b,14c,15b,17b,19b"
},
"test/mock/src/untest/untest.scss": {
"functions": "",
"branches": "",
"statements": "",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "2-17"
"uncoveredLines": "2-17",
"extras": "1c,3b,7b,8c,9b,12b,14c,18b"
},
"test/mock/src/untest/untest.ts": {
"functions": "",
"branches": "",
"statements": "",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "2-31"
"uncoveredLines": "2-31",
"extras": "1c,6b,12b,13b,15c,16c,17c,22b,23c,24b,26b,28b,30b"
},
"test/mock/src/untest/untest.vue": {
"functions": "",
"branches": "",
"statements": "",
"lines": "0.00 %",
"bytes": "0.00 %",
"uncoveredLines": "1-15"
"uncoveredLines": "1-15",
"extras": "6b,10b,16b"
}
}
}
Loading

0 comments on commit 58881cb

Please sign in to comment.