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 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) - Playwright, Jest, Vitest, Codecov, Coveralls, Sonar Cloud
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
- - `v8` (V8 data only)
60
- - Test in browser
61
- - Build with webpack: [V8](https://cenfun.github.io/monocart-coverage-reports/v8) and [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify)
62
- - Build with [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild)
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
  ![](test/v8.gif)
70
72
 
71
- - `v8-json` (V8 data only)
73
+ - `v8-json`
72
74
  - [V8 coverage-report.json](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json)
73
- - `codecov` (V8 data only)
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
- > Istanbul [build-in reports](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
79
+ ![](test/console-details.png)
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
  ![](test/console-summary.png)
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
  ![](./test/debug-sourcemap.png)
646
653
 
647
654
  ## Integration
648
- - [monocart-reporter](https://github.com/cenfun/monocart-reporter) - A [Playwright](https://github.com/microsoft/playwright) custom reporter, supports generating [Code Coverage Report](https://github.com/cenfun/monocart-reporter?#code-coverage-report)
649
- - [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - A [Jest](https://github.com/jestjs/jest/) custom reporter for coverage reports
650
- - [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - A [Vitest](https://github.com/vitest-dev/vitest) custom provider module for coverage reports
651
- - [Codecov](https://codecov.com/)
652
- - [![codecov](https://codecov.io/gh/cenfun/monocart-coverage-reports/graph/badge.svg?token=H0LW7UKYU3)](https://codecov.io/gh/cenfun/monocart-coverage-reports)
653
- - Supports native `codecov` built-in report ([specification](https://docs.codecov.com/docs/codecov-custom-coverage-format))
654
- ```js
655
- const coverageOptions = {
656
- outputDir: "./coverage-reports",
657
- reports: [
658
- ['codecov']
659
- ]
660
- };
661
- ```
662
- - Github Actions example:
663
- ```yml
664
- - name: Codecov
665
- uses: codecov/codecov-action@v3
666
- with:
667
- files: ./coverage-reports/codecov.json
668
- ```
669
- - [Coveralls](https://coveralls.io/)
670
- - [![Coverage Status](https://coveralls.io/repos/github/cenfun/monocart-coverage-reports/badge.svg?branch=main)](https://coveralls.io/github/cenfun/monocart-coverage-reports?branch=main)
671
- ```js
672
- const coverageOptions = {
673
- outputDir: "./coverage-reports",
674
- lcov: true
675
- };
676
- ```
677
- - Github Actions example:
678
- ```yml
679
- - name: Coveralls
680
- uses: coverallsapp/github-action@v2
681
- with:
682
- files: ./coverage-reports/lcov.info
683
- ```
684
- - [Sonar Cloud](https://sonarcloud.io/)
685
- - [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=monocart-coverage-reports&metric=coverage)](https://sonarcloud.io/summary/new_code?id=monocart-coverage-reports)
686
- - Github Actions example:
687
- ```yml
688
- - name: Analyze with SonarCloud
689
- uses: sonarsource/sonarcloud-github-action@master
690
- env:
691
- SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
692
- with:
693
- projectBaseDir: ./
694
- args: >
695
- -Dsonar.organization=cenfun
696
- -Dsonar.projectKey=monocart-coverage-reports
697
- -Dsonar.projectName=monocart-coverage-reports
698
- -Dsonar.javascript.lcov.reportPaths=docs/mcr/lcov.info
699
- -Dsonar.sources=lib
700
- -Dsonar.tests=test
701
- -Dsonar.exclusions=dist/*,packages/*
702
- ```
703
- - Integration with any testing framework
704
- - First, you need to collect coverage data when any stage of the test is completed. Then, add the coverage data to the coverage report.
705
- - Upon the completion of all tests, generate the coverage report.
706
- - see [Multiprocessing Support](#multiprocessing-support)
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
+ [![codecov](https://codecov.io/gh/cenfun/monocart-coverage-reports/graph/badge.svg?token=H0LW7UKYU3)](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
+ [![Coverage Status](https://coveralls.io/repos/github/cenfun/monocart-coverage-reports/badge.svg?branch=main)](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
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=monocart-coverage-reports&metric=coverage)](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)
@@ -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
- const p = Util.PSF(v, 100, 2);
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 showConsoleSummary = (reportData, reportOptions, options) => {
144
+ const handleConsoleSummaryReport = (reportData, reportOptions, options) => {
157
145
 
158
- const { metrics } = reportOptions;
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 allMetrics = {
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 = list.map((k) => {
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 saveRawReport = (reportData, reportOptions, options) => {
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': showConsoleSummary,
289
- 'raw': saveRawReport
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
- // if assets dir is out of output dir will be ignore
116
- fs.readdirSync(outputDir).forEach((itemName) => {
117
- if (itemName === this.cacheDirName) {
118
- return;
119
- }
120
- Util.rmSync(path.resolve(outputDir, itemName));
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