monocart-coverage-reports 2.7.9 → 2.8.0

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,7 +6,9 @@
6
6
  ![](https://img.shields.io/github/license/cenfun/monocart-coverage-reports)
7
7
  ![](https://img.shields.io/github/actions/workflow/status/cenfun/monocart-coverage-reports/static.yml)
8
8
 
9
- > A code coverage tool to generate native [V8](https://v8.dev/blog/javascript-code-coverage) reports or [Istanbul](https://istanbul.js.org/) reports.
9
+ 🌐 English | [įŽ€äŊ“中文](README.zh-Hans.md)
10
+
11
+ > A JavaScript code coverage tool to generate native [V8](https://v8.dev/blog/javascript-code-coverage) reports or [Istanbul](https://istanbul.js.org/) reports.
10
12
 
11
13
  * [Usage](#usage)
12
14
  * [Options](#options)
@@ -37,10 +39,11 @@
37
39
  * [Integration with Any Testing Framework](#integration-with-any-testing-framework)
38
40
  * [Integration Examples](#integration-examples)
39
41
  - [Playwright](#playwright)
42
+ - [CodeceptJS](#codeceptjs)
40
43
  - [Jest](#jest)
41
44
  - [Vitest](#vitest)
45
+ - [Puppeteer](#puppeteer)
42
46
  - [Cypress](#cypress)
43
- - [CodeceptJS](#codeceptjs)
44
47
  - [WebdriverIO](#webdriverio)
45
48
  - [Storybook Test Runner](#storybook-test-runner)
46
49
  - [TestCafe](#testcafe)
@@ -202,6 +205,8 @@ const mcr = MCR(coverageOptions);
202
205
  ```
203
206
 
204
207
  ## Compare Reports
208
+ > If the V8 data format is used for Istanbul reports, it will be automatically converted from V8 to Istanbul.
209
+
205
210
  | | Istanbul | V8 | V8 to Istanbul |
206
211
  | :--------------| :------ | :------ | :---------------------- |
207
212
  | Coverage data | [Istanbul](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md) (Object) | [V8](#v8-coverage-data-format) (Array) | [V8](#v8-coverage-data-format) (Array) |
@@ -324,6 +329,8 @@ Possible solutions:
324
329
  - Taking coverage data and adding it to the report.
325
330
  - Example:
326
331
  > node [./test/test-node-ins.js](./test/test-node-ins.js)
332
+ - vm Example (scriptOffset):
333
+ > node [./test/test-node-vm.js](./test/test-node-vm.js)
327
334
 
328
335
  - [CDP](https://chromedevtools.github.io/devtools-protocol/) API
329
336
  - Enabling [Node Debugging](https://nodejs.org/en/guides/debugging-getting-started/).
@@ -696,32 +703,7 @@ npx mcr node ./test/specs/node.test.js -r v8,console-details --lcov
696
703
  ```
697
704
 
698
705
  - CLI Options
699
- ```sh
700
- Usage: mcr [options] [command]
701
-
702
- CLI to generate coverage reports
703
-
704
- Arguments:
705
- command command to execute
706
-
707
- Options:
708
- -v, --version output the current version
709
- -c, --config <path> custom config file path
710
- -l, --logging <logging> off, error, info, debug
711
- -n, --name <name> report name for title
712
- -r, --reports <name[,name]> coverage reports to use
713
- -o, --outputDir <dir> output dir for reports
714
- -i, --inputDir <dir> input dir for merging raw files
715
- --entryFilter <pattern> entry url filter
716
- --sourceFilter <pattern> source path filter
717
- --outputFile <path> output file for v8 report
718
- --inline inline html for v8 report
719
- --assetsPath <path> assets path if not inline
720
- --lcov generate lcov.info file
721
- --import <module> preload module at startup
722
- --require <module> preload module at startup
723
- -h, --help display help for command
724
- ```
706
+ see all options with running `mcr` or `mcr --help`
725
707
 
726
708
  - Use `--` to separate sub CLI args
727
709
  ```sh
@@ -744,24 +726,24 @@ Loading config file by priority:
744
726
  - `mcr.config.mjs`
745
727
  - `mcr.config.json` - json format
746
728
  - `mcr.config.ts` (requires preloading the ts execution module)
747
- - `.mcrrc.js`
748
- - `.mcrrc` - json format
749
729
 
750
730
  ## Merge Coverage Reports
751
731
  The following usage scenarios may require merging coverage reports:
752
- - When the code is executed in different environments, like Node.js server side and browser client side (Next.js for instance). Each environment may generate its own coverage report. Merging them can give a more comprehensive view of the test coverage.
753
- - When the code is subjected to different kinds of testing. For example, unit tests with Jest might cover certain parts of the code, while end-to-end tests with Playwright might cover other parts. Merging these different coverage reports can provide a holistic view of what code has been tested.
732
+ - When the code is executed in different environments, like Node.js `server side` and browser `client side` (`Next.js` for instance). Each environment may generate its own coverage report. Merging them can give a more comprehensive view of the test coverage.
733
+ - When the code is subjected to different kinds of testing. For example, `unit tests` with `Jest` might cover certain parts of the code, while `end-to-end tests` with `Playwright` might cover other parts. Merging these different coverage reports can provide a holistic view of what code has been tested.
754
734
  - When tests are run on different machines or containers, each might produce its own coverage report. Merging these can give a complete picture of the test coverage across all machines or shards.
755
735
 
756
736
  ### Automatic Merging
757
- - `MCR` will automatically merge all the added coverage data when executing `generate()`. And it supports adding coverage data asynchronously across processes, see [Multiprocessing Support](#multiprocessing-support)
758
- - For Next.js, it can actually add coverage data including both server side and client side before executing `generate()`, see example [nextjs-with-playwright](https://github.com/cenfun/nextjs-with-playwright)
759
- - Use Codecov, a popular online code coverage service, which supports automatic merging of reports. Please use report `codecov`, it will generate report file `codecov.json`. If multiple `codecov.json` files are generated, upload all these files, they will be automatically merged. see [Codecov](#codecov) and [merging reports](https://docs.codecov.com/docs/merging-reports)
737
+ - The `MCR` will automatically merge all the added coverage data when executing `generate()`. And it supports adding coverage data asynchronously across processes, see [Multiprocessing Support](#multiprocessing-support)
738
+ - For `Next.js`, it can actually add coverage data including both server side and client side before executing `generate()`, see example [nextjs-with-playwright](https://github.com/cenfun/nextjs-with-playwright)
739
+ - Using `Codecov`, a popular online code coverage service, which supports automatic merging of reports. Please use report `codecov`, it will generate report file `codecov.json`. If multiple `codecov.json` files are generated, upload all these files, they will be automatically merged. see [Codecov](#codecov) and [merging reports](https://docs.codecov.com/docs/merging-reports)
760
740
 
761
741
  ### Manual Merging
762
- If the reports cannot be merged automatically, then here is how to manually merge the reports.
742
+ If the reports cannot be merged automatically, then here is how to manually merge the reports.
763
743
  First, using the `raw` report to export the original coverage data to the specified directory.
764
- - For example, we have `raw` coverage data from unit tests, which is output to `./coverage-reports/unit/raw`
744
+ - For example, we have `raw` coverage data from `unit test`, which is output to `./coverage-reports/unit/raw`. Unit test examples:
745
+ - `Jest` + [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage)
746
+ - `Vitest` + [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage)
765
747
  ```js
766
748
  const coverageOptions = {
767
749
  name: 'My Unit Test Coverage Report',
@@ -777,8 +759,13 @@ const coverageOptions = {
777
759
  ]
778
760
  };
779
761
  ```
780
- - We also have `raw` coverage data from e2e tests, which is output to `./coverage-reports/e2e/raw`
781
- - Create a script `merge-coverage.js` to generate a merged report with option `inputDir`. After all the tests are completed, running script `node path/to/merge-coverage.js`
762
+
763
+ - We also have `raw` coverage data from `e2e test`, which is output to `./coverage-reports/e2e/raw`. E2E test examples:
764
+ - `Playwright` + [monocart-reporter](https://github.com/cenfun/monocart-reporter) with coverage API
765
+ - `Playwright` + `MCR`, see [playwright-coverage](https://github.com/cenfun/playwright-coverage)
766
+ - see more [Integration Examples](#integration-examples)
767
+
768
+ - Then create a script `merge-coverage.js` to generate a merged report with option `inputDir`.
782
769
  ```js
783
770
  // merge-coverage.js
784
771
  const fs = require('fs');
@@ -828,7 +815,7 @@ const coverageOptions = {
828
815
  };
829
816
  await new CoverageReport(coverageOptions).generate();
830
817
  ```
831
- - All the command scripts are probably like following:
818
+ - Running script `node path/to/merge-coverage.js` after all the tests are completed. All the command scripts are probably like following:
832
819
  ```json
833
820
  {
834
821
  "scripts": {
@@ -907,42 +894,46 @@ When `logging` is `debug`, the raw report data will be preserved in `[outputDir]
907
894
  ## Integration Examples
908
895
 
909
896
  ### [Playwright](https://github.com/microsoft/playwright)
910
- - [playwright-coverage](https://github.com/cenfun/playwright-coverage) - A Example for Playwright Coverage Reports
911
- - [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)
912
- - Coverage for component testing:
897
+ - [playwright-coverage](https://github.com/cenfun/playwright-coverage) - Example for Playwright coverage reports
898
+ - [playwright-bdd-coverage](https://github.com/cenfun/playwright-bdd-coverage) - Example for Playwright BDD coverage reports
899
+ - [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)
900
+ - Coverage for component testing with `monocart-reporter`:
913
901
  - [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue)
914
902
  - [playwright-ct-react](https://github.com/cenfun/playwright-ct-react)
915
903
  - [playwright-ct-svelte](https://github.com/cenfun/playwright-ct-svelte)
916
904
  - Coverage for Next.js, both server side and client side:
917
905
  - [nextjs-with-playwright](https://github.com/cenfun/nextjs-with-playwright)
918
906
  - [nextjs-with-playwright-istanbul](https://github.com/cenfun/nextjs-with-playwright-istanbul)
907
+ - see [Collecting V8 Coverage Data with Playwright](#collecting-v8-coverage-data-with-playwright)
908
+
909
+ ### [CodeceptJS](https://github.com/codeceptjs/CodeceptJS)
910
+ - CodeceptJS is a [BDD](https://codecept.io/bdd/) + [AI](https://codecept.io/ai/) testing framework for e2e testing, it has integrated `MCR` since [v3.5.15](https://github.com/codeceptjs/CodeceptJS/releases/tag/3.5.15), see [plugins/coverage](https://codecept.io/plugins/#coverage). There's no need to use ~~[codeceptjs-monocart-coverage](https://github.com/cenfun/codeceptjs-monocart-coverage)~~ anymore.
919
911
 
920
912
  ### [Jest](https://github.com/jestjs/jest/)
921
- - [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - A Jest custom reporter for coverage reports
922
- - [jest-puppeteer-coverage](https://github.com/cenfun/jest-puppeteer-coverage) - A Jest Puppeteer Coverage Example
923
- - Example for Jest (unit) + Puppeteer (e2e) + Codecov: [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js)
913
+ - [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - Jest custom reporter for coverage reports
924
914
 
925
915
  ### [Vitest](https://github.com/vitest-dev/vitest)
926
- - [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - A Vitest custom provider module for coverage reports
916
+ - [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - Vitest custom provider module for coverage reports
927
917
 
928
- ### [Cypress](https://github.com/cypress-io/cypress)
929
- - [cypress-monocart-coverage](https://github.com/cenfun/cypress-monocart-coverage) - A Cypress plugin for coverage reports
918
+ ### [Puppeteer](https://github.com/puppeteer/puppeteer/)
919
+ - [jest-puppeteer-coverage](https://github.com/cenfun/jest-puppeteer-coverage) - Example for Jest puppeteer coverage
920
+ - [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) - Example for Jest (unit) + Puppeteer (e2e) + Codecov
921
+ - see [Collecting Raw V8 Coverage Data with Puppeteer](#collecting-raw-v8-coverage-data-with-puppeteer)
930
922
 
931
- ### [CodeceptJS](https://github.com/codeceptjs/CodeceptJS)
932
- - CodeceptJS has integrated MCR from version [3.5.15](https://github.com/codeceptjs/CodeceptJS/releases/tag/3.5.15)
933
- - [codeceptjs-monocart-coverage](https://github.com/cenfun/codeceptjs-monocart-coverage) - A CodeceptJS plugin for coverage reports
923
+ ### [Cypress](https://github.com/cypress-io/cypress)
924
+ - [cypress-monocart-coverage](https://github.com/cenfun/cypress-monocart-coverage) - Cypress plugin for coverage reports
934
925
 
935
926
  ### [WebdriverIO](https://github.com/webdriverio/webdriverio)
936
- - [wdio-monocart-service](https://github.com/cenfun/wdio-monocart-service) - A WebdriverIO service for coverage reports
927
+ - [wdio-monocart-service](https://github.com/cenfun/wdio-monocart-service) - WebdriverIO service for coverage reports
937
928
 
938
929
  ### [Storybook Test Runner](https://github.com/storybookjs/test-runner)
939
- - [storybook-monocart-coverage](https://github.com/cenfun/storybook-monocart-coverage) - Storybook V8 Coverage Example
930
+ - [storybook-monocart-coverage](https://github.com/cenfun/storybook-monocart-coverage) - Example for Storybook V8 coverage reports
940
931
 
941
932
  ### [TestCafe](https://github.com/DevExpress/testcafe)
942
- - [testcafe-reporter-coverage](https://github.com/cenfun/testcafe-reporter-coverage) - A TestCafe custom reporter for coverage reports
933
+ - [testcafe-reporter-coverage](https://github.com/cenfun/testcafe-reporter-coverage) - TestCafe custom reporter for coverage reports
943
934
 
944
935
  ### [Selenium Webdriver](https://github.com/seleniumhq/selenium)
945
- - [selenium-webdriver-coverage](https://github.com/cenfun/selenium-webdriver-coverage) - Selenium Webdriver V8 Coverage Example
936
+ - [selenium-webdriver-coverage](https://github.com/cenfun/selenium-webdriver-coverage) - Example for Selenium Webdriver V8 coverage reports
946
937
 
947
938
  ### [Mocha](https://github.com/mochajs/mocha)
948
939
  ```sh