monocart-coverage-reports 2.4.4 → 2.5.1
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 +85 -74
- package/lib/default/options.js +3 -0
- package/lib/generate.js +13 -33
- package/lib/index.d.ts +8 -0
- package/lib/index.js +9 -7
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/platform/share.js +18 -59
- package/lib/utils/util.js +13 -0
- package/lib/v8/v8.js +214 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,7 +33,14 @@
|
|
|
33
33
|
- [Using `v8-to-istanbul`](#using-v8-to-istanbul)
|
|
34
34
|
- [How Monocart Works](#how-monocart-works)
|
|
35
35
|
* [Debug for Coverage and Sourcemap](#debug-for-coverage-and-sourcemap)
|
|
36
|
-
* [Integration](#integration)
|
|
36
|
+
* [Integration](#integration)
|
|
37
|
+
- [Playwright](#playwright)
|
|
38
|
+
- [Jest](#jest)
|
|
39
|
+
- [Vitest](#vitest)
|
|
40
|
+
- [Codecov](#codecov)
|
|
41
|
+
- [Coveralls](#coveralls)
|
|
42
|
+
- [Sonar Cloud](#sonar-cloud)
|
|
43
|
+
- [Integration with Any Testing Framework](#integration-with-any-testing-framework)
|
|
37
44
|
* [Thanks](#thanks)
|
|
38
45
|
|
|
39
46
|
## Usage
|
|
@@ -56,24 +63,22 @@ console.log(coverageResults.summary);
|
|
|
56
63
|
- [lib/default/options.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/lib/default/options.js)
|
|
57
64
|
|
|
58
65
|
## Available Reports
|
|
59
|
-
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
- Collect with [puppeteer](https://cenfun.github.io/monocart-coverage-reports/puppeteer/)
|
|
64
|
-
- [anonymous](https://cenfun.github.io/monocart-coverage-reports/anonymous/) and [css](https://cenfun.github.io/monocart-coverage-reports/css/)
|
|
65
|
-
- Test in Node.js
|
|
66
|
-
- Collect with [env](https://cenfun.github.io/monocart-coverage-reports/v8-node-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)
|
|
67
|
-
- Web server example: [koa](https://cenfun.github.io/monocart-coverage-reports/v8-node-koa/)
|
|
66
|
+
> V8 build-in reports (V8 data only):
|
|
67
|
+
- `v8`
|
|
68
|
+
- Browser: Build with webpack [V8](https://cenfun.github.io/monocart-coverage-reports/v8) and [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify); Build with [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild); Collect with [puppeteer](https://cenfun.github.io/monocart-coverage-reports/puppeteer/); [anonymous](https://cenfun.github.io/monocart-coverage-reports/anonymous/) and [css](https://cenfun.github.io/monocart-coverage-reports/css/)
|
|
69
|
+
- Node.js: Collect with [env](https://cenfun.github.io/monocart-coverage-reports/v8-node-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); Web server example: [koa](https://cenfun.github.io/monocart-coverage-reports/v8-node-koa/)
|
|
68
70
|
|
|
69
71
|

|
|
70
72
|
|
|
71
|
-
- `v8-json`
|
|
73
|
+
- `v8-json`
|
|
72
74
|
- [V8 coverage-report.json](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json)
|
|
73
|
-
- `codecov`
|
|
75
|
+
- `codecov`
|
|
74
76
|
- coverage data for [Codecov](https://docs.codecov.com/docs/codecov-custom-coverage-format), see [example](https://app.codecov.io/github/cenfun/monocart-coverage-reports)
|
|
77
|
+
- `console-details` Show file coverage and uncovered lines in the console. Like `text`, but for V8.
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+

|
|
80
|
+
|
|
81
|
+
> Istanbul build-in reports (both V8 and istanbul data):
|
|
77
82
|
- `clover`
|
|
78
83
|
- `cobertura`
|
|
79
84
|
- `html`
|
|
@@ -93,9 +98,11 @@ console.log(coverageResults.summary);
|
|
|
93
98
|
- `text-lcov`
|
|
94
99
|
- `text-summary`
|
|
95
100
|
|
|
96
|
-
> Other reports
|
|
97
|
-
- `console-summary` shows coverage summary in console
|
|
101
|
+
> Other reports:
|
|
102
|
+
- `console-summary` shows coverage summary in the console
|
|
103
|
+
|
|
98
104
|

|
|
105
|
+
|
|
99
106
|
- `raw` only keep all original data, which can be used for other reports input with `inputDir`
|
|
100
107
|
- see [Merge Coverage Reports](#merge-coverage-reports)
|
|
101
108
|
|
|
@@ -645,65 +652,69 @@ When `logging` is `debug`, the raw report data will be preserved in `[outputDir]
|
|
|
645
652
|

|
|
646
653
|
|
|
647
654
|
## Integration
|
|
648
|
-
|
|
649
|
-
- [
|
|
650
|
-
|
|
651
|
-
- [
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
655
|
+
### [Playwright](https://github.com/microsoft/playwright)
|
|
656
|
+
- [monocart-reporter](https://github.com/cenfun/monocart-reporter) - A Playwright custom reporter, supports generating [Code Coverage Report](https://github.com/cenfun/monocart-reporter?#code-coverage-report)
|
|
657
|
+
### [Jest](https://github.com/jestjs/jest/)
|
|
658
|
+
- [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - A Jest custom reporter for coverage reports
|
|
659
|
+
### [Vitest](https://github.com/vitest-dev/vitest)
|
|
660
|
+
- [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - A Vitest custom provider module for coverage reports
|
|
661
|
+
### [Codecov](https://codecov.com/)
|
|
662
|
+
[](https://codecov.io/gh/cenfun/monocart-coverage-reports)
|
|
663
|
+
- Supports native `codecov` built-in report ([specification](https://docs.codecov.com/docs/codecov-custom-coverage-format))
|
|
664
|
+
```js
|
|
665
|
+
const coverageOptions = {
|
|
666
|
+
outputDir: "./coverage-reports",
|
|
667
|
+
reports: [
|
|
668
|
+
['codecov']
|
|
669
|
+
]
|
|
670
|
+
};
|
|
671
|
+
```
|
|
672
|
+
- Github actions example:
|
|
673
|
+
```yml
|
|
674
|
+
- name: Codecov
|
|
675
|
+
uses: codecov/codecov-action@v3
|
|
676
|
+
with:
|
|
677
|
+
files: ./coverage-reports/codecov.json
|
|
678
|
+
```
|
|
679
|
+
### [Coveralls](https://coveralls.io/)
|
|
680
|
+
[](https://coveralls.io/github/cenfun/monocart-coverage-reports?branch=main)
|
|
681
|
+
- Using `lcov` report:
|
|
682
|
+
```js
|
|
683
|
+
const coverageOptions = {
|
|
684
|
+
outputDir: "./coverage-reports",
|
|
685
|
+
lcov: true
|
|
686
|
+
};
|
|
687
|
+
```
|
|
688
|
+
- Github actions example:
|
|
689
|
+
```yml
|
|
690
|
+
- name: Coveralls
|
|
691
|
+
uses: coverallsapp/github-action@v2
|
|
692
|
+
with:
|
|
693
|
+
files: ./coverage-reports/lcov.info
|
|
694
|
+
```
|
|
695
|
+
### [Sonar Cloud](https://sonarcloud.io/)
|
|
696
|
+
[](https://sonarcloud.io/summary/new_code?id=monocart-coverage-reports)
|
|
697
|
+
- Using `lcov` report. Github actions example:
|
|
698
|
+
```yml
|
|
699
|
+
- name: Analyze with SonarCloud
|
|
700
|
+
uses: sonarsource/sonarcloud-github-action@master
|
|
701
|
+
env:
|
|
702
|
+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
703
|
+
with:
|
|
704
|
+
projectBaseDir: ./
|
|
705
|
+
args: >
|
|
706
|
+
-Dsonar.organization=cenfun
|
|
707
|
+
-Dsonar.projectKey=monocart-coverage-reports
|
|
708
|
+
-Dsonar.projectName=monocart-coverage-reports
|
|
709
|
+
-Dsonar.javascript.lcov.reportPaths=docs/mcr/lcov.info
|
|
710
|
+
-Dsonar.sources=lib
|
|
711
|
+
-Dsonar.tests=test
|
|
712
|
+
-Dsonar.exclusions=dist/*,packages/*
|
|
713
|
+
```
|
|
714
|
+
### Integration with Any Testing Framework
|
|
715
|
+
- Collecting coverage data when any stage of the test is completed, and adding the coverage data to the coverage reporter.
|
|
716
|
+
- Generating the coverage reports after the completion of all tests.
|
|
717
|
+
- see [Multiprocessing Support](#multiprocessing-support)
|
|
707
718
|
|
|
708
719
|
## Thanks
|
|
709
720
|
- Special thanks to [@edumserrano](https://github.com/edumserrano)
|
package/lib/default/options.js
CHANGED
|
@@ -65,6 +65,9 @@ module.exports = {
|
|
|
65
65
|
// {object} { bytes:[50,80], statements:[50,80], branches:[50,80], functions:[50,80], lines:[50,80] }
|
|
66
66
|
watermarks: [50, 80],
|
|
67
67
|
|
|
68
|
+
// {boolean} clean previous files in output dir before generating report. Defaults to true.
|
|
69
|
+
clean: true,
|
|
70
|
+
|
|
68
71
|
// {function} onEnd hook
|
|
69
72
|
// onEnd: async (reportData) => {}
|
|
70
73
|
onEnd: null
|
package/lib/generate.js
CHANGED
|
@@ -72,6 +72,7 @@ const getReportGroup = (reports, lcov, dataType) => {
|
|
|
72
72
|
'v8': 'v8',
|
|
73
73
|
'v8-json': 'v8',
|
|
74
74
|
'codecov': 'v8',
|
|
75
|
+
'console-details': 'v8',
|
|
75
76
|
|
|
76
77
|
// istanbul
|
|
77
78
|
'clover': 'istanbul',
|
|
@@ -126,22 +127,9 @@ const getReportGroup = (reports, lcov, dataType) => {
|
|
|
126
127
|
|
|
127
128
|
// ========================================================================================================
|
|
128
129
|
|
|
129
|
-
const capitalizeFirstLetter = (string) => {
|
|
130
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
130
|
const pFormatter = (v, row, column) => {
|
|
134
131
|
if (typeof v === 'number') {
|
|
135
|
-
|
|
136
|
-
if (row.status === 'low') {
|
|
137
|
-
return EC.red(p);
|
|
138
|
-
}
|
|
139
|
-
if (row.status === 'medium') {
|
|
140
|
-
return EC.yellow(p);
|
|
141
|
-
}
|
|
142
|
-
if (row.status === 'high') {
|
|
143
|
-
return EC.green(p);
|
|
144
|
-
}
|
|
132
|
+
return Util.getColorStrByStatus(Util.PSF(v, 100, 2), row.status);
|
|
145
133
|
}
|
|
146
134
|
return v;
|
|
147
135
|
};
|
|
@@ -153,9 +141,12 @@ const nFormatter = (v) => {
|
|
|
153
141
|
return v;
|
|
154
142
|
};
|
|
155
143
|
|
|
156
|
-
const
|
|
144
|
+
const handleConsoleSummaryReport = (reportData, reportOptions, options) => {
|
|
157
145
|
|
|
158
|
-
const
|
|
146
|
+
const csOptions = {
|
|
147
|
+
metrics: [],
|
|
148
|
+
... reportOptions
|
|
149
|
+
};
|
|
159
150
|
|
|
160
151
|
const {
|
|
161
152
|
summary, name, type
|
|
@@ -165,23 +156,12 @@ const showConsoleSummary = (reportData, reportOptions, options) => {
|
|
|
165
156
|
EC.logCyan(name);
|
|
166
157
|
}
|
|
167
158
|
|
|
168
|
-
const
|
|
169
|
-
v8: ['bytes', 'statements', 'branches', 'functions', 'lines'],
|
|
170
|
-
istanbul: ['statements', 'branches', 'functions', 'lines']
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
let list = allMetrics[type];
|
|
174
|
-
if (Util.isList(metrics)) {
|
|
175
|
-
const newList = list.filter((k) => metrics.includes(k));
|
|
176
|
-
if (newList.length) {
|
|
177
|
-
list = newList;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
159
|
+
const metrics = Util.getMetrics(type, csOptions.metrics);
|
|
180
160
|
|
|
181
|
-
const rows =
|
|
161
|
+
const rows = metrics.map((k) => {
|
|
182
162
|
return {
|
|
183
163
|
... summary[k],
|
|
184
|
-
name: capitalizeFirstLetter(k)
|
|
164
|
+
name: Util.capitalizeFirstLetter(k)
|
|
185
165
|
};
|
|
186
166
|
});
|
|
187
167
|
|
|
@@ -216,7 +196,7 @@ const showConsoleSummary = (reportData, reportOptions, options) => {
|
|
|
216
196
|
});
|
|
217
197
|
};
|
|
218
198
|
|
|
219
|
-
const
|
|
199
|
+
const handleRawReport = (reportData, reportOptions, options) => {
|
|
220
200
|
const rawOptions = {
|
|
221
201
|
outputDir: 'raw',
|
|
222
202
|
... reportOptions
|
|
@@ -285,8 +265,8 @@ const generateCoverageReports = async (dataList, sourceCache, options) => {
|
|
|
285
265
|
// console.log(Object.keys(coverageResults));
|
|
286
266
|
|
|
287
267
|
const buildInBothReports = {
|
|
288
|
-
'console-summary':
|
|
289
|
-
'raw':
|
|
268
|
+
'console-summary': handleConsoleSummaryReport,
|
|
269
|
+
'raw': handleRawReport
|
|
290
270
|
};
|
|
291
271
|
|
|
292
272
|
const bothGroup = options.reportGroup.both;
|
package/lib/index.d.ts
CHANGED
|
@@ -36,6 +36,11 @@ declare namespace MCR {
|
|
|
36
36
|
['codecov'] | ["codecov", {
|
|
37
37
|
outputFile?: string;
|
|
38
38
|
}] |
|
|
39
|
+
['console-details'] | ['console-details', {
|
|
40
|
+
maxCols?: number;
|
|
41
|
+
skipPercent?: number;
|
|
42
|
+
metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">;
|
|
43
|
+
}] |
|
|
39
44
|
['clover'] | ['clover', {
|
|
40
45
|
file?: string;
|
|
41
46
|
}] |
|
|
@@ -232,6 +237,9 @@ declare namespace MCR {
|
|
|
232
237
|
* {object} { bytes:[50,80], statements:[50,80], branches:[50,80], functions:[50,80], lines:[50,80] } */
|
|
233
238
|
watermarks?: Watermarks;
|
|
234
239
|
|
|
240
|
+
/** {boolean} clean previous files in output dir before generating report. Defaults to true. */
|
|
241
|
+
clean?: boolean;
|
|
242
|
+
|
|
235
243
|
/** {function} onEnd hook */
|
|
236
244
|
onEnd?: (reportData: CoverageResults) => Promise<void>;
|
|
237
245
|
}
|
package/lib/index.js
CHANGED
|
@@ -112,13 +112,15 @@ class CoverageReport {
|
|
|
112
112
|
const outputDir = this.options.outputDir;
|
|
113
113
|
|
|
114
114
|
if (fs.existsSync(outputDir)) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
// if assets dir is out of output dir will be ignore
|
|
116
|
+
if (this.options.clean) {
|
|
117
|
+
fs.readdirSync(outputDir).forEach((itemName) => {
|
|
118
|
+
if (itemName === this.cacheDirName) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
Util.rmSync(path.resolve(outputDir, itemName));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
122
124
|
} else {
|
|
123
125
|
fs.mkdirSync(outputDir, {
|
|
124
126
|
recursive: true
|