monocart-coverage-reports 2.5.0 → 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
@@ -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/index.d.ts CHANGED
@@ -237,6 +237,9 @@ declare namespace MCR {
237
237
  * {object} { bytes:[50,80], statements:[50,80], branches:[50,80], functions:[50,80], lines:[50,80] } */
238
238
  watermarks?: Watermarks;
239
239
 
240
+ /** {boolean} clean previous files in output dir before generating report. Defaults to true. */
241
+ clean?: boolean;
242
+
240
243
  /** {function} onEnd hook */
241
244
  onEnd?: (reportData: CoverageResults) => Promise<void>;
242
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {