monocart-coverage-reports 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -18
- package/lib/converter/converter.js +41 -59
- package/lib/generate.js +11 -2
- package/lib/index.d.ts +5 -2
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/v8/v8.js +20 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,24 +43,6 @@ console.log(coverageResults.summary);
|
|
|
43
43
|
- [lib/default/options.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/lib/default/options.js)
|
|
44
44
|
|
|
45
45
|
## Available Reports
|
|
46
|
-
```js
|
|
47
|
-
const CoverageReport = require('monocart-coverage-reports');
|
|
48
|
-
const options = {
|
|
49
|
-
outputDir: './coverage-reports',
|
|
50
|
-
reports: [
|
|
51
|
-
['console-summary'],
|
|
52
|
-
['v8'],
|
|
53
|
-
['html', {
|
|
54
|
-
subdir: 'istanbul'
|
|
55
|
-
}],
|
|
56
|
-
['json', {
|
|
57
|
-
file: 'my-json-file.json'
|
|
58
|
-
}],
|
|
59
|
-
'lcovonly'
|
|
60
|
-
]
|
|
61
|
-
}
|
|
62
|
-
const coverageReport = new CoverageReport(options);
|
|
63
|
-
```
|
|
64
46
|
- `v8` (V8 data only)
|
|
65
47
|
- [V8 html](https://cenfun.github.io/monocart-coverage-reports/v8) - Example for browser, build with webpack, and also [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild)
|
|
66
48
|
- [V8 Node](https://cenfun.github.io/monocart-coverage-reports/v8-node-env) - Example for Node.js using env, and also [V8 API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/v8-node-cdp)
|
|
@@ -94,6 +76,25 @@ const coverageReport = new CoverageReport(options);
|
|
|
94
76
|
- `text-lcov`
|
|
95
77
|
- `text-summary`
|
|
96
78
|
|
|
79
|
+
```js
|
|
80
|
+
const CoverageReport = require('monocart-coverage-reports');
|
|
81
|
+
const options = {
|
|
82
|
+
outputDir: './coverage-reports',
|
|
83
|
+
reports: [
|
|
84
|
+
['console-summary'],
|
|
85
|
+
['v8'],
|
|
86
|
+
['html', {
|
|
87
|
+
subdir: 'istanbul'
|
|
88
|
+
}],
|
|
89
|
+
['json', {
|
|
90
|
+
file: 'my-json-file.json'
|
|
91
|
+
}],
|
|
92
|
+
'lcovonly'
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
const coverageReport = new CoverageReport(options);
|
|
96
|
+
```
|
|
97
|
+
|
|
97
98
|
## Integration
|
|
98
99
|
- [monocart-reporter](https://cenfun.github.io/monocart-reporter/) - Test reporter for [Playwright](https://github.com/microsoft/playwright)
|
|
99
100
|
- [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - Integration with [Vitest](https://github.com/vitest-dev/vitest) coverage
|
|
@@ -184,38 +184,9 @@ const collectFileCoverage = (item, coverageInfo, state) => {
|
|
|
184
184
|
|
|
185
185
|
// ========================================================================================================
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* @isBlockCoverage indicates if the function has block coverage information
|
|
191
|
-
* @false means that there is a single range and its count is the number of times the function was called.
|
|
192
|
-
* @true means that the ranges form a tree of blocks representing how many times each statement or expression inside was executed.
|
|
193
|
-
* It detects skipped or repeated statements. The root range counts the number of function calls.
|
|
194
|
-
*
|
|
195
|
-
* @functionName can be an empty string. This is common for the FunctionCov representing the whole module.
|
|
196
|
-
*/
|
|
197
|
-
// if you have a line of code that says `var x= 10; console.log(x);` that's one line and 2 statements.
|
|
198
|
-
|
|
199
|
-
const addJsLineCoverage = (state, range) => {
|
|
200
|
-
|
|
201
|
-
const { locator, coverageInfo } = state;
|
|
202
|
-
|
|
203
|
-
const { data, lineMap } = coverageInfo;
|
|
204
|
-
|
|
205
|
-
const {
|
|
206
|
-
startOffset, endOffset, count
|
|
207
|
-
} = range;
|
|
208
|
-
|
|
209
|
-
// add bytes range
|
|
210
|
-
data.bytes.push({
|
|
211
|
-
// index,
|
|
212
|
-
start: startOffset,
|
|
213
|
-
end: endOffset,
|
|
214
|
-
count
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
const sLoc = locator.offsetToLocation(startOffset);
|
|
218
|
-
const eLoc = locator.offsetToLocation(endOffset);
|
|
187
|
+
const updateLineCoverage = (start, end, count, lineMap, locator) => {
|
|
188
|
+
const sLoc = locator.offsetToLocation(start);
|
|
189
|
+
const eLoc = locator.offsetToLocation(end);
|
|
219
190
|
|
|
220
191
|
// update lines coverage
|
|
221
192
|
const lines = Util.getRangeLines(sLoc, eLoc);
|
|
@@ -251,6 +222,39 @@ const addJsLineCoverage = (state, range) => {
|
|
|
251
222
|
// console.log('===========================================', state.sourcePath);
|
|
252
223
|
// console.log(coverageInfo.lines);
|
|
253
224
|
// }
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// https://github.com/demurgos/v8-coverage
|
|
228
|
+
/**
|
|
229
|
+
* @ranges is always non-empty. The first range is called the "root range".
|
|
230
|
+
* @isBlockCoverage indicates if the function has block coverage information
|
|
231
|
+
* @false means that there is a single range and its count is the number of times the function was called.
|
|
232
|
+
* @true means that the ranges form a tree of blocks representing how many times each statement or expression inside was executed.
|
|
233
|
+
* It detects skipped or repeated statements. The root range counts the number of function calls.
|
|
234
|
+
*
|
|
235
|
+
* @functionName can be an empty string. This is common for the FunctionCov representing the whole module.
|
|
236
|
+
*/
|
|
237
|
+
// if you have a line of code that says `var x= 10; console.log(x);` that's one line and 2 statements.
|
|
238
|
+
|
|
239
|
+
const addJsLineCoverage = (state, range) => {
|
|
240
|
+
|
|
241
|
+
const { locator, coverageInfo } = state;
|
|
242
|
+
|
|
243
|
+
const { data, lineMap } = coverageInfo;
|
|
244
|
+
|
|
245
|
+
const {
|
|
246
|
+
startOffset, endOffset, count
|
|
247
|
+
} = range;
|
|
248
|
+
|
|
249
|
+
// add bytes range
|
|
250
|
+
data.bytes.push({
|
|
251
|
+
// index,
|
|
252
|
+
start: startOffset,
|
|
253
|
+
end: endOffset,
|
|
254
|
+
count
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
updateLineCoverage(startOffset, endOffset, count, lineMap, locator);
|
|
254
258
|
|
|
255
259
|
};
|
|
256
260
|
|
|
@@ -264,28 +268,11 @@ const addCssLineCoverage = (state, range) => {
|
|
|
264
268
|
start, end, count
|
|
265
269
|
} = range;
|
|
266
270
|
|
|
267
|
-
if (count > 0) {
|
|
268
|
-
const sLoc = locator.offsetToLocation(start);
|
|
269
|
-
const eLoc = locator.offsetToLocation(end);
|
|
270
|
-
|
|
271
|
-
// covered css lines
|
|
272
|
-
const lines = Util.getRangeLines(sLoc, eLoc);
|
|
273
|
-
lines.forEach((it) => {
|
|
274
|
-
if (!it.entire) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
const line = lineMap.get(it.line);
|
|
278
|
-
if (line) {
|
|
279
|
-
// default is uncovered
|
|
280
|
-
// count always 1, covered is certain
|
|
281
|
-
line.covered = true;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
271
|
// add bytes range
|
|
287
272
|
data.bytes.push(range);
|
|
288
273
|
|
|
274
|
+
updateLineCoverage(start, end, count, lineMap, locator);
|
|
275
|
+
|
|
289
276
|
};
|
|
290
277
|
|
|
291
278
|
// ========================================================================================================
|
|
@@ -406,9 +393,7 @@ const handleBranchesCoverage = (state) => {
|
|
|
406
393
|
|
|
407
394
|
const handleLinesCoverage = (state) => {
|
|
408
395
|
|
|
409
|
-
const {
|
|
410
|
-
js, locator, coverageInfo
|
|
411
|
-
} = state;
|
|
396
|
+
const { locator, coverageInfo } = state;
|
|
412
397
|
|
|
413
398
|
const lines = coverageInfo.lines;
|
|
414
399
|
const lineMap = coverageInfo.lineMap;
|
|
@@ -417,10 +402,6 @@ const handleLinesCoverage = (state) => {
|
|
|
417
402
|
let blankCount = 0;
|
|
418
403
|
let commentCount = 0;
|
|
419
404
|
|
|
420
|
-
// js: 1 (functions include all uncovered)
|
|
421
|
-
// css: 0 (ranges include all covered)
|
|
422
|
-
const baseLineCount = js ? 1 : 0;
|
|
423
|
-
|
|
424
405
|
locator.lines.forEach((it) => {
|
|
425
406
|
// exclude blank and comment
|
|
426
407
|
if (it.blank) {
|
|
@@ -433,7 +414,8 @@ const handleLinesCoverage = (state) => {
|
|
|
433
414
|
}
|
|
434
415
|
// line 1-base
|
|
435
416
|
const line = it.line + 1;
|
|
436
|
-
|
|
417
|
+
// default count to 1, both js and css
|
|
418
|
+
const lineInfo = new InfoLine(line, it.length, 1);
|
|
437
419
|
lineMap.set(line, lineInfo);
|
|
438
420
|
lines.push(lineInfo);
|
|
439
421
|
});
|
package/lib/generate.js
CHANGED
|
@@ -216,6 +216,8 @@ const showConsoleSummary = (coverageResults, options) => {
|
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
const { metrics } = consoleOptions;
|
|
220
|
+
|
|
219
221
|
const {
|
|
220
222
|
summary, name, type
|
|
221
223
|
} = coverageResults;
|
|
@@ -223,12 +225,19 @@ const showConsoleSummary = (coverageResults, options) => {
|
|
|
223
225
|
EC.logCyan(name);
|
|
224
226
|
}
|
|
225
227
|
|
|
226
|
-
const
|
|
228
|
+
const allMetrics = {
|
|
227
229
|
v8: ['bytes', 'functions', 'branches', 'lines'],
|
|
228
230
|
istanbul: ['statements', 'functions', 'branches', 'lines']
|
|
229
231
|
};
|
|
230
232
|
|
|
231
|
-
|
|
233
|
+
let list = allMetrics[type];
|
|
234
|
+
if (Util.isList(metrics)) {
|
|
235
|
+
const newList = list.filter((k) => metrics.includes(k));
|
|
236
|
+
if (newList.length) {
|
|
237
|
+
list = newList;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
232
241
|
const rows = list.map((k) => {
|
|
233
242
|
return {
|
|
234
243
|
... summary[k],
|
package/lib/index.d.ts
CHANGED
|
@@ -23,12 +23,15 @@ export type ReportDescription =
|
|
|
23
23
|
['v8'] | ["v8", {
|
|
24
24
|
outputFile?: string,
|
|
25
25
|
inline?: boolean,
|
|
26
|
-
assetsPath?: string
|
|
26
|
+
assetsPath?: string,
|
|
27
|
+
metrics?: Array<"bytes" | "functions" | "branches" | "lines">
|
|
27
28
|
}] |
|
|
28
29
|
['v8-json'] | ["v8-json", {
|
|
29
30
|
outputFile?: string
|
|
30
31
|
}] |
|
|
31
|
-
['console-summary'] |
|
|
32
|
+
['console-summary'] | ['console-summary', {
|
|
33
|
+
metrics?: Array<"bytes" | "functions" | "branches" | "lines" | "statements">
|
|
34
|
+
}] |
|
|
32
35
|
['clover'] | ['clover', {
|
|
33
36
|
file?: string
|
|
34
37
|
}] |
|