monocart-coverage-reports 2.8.1 → 2.8.3

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
@@ -21,7 +21,7 @@
21
21
  - [Collecting V8 Coverage Data from Node.js](#collecting-v8-coverage-data-from-nodejs)
22
22
  - [Collecting V8 Coverage Data with `CDPClient` API](#collecting-v8-coverage-data-with-cdpclient-api)
23
23
  - [V8 Coverage Data API](#v8-coverage-data-api)
24
- * [Using `entryFilter` and `sourceFilter` to filter the results for V8 report](#using-entryfilter-and-sourcefilter-to-filter-the-results-for-v8-report)
24
+ * [Filtering Results](#filtering-results)
25
25
  * [Resolve `sourcePath` for the Source Files](#resolve-sourcepath-for-the-source-files)
26
26
  * [Adding Empty Coverage for Untested Files](#adding-empty-coverage-for-untested-files)
27
27
  * [onEnd Hook](#onend-hook)
@@ -53,6 +53,7 @@
53
53
  - [ts-node](#ts-node)
54
54
  - [AVA](#ava)
55
55
  - [Codecov](#codecov)
56
+ - [Codacy](#codacy)
56
57
  - [Coveralls](#coveralls)
57
58
  - [Sonar Cloud](#sonar-cloud)
58
59
  * [Contributing](#contributing)
@@ -467,7 +468,8 @@ export interface ScriptCoverage {
467
468
  export type V8CoverageData = ScriptCoverage[];
468
469
  ```
469
470
 
470
- ## Using `entryFilter` and `sourceFilter` to filter the results for V8 report
471
+ ## Filtering Results
472
+ ### Using `entryFilter` and `sourceFilter` to filter the results for V8 report
471
473
  When V8 coverage data collected, it actually contains the data of all entry files, for example:
472
474
 
473
475
  - *dist/main.js*
@@ -517,19 +519,33 @@ const coverageOptions = {
517
519
  }
518
520
  };
519
521
  ```
520
- In fact, the `minimatch` patterns will be transformed to a function like:
522
+ As CLI args (JSON-like string. Added in: v2.8):
523
+ ```sh
524
+ mcr --sourceFilter "{'**/node_modules/**':false,'**/**':true}"
525
+ ```
526
+ Note, those patterns will be transformed to a function, and the order of the patterns will impact the results:
521
527
  ```js
522
528
  const coverageOptions = {
523
- // '**/node_modules/**': false,
524
- // '**/vendor.js': false,
525
- // '**/src/**': true
526
529
  entryFilter: (entry) => {
527
530
  if (minimatch(entry.url, '**/node_modules/**')) { return false; }
528
531
  if (minimatch(entry.url, '**/vendor.js')) { return false; }
529
532
  if (minimatch(entry.url, '**/src/**')) { return true; }
530
533
  return false; // else unmatched
531
534
  }
532
- // Note, the order of the patterns will impact the results
535
+ };
536
+ ```
537
+
538
+ ### Using `filter` instead of `entryFilter` and `sourceFilter`
539
+ If you don't want to define both `entryFilter` and `sourceFilter`, you can use `filter` instead. (Added in: v2.8)
540
+ ```js
541
+ const coverageOptions = {
542
+ // combined patterns
543
+ filter: {
544
+ '**/node_modules/**': false,
545
+ '**/vendor.js': false,
546
+ '**/src/**': true
547
+ '**/**': true
548
+ }
533
549
  };
534
550
  ```
535
551
 
@@ -826,6 +842,7 @@ await new CoverageReport(coverageOptions).generate();
826
842
  }
827
843
  }
828
844
  ```
845
+ see example: [merge-code-coverage](https://github.com/cenfun/merge-code-coverage)
829
846
 
830
847
  ## Common issues
831
848
  ### Unexpected coverage
@@ -897,6 +914,7 @@ When `logging` is `debug`, the raw report data will be preserved in `[outputDir]
897
914
  - [playwright-coverage](https://github.com/cenfun/playwright-coverage) - Example for Playwright coverage reports
898
915
  - [playwright-bdd-coverage](https://github.com/cenfun/playwright-bdd-coverage) - Example for Playwright BDD coverage reports
899
916
  - [monocart-reporter](https://github.com/cenfun/monocart-reporter) - Playwright custom reporter, supports generating [Code coverage report](https://github.com/cenfun/monocart-reporter?#code-coverage-report)
917
+ - [merge-code-coverage](https://github.com/cenfun/merge-code-coverage) - Example for merging code coverage (unit + e2e shard)
900
918
  - Coverage for component testing with `monocart-reporter`:
901
919
  - [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue)
902
920
  - [playwright-ct-react](https://github.com/cenfun/playwright-ct-react)
@@ -969,13 +987,32 @@ const coverageOptions = {
969
987
  ]
970
988
  };
971
989
  ```
972
- - Github actions example:
990
+ - Github actions:
973
991
  ```yml
974
992
  - name: Codecov
975
993
  uses: codecov/codecov-action@v3
976
994
  with:
977
995
  files: ./coverage-reports/codecov.json
978
996
  ```
997
+
998
+ ### [Codacy](https://www.codacy.com/)
999
+ [![Codacy](https://app.codacy.com/project/badge/Coverage/715016ea8e90479db875b777db8bad55)](https://app.codacy.com/gh/cenfun/monocart-coverage-reports/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
1000
+ - Using `lcov` report:
1001
+ ```js
1002
+ const coverageOptions = {
1003
+ outputDir: "./coverage-reports",
1004
+ lcov: true
1005
+ };
1006
+ ```
1007
+ - Github actions:
1008
+ ```yml
1009
+ - name: Codacy Coverage Reporter
1010
+ uses: codacy/codacy-coverage-reporter-action@v1
1011
+ with:
1012
+ project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
1013
+ coverage-reports: ./docs/mcr/lcov.info
1014
+ ```
1015
+
979
1016
  ### [Coveralls](https://coveralls.io/)
980
1017
  [![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)
981
1018
  - Using `lcov` report:
@@ -985,13 +1022,14 @@ const coverageOptions = {
985
1022
  lcov: true
986
1023
  };
987
1024
  ```
988
- - Github actions example:
1025
+ - Github actions:
989
1026
  ```yml
990
1027
  - name: Coveralls
991
1028
  uses: coverallsapp/github-action@v2
992
1029
  with:
993
1030
  files: ./coverage-reports/lcov.info
994
1031
  ```
1032
+
995
1033
  ### [Sonar Cloud](https://sonarcloud.io/)
996
1034
  [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=monocart-coverage-reports&metric=coverage)](https://sonarcloud.io/summary/new_code?id=monocart-coverage-reports)
997
1035
  - Using `lcov` report. Github actions example:
@@ -1013,8 +1051,9 @@ const coverageOptions = {
1013
1051
  ```
1014
1052
 
1015
1053
  ## Contributing
1054
+ - Node.js 20+
1055
+ - VSCode (extensions: eslint/stylelint/vue)
1016
1056
  ```sh
1017
- # Node.js 20+
1018
1057
  npm install starfall-cli -g
1019
1058
  npm install
1020
1059
 
package/README.zh-Hans.md CHANGED
@@ -21,7 +21,7 @@
21
21
  - [从Node.js](#collecting-v8-coverage-data-from-nodejs)
22
22
  - [使用`CDPClient`API](#collecting-v8-coverage-data-with-cdpclient-api)
23
23
  - [参考V8覆盖率的API](#v8-coverage-data-api)
24
- * [使用 `entryFilter` 和 `sourceFilter` 来过滤V8覆盖率数据](#using-entryfilter-and-sourcefilter-to-filter-the-results-for-v8-report)
24
+ * [过滤V8覆盖率数据](#filtering-results)
25
25
  * [使用 `sourcePath` 修改源文件路径](#resolve-sourcepath-for-the-source-files)
26
26
  * [为未测试的文件添加空的覆盖率报告](#adding-empty-coverage-for-untested-files)
27
27
  * [onEnd回调函数](#onend-hook)
@@ -53,6 +53,7 @@
53
53
  - [ts-node](#ts-node)
54
54
  - [AVA](#ava)
55
55
  - [Codecov](#codecov)
56
+ - [Codacy](#codacy)
56
57
  - [Coveralls](#coveralls)
57
58
  - [Sonar Cloud](#sonar-cloud)
58
59
  * [Contributing](#contributing)
@@ -471,6 +472,7 @@ export interface ScriptCoverage {
471
472
  export type V8CoverageData = ScriptCoverage[];
472
473
  ```
473
474
 
475
+ ## Filtering Results
474
476
  ## Using `entryFilter` and `sourceFilter` to filter the results for V8 report
475
477
  当收集到V8的覆盖数据时,它实际上包含了所有的入口文件的覆盖率数据, 比如有以下3个文件:
476
478
 
@@ -521,19 +523,33 @@ const coverageOptions = {
521
523
  }
522
524
  };
523
525
  ```
524
- 这些`minimatch`匹配的运行逻辑,大概相当于:
526
+ 作为CLI参数(JSON字符串,Added in: v2.8):
527
+ ```sh
528
+ mcr --sourceFilter "{'**/node_modules/**':false,'**/**':true}"
529
+ ```
530
+ 注意,这些匹配实际上会转换成一个过滤函数(如下),所以如果一个匹配成功则会直接返回,后面的将不再继续匹配。请注意先后顺序,如果存在包含关系的,可以调整上下顺序,最后如果都未匹配,则默认返回false
525
531
  ```js
526
532
  const coverageOptions = {
527
- // '**/node_modules/**': false,
528
- // '**/vendor.js': false,
529
- // '**/src/**': true
530
533
  entryFilter: (entry) => {
531
534
  if (minimatch(entry.url, '**/node_modules/**')) { return false; }
532
535
  if (minimatch(entry.url, '**/vendor.js')) { return false; }
533
536
  if (minimatch(entry.url, '**/src/**')) { return true; }
534
537
  return false; // else unmatched
535
538
  }
536
- // 注意,前面的如果已经匹配到会直接返回,后面的不会继续匹配,所以如果存在包含关系的,需要注意每个匹配的上下顺序,最后如果都未匹配,则默认返回false
539
+ };
540
+ ```
541
+
542
+ ### Using `filter` instead of `entryFilter` and `sourceFilter`
543
+ 如果你不想定义两个过滤器,可以使用 `filter` 选项代替,可以将多个匹配合并在一起. (Added in: v2.8)
544
+ ```js
545
+ const coverageOptions = {
546
+ // combined patterns
547
+ filter: {
548
+ '**/node_modules/**': false,
549
+ '**/vendor.js': false,
550
+ '**/src/**': true
551
+ '**/**': true
552
+ }
537
553
  };
538
554
  ```
539
555
 
@@ -828,6 +844,7 @@ await new CoverageReport(coverageOptions).generate();
828
844
  }
829
845
  }
830
846
  ```
847
+ 参见例子: [merge-code-coverage](https://github.com/cenfun/merge-code-coverage)
831
848
 
832
849
  ## Common issues
833
850
  > 常见问题
@@ -901,6 +918,7 @@ const coverageOptions = {
901
918
  - [playwright-coverage](https://github.com/cenfun/playwright-coverage) - Example for Playwright coverage reports
902
919
  - [playwright-bdd-coverage](https://github.com/cenfun/playwright-bdd-coverage) - Example for Playwright BDD coverage reports
903
920
  - [monocart-reporter](https://github.com/cenfun/monocart-reporter) - Playwright custom reporter, supports generating [Code coverage report](https://github.com/cenfun/monocart-reporter?#code-coverage-report)
921
+ - [merge-code-coverage](https://github.com/cenfun/merge-code-coverage) - Example for merging code coverage (unit + e2e shard)
904
922
  - Coverage for component testing with `monocart-reporter`:
905
923
  - [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue)
906
924
  - [playwright-ct-react](https://github.com/cenfun/playwright-ct-react)
@@ -980,6 +998,25 @@ const coverageOptions = {
980
998
  with:
981
999
  files: ./coverage-reports/codecov.json
982
1000
  ```
1001
+
1002
+ ### [Codacy](https://www.codacy.com/)
1003
+ [![Codacy](https://app.codacy.com/project/badge/Coverage/715016ea8e90479db875b777db8bad55)](https://app.codacy.com/gh/cenfun/monocart-coverage-reports/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
1004
+ - Using `lcov` report:
1005
+ ```js
1006
+ const coverageOptions = {
1007
+ outputDir: "./coverage-reports",
1008
+ lcov: true
1009
+ };
1010
+ ```
1011
+ - Github actions:
1012
+ ```yml
1013
+ - name: Codacy Coverage Reporter
1014
+ uses: codacy/codacy-coverage-reporter-action@v1
1015
+ with:
1016
+ project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
1017
+ coverage-reports: ./docs/mcr/lcov.info
1018
+ ```
1019
+
983
1020
  ### [Coveralls](https://coveralls.io/)
984
1021
  [![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)
985
1022
  - Using `lcov` report:
@@ -996,6 +1033,7 @@ const coverageOptions = {
996
1033
  with:
997
1034
  files: ./coverage-reports/lcov.info
998
1035
  ```
1036
+
999
1037
  ### [Sonar Cloud](https://sonarcloud.io/)
1000
1038
  [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=monocart-coverage-reports&metric=coverage)](https://sonarcloud.io/summary/new_code?id=monocart-coverage-reports)
1001
1039
  - Using `lcov` report. Github actions example:
@@ -1017,8 +1055,9 @@ const coverageOptions = {
1017
1055
  ```
1018
1056
 
1019
1057
  ## Contributing
1058
+ - Node.js 20+
1059
+ - VSCode (extensions: eslint/stylelint/vue)
1020
1060
  ```sh
1021
- # Node.js 20+
1022
1061
  npm install starfall-cli -g
1023
1062
  npm install
1024
1063
 
package/lib/cli.js CHANGED
@@ -6,7 +6,7 @@ const EC = require('eight-colors');
6
6
  const {
7
7
  foregroundChild,
8
8
  program
9
- } = require('./packages/monocart-coverage-vendor.js');
9
+ } = require('./packages/monocart-coverage-cli.js');
10
10
 
11
11
  const MCR = require('./index.js');
12
12
  const Util = require('./utils/util.js');