monocart-coverage-reports 2.0.5 → 2.0.6

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 CHANGED
@@ -6,12 +6,9 @@
6
6
 
7
7
  > Code coverage tool to generate native [V8](https://v8.dev/blog/javascript-code-coverage) reports or [Istanbul](https://istanbul.js.org/) reports.
8
8
 
9
- * [Preview Reports](#preview-reports)
10
9
  * [Usage](#usage)
11
10
  * [Default Options](#default-options)
12
- * [Multiple Reports](#multiple-reports)
13
- - [V8 reports](#v8-reports)
14
- - [Istanbul reports](#istanbul-reports)
11
+ * [Available Reports](#available-reports)
15
12
  * [Multiprocessing Support](#multiprocessing-support)
16
13
  * [Compare Reports](#compare-reports)
17
14
  * [Compare Workflows](#compare-workflows)
@@ -26,14 +23,6 @@
26
23
  * [Istanbul Introduction](#istanbul-introduction)
27
24
  * [Thanks](#thanks)
28
25
 
29
- ## Preview Reports
30
- - [V8](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)
31
- - [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)
32
- - [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify)
33
- - [V8 to Istanbul](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/istanbul)
34
- - [Istanbul](https://cenfun.github.io/monocart-coverage-reports/istanbul/)
35
- - [Integration with Monocart Reporter](https://cenfun.github.io/monocart-reporter/) - Playwright test report
36
-
37
26
  ## Usage
38
27
  ```js
39
28
  const CoverageReport = require('monocart-coverage-reports');
@@ -53,30 +42,13 @@ console.log(coverageResults.summary);
53
42
  ## Default Options
54
43
  - [lib/default/options.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/lib/default/options.js)
55
44
 
56
- ## Multiple Reports
57
- ### V8 reports
58
- - v8 (html)
59
- - v8-json
60
- ### [Istanbul reports](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
61
- - clover
62
- - cobertura
63
- - html
64
- - html-spa
65
- - json
66
- - json-summary
67
- - lcov
68
- - lcovonly
69
- - none
70
- - teamcity
71
- - text
72
- - text-lcov
73
- - text-summary
74
-
45
+ ## Available Reports
75
46
  ```js
76
47
  const CoverageReport = require('monocart-coverage-reports');
77
48
  const options = {
78
49
  outputDir: './coverage-reports',
79
50
  reports: [
51
+ ['console-summary'],
80
52
  ['v8'],
81
53
  ['html', {
82
54
  subdir: 'istanbul'
@@ -89,6 +61,43 @@ const options = {
89
61
  }
90
62
  const coverageReport = new CoverageReport(options);
91
63
  ```
64
+ - `v8` (V8 data only)
65
+ - [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
+ - [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)
67
+ - [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify)
68
+
69
+ ![](test/v8.gif)
70
+
71
+ - `v8-json` (V8 data only)
72
+ - [V8 coverage-report.json](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json)
73
+ - `console-summary` shows coverage summary in console
74
+
75
+ ![](test/console-summary.png)
76
+
77
+ > Following are [istanbul reports](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
78
+ - `clover`
79
+ - `cobertura`
80
+ - `html`
81
+ - [Istanbul html](https://cenfun.github.io/monocart-coverage-reports/istanbul/)
82
+ - [V8 to Istanbul](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/istanbul)
83
+ - `html-spa`
84
+ - [Istanbul html-spa](https://cenfun.github.io/monocart-coverage-reports/istanbul/html-spa/)
85
+ - `json`
86
+ - `json-summary`
87
+ - `lcov`
88
+ - `lcovonly`
89
+ - [V8 lcov.info](https://cenfun.github.io/monocart-coverage-reports/v8/lcov.info)
90
+ - [Istanbul lcov.info](https://cenfun.github.io/monocart-coverage-reports/istanbul/lcov.info)
91
+ - `none`
92
+ - `teamcity`
93
+ - `text`
94
+ - `text-lcov`
95
+ - `text-summary`
96
+
97
+ ## Integration
98
+ - [monocart-reporter](https://cenfun.github.io/monocart-reporter/) - Test reporter for [Playwright](https://github.com/microsoft/playwright)
99
+ - [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - Integration with [Vitest](https://github.com/vitest-dev/vitest) coverage
100
+
92
101
 
93
102
  ## Multiprocessing Support
94
103
  The data will be added to `[outputDir]/.cache`, and the cache will be removed after reports generated.
package/lib/generate.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
-
3
+ const CG = require('console-grid');
4
+ const EC = require('eight-colors');
4
5
  const Util = require('./utils/util.js');
5
6
  const {
6
7
  initIstanbulData, mergeIstanbulCoverage, saveIstanbulReports
@@ -72,6 +73,9 @@ const getReportGroup = (reports, lcov, dataType) => {
72
73
  'v8',
73
74
  'v8-json',
74
75
 
76
+ // both
77
+ 'console-summary',
78
+
75
79
  // istanbul
76
80
  'clover',
77
81
  'cobertura',
@@ -95,6 +99,7 @@ const getReportGroup = (reports, lcov, dataType) => {
95
99
  return;
96
100
  }
97
101
 
102
+ // v8
98
103
  if (k.startsWith('v8')) {
99
104
  // v8
100
105
  if (!reportGroup.v8) {
@@ -104,6 +109,12 @@ const getReportGroup = (reports, lcov, dataType) => {
104
109
  return;
105
110
  }
106
111
 
112
+ // both
113
+ if (k === 'console-summary') {
114
+ reportGroup[k] = reportMap[k];
115
+ return;
116
+ }
117
+
107
118
  // istanbul
108
119
  if (!reportGroup.istanbul) {
109
120
  reportGroup.istanbul = {};
@@ -114,6 +125,8 @@ const getReportGroup = (reports, lcov, dataType) => {
114
125
  return reportGroup;
115
126
  };
116
127
 
128
+ // ========================================================================================================
129
+
117
130
 
118
131
  const generateCoverageReports = async (dataList, options) => {
119
132
 
@@ -144,6 +157,8 @@ const generateCoverageReports = async (dataList, options) => {
144
157
 
145
158
  };
146
159
 
160
+ // ========================================================================================================
161
+
147
162
 
148
163
  const getCoverageDataList = async (cacheDir) => {
149
164
  const files = fs.readdirSync(cacheDir).filter((f) => f.startsWith('coverage-'));
@@ -164,8 +179,105 @@ const getCoverageDataList = async (cacheDir) => {
164
179
  }
165
180
  };
166
181
 
182
+ // ========================================================================================================
183
+
184
+ const capitalizeFirstLetter = (string) => {
185
+ return string.charAt(0).toUpperCase() + string.slice(1);
186
+ };
187
+
188
+ const pFormatter = (v, row, column) => {
189
+ if (typeof v === 'number') {
190
+ const p = Util.PSF(v, 100, 2);
191
+ if (row.status === 'low') {
192
+ return EC.red(p);
193
+ }
194
+ if (row.status === 'medium') {
195
+ return EC.yellow(p);
196
+ }
197
+ if (row.status === 'high') {
198
+ return EC.green(p);
199
+ }
200
+ }
201
+ return v;
202
+ };
203
+
204
+ const nFormatter = (v) => {
205
+ if (typeof v === 'number') {
206
+ return Util.NF(v);
207
+ }
208
+ return v;
209
+ };
210
+
211
+ const showConsoleSummary = (coverageResults, options) => {
212
+
213
+ const reportGroup = options.reportGroup;
214
+ const consoleOptions = reportGroup['console-summary'];
215
+ if (!consoleOptions) {
216
+ return;
217
+ }
218
+
219
+ const {
220
+ summary, name, type
221
+ } = coverageResults;
222
+ if (name) {
223
+ EC.logCyan(name);
224
+ }
225
+
226
+ const indicators = {
227
+ v8: ['bytes', 'functions', 'branches', 'lines'],
228
+ istanbul: ['statements', 'functions', 'branches', 'lines']
229
+ };
230
+
231
+ const list = indicators[type] || indicators.v8;
232
+ const rows = list.map((k) => {
233
+ return {
234
+ ... summary[k],
235
+ name: capitalizeFirstLetter(k)
236
+ };
237
+ });
238
+
239
+ const columns = [{
240
+ id: 'name',
241
+ name: 'Name'
242
+ }, {
243
+ id: 'pct',
244
+ name: 'Coverage %',
245
+ align: 'right',
246
+ formatter: pFormatter
247
+ }, {
248
+ id: 'covered',
249
+ name: 'Covered',
250
+ align: 'right',
251
+ formatter: nFormatter
252
+ }, {
253
+ id: 'uncovered',
254
+ name: 'Uncovered',
255
+ align: 'right',
256
+ formatter: nFormatter
257
+ }, {
258
+ id: 'total',
259
+ name: 'Total',
260
+ align: 'right',
261
+ formatter: nFormatter
262
+ }];
263
+
264
+ if (type === 'istanbul') {
265
+ columns.splice(4, 0, {
266
+ id: 'skipped',
267
+ name: 'Skipped',
268
+ align: 'right',
269
+ formatter: nFormatter
270
+ });
271
+ }
272
+
273
+ CG({
274
+ columns,
275
+ rows
276
+ });
277
+ };
167
278
 
168
279
  module.exports = {
169
280
  getCoverageDataList,
170
- generateCoverageReports
281
+ generateCoverageReports,
282
+ showConsoleSummary
171
283
  };
package/lib/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export type ReportDescription =
28
28
  ['v8-json'] | ["v8-json", {
29
29
  outputFile?: string
30
30
  }] |
31
+ ['console-summary'] |
31
32
  ['clover'] | ['clover', {
32
33
  file?: string
33
34
  }] |
package/lib/index.js CHANGED
@@ -4,7 +4,9 @@ const defaultOptions = require('./default/options.js');
4
4
  const Util = require('./utils/util.js');
5
5
 
6
6
  const { initV8ListAndSourcemap } = require('./v8/v8.js');
7
- const { getCoverageDataList, generateCoverageReports } = require('./generate.js');
7
+ const {
8
+ getCoverageDataList, generateCoverageReports, showConsoleSummary
9
+ } = require('./generate.js');
8
10
 
9
11
  class CoverageReport {
10
12
 
@@ -107,6 +109,8 @@ class CoverageReport {
107
109
  Util.rmSync(cacheDir);
108
110
  }
109
111
 
112
+ showConsoleSummary(coverageResults, this.options);
113
+
110
114
  const onEnd = this.options.onEnd;
111
115
  if (typeof onEnd === 'function') {
112
116
  await onEnd(coverageResults);
@@ -37,6 +37,19 @@ class IstanbulSummary extends ReportBase {
37
37
  }
38
38
 
39
39
  getReport() {
40
+
41
+ // remove branchesTrue
42
+ delete this.summary.branchesTrue;
43
+
44
+ // add uncovered
45
+ Object.keys(this.summary).forEach((id) => {
46
+ const item = this.summary[id];
47
+ // NOTE: skipped
48
+ item.uncovered = item.total - item.covered - item.skipped;
49
+ });
50
+
51
+ // console.log(this.summary);
52
+
40
53
  return {
41
54
  summary: this.summary,
42
55
  files: this.files
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "lib/index.js",
6
6
  "exports": {