monocart-coverage-reports 2.3.3 → 2.4.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 +50 -20
- package/lib/converter/ast-visitor.js +646 -0
- package/lib/converter/ast.js +116 -137
- package/lib/converter/collect-source-maps.js +1 -1
- package/lib/converter/converter.js +337 -226
- package/lib/converter/find-original-range.js +471 -411
- package/lib/converter/ignore.js +33 -22
- package/lib/converter/info-branch.js +13 -2
- package/lib/converter/info-function.js +29 -6
- package/lib/converter/info-statement.js +43 -0
- package/lib/default/options.js +1 -1
- package/lib/generate.js +2 -2
- package/lib/index.d.ts +24 -13
- package/lib/istanbul/istanbul.js +1 -1
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +38 -37
- package/lib/platform/share.js +39 -4
- package/lib/utils/util.js +8 -2
- package/lib/v8/v8-summary.js +5 -1
- package/lib/v8/v8.js +4 -1
- package/package.json +3 -3
- package/lib/converter/branches.js +0 -429
- package/lib/converter/find-in-ranges.js +0 -39
- package/lib/converter/info-line.js +0 -23
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/monocart-coverage-reports)
|
|
4
4
|
[](https://www.npmjs.com/package/monocart-coverage-reports)
|
|
5
|
+

|
|
5
6
|

|
|
6
7
|

|
|
7
8
|
|
|
@@ -29,8 +30,8 @@
|
|
|
29
30
|
* [How to convert V8 to Istanbul](#how-to-convert-v8-to-istanbul)
|
|
30
31
|
- [Using `v8-to-istanbul`](#using-v8-to-istanbul)
|
|
31
32
|
- [How Monocart Works](#how-monocart-works)
|
|
33
|
+
* [Debug for Coverage and Sourcemap](#debug-for-coverage-and-sourcemap)
|
|
32
34
|
* [Integration](#integration) - Playwright, Jest, Vitest, Codecov, Coveralls, Sonar Cloud
|
|
33
|
-
* [Istanbul Introduction](#istanbul-introduction)
|
|
34
35
|
* [Thanks](#thanks)
|
|
35
36
|
|
|
36
37
|
## Usage
|
|
@@ -302,7 +303,7 @@ mcr "node ./test/test-node-env.js" -c test/cli-options.js
|
|
|
302
303
|
- see [Node.js V8 Coverage Report for Server Side](#nodejs-v8-coverage-report-for-server-side)
|
|
303
304
|
|
|
304
305
|
## Manually Resolve the Sourcemap
|
|
305
|
-
>
|
|
306
|
+
> Sometimes, the sourcemap file cannot be successfully loaded with the `sourceMappingURL`, you can try to manually read the sourcemap file before the coverage data is added to the report.
|
|
306
307
|
```js
|
|
307
308
|
const jsCoverage = await page.coverage.stopJSCoverage();
|
|
308
309
|
jsCoverage.forEach((entry) => {
|
|
@@ -370,26 +371,32 @@ Possible solutions:
|
|
|
370
371
|
- see [`mcr` CLI](#mcr-cli)
|
|
371
372
|
|
|
372
373
|
## Multiprocessing Support
|
|
373
|
-
The data will be added to `[outputDir]/.cache`,
|
|
374
|
-
-
|
|
374
|
+
> The data will be added to `[outputDir]/.cache`, After the generation of the report, this data will be removed unless debugging has been enabled or a raw report has been used, see [Debug for Coverage and Sourcemap](#debug-for-coverage-and-sourcemap)
|
|
375
|
+
- Main process, before the start of testing
|
|
375
376
|
```js
|
|
377
|
+
// clean previous cache before the start of testing (option)
|
|
376
378
|
const MCR = require('monocart-coverage-reports');
|
|
377
379
|
const options = require('path-to/same-options.js');
|
|
378
|
-
|
|
379
|
-
await coverageReport.add(coverageData1);
|
|
380
|
+
MCR(options).cleanCache();
|
|
380
381
|
```
|
|
381
382
|
|
|
382
|
-
-
|
|
383
|
+
- Sub process 1, testing stage 1
|
|
383
384
|
```js
|
|
384
385
|
const MCR = require('monocart-coverage-reports');
|
|
385
386
|
const options = require('path-to/same-options.js');
|
|
386
|
-
|
|
387
|
-
|
|
387
|
+
await MCR(options).add(coverageData1);
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
- Sub process 2, testing stage 2
|
|
391
|
+
```js
|
|
392
|
+
const MCR = require('monocart-coverage-reports');
|
|
393
|
+
const options = require('path-to/same-options.js');
|
|
394
|
+
await MCR(options).add(coverageData2);
|
|
388
395
|
```
|
|
389
396
|
|
|
390
|
-
-
|
|
397
|
+
- Main process, after the completion of testing
|
|
391
398
|
```js
|
|
392
|
-
// after
|
|
399
|
+
// generate coverage reports after the completion of testing
|
|
393
400
|
const MCR = require('monocart-coverage-reports');
|
|
394
401
|
const options = require('path-to/same-options.js');
|
|
395
402
|
const coverageReport = MCR(options);
|
|
@@ -399,10 +406,11 @@ console.log(coverageResults.summary);
|
|
|
399
406
|
|
|
400
407
|
## Merge Coverage Reports
|
|
401
408
|
The following usage scenarios may require merging coverage reports:
|
|
402
|
-
- 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.
|
|
409
|
+
- 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. see example [nextjs-with-playwright](https://github.com/cenfun/nextjs-with-playwright) for automatic report merging.
|
|
403
410
|
- 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.
|
|
404
411
|
- When tests are run on different machines or different shards, each might produce its own coverage report. Merging these can give a complete picture of the test coverage across all machines or shards.
|
|
405
412
|
|
|
413
|
+
If the reports cannot be merged automatically, then here is how to manually merge the reports.
|
|
406
414
|
First, using the `raw` report to export the original coverage data to the specified directory.
|
|
407
415
|
```js
|
|
408
416
|
const coverageOptions = {
|
|
@@ -478,7 +486,7 @@ const os = platform === 'wind32' ? 'Windows' /* v8 ignore next */ : 'Other';
|
|
|
478
486
|
|
|
479
487
|
// v8 ignore next 3
|
|
480
488
|
if (platform === 'linux') {
|
|
481
|
-
console.
|
|
489
|
+
console.log('hello linux');
|
|
482
490
|
}
|
|
483
491
|
```
|
|
484
492
|
|
|
@@ -577,6 +585,25 @@ We implemented new converter instead of v8-to-istanbul:
|
|
|
577
585
|
| LogicalExpression | ✔ Not Perfect |
|
|
578
586
|
| SwitchStatement | ✔ Not Perfect |
|
|
579
587
|
|
|
588
|
+
## Debug for Coverage and Sourcemap
|
|
589
|
+
> Sometimes, the coverage is not what we expect. The next step is to figure out why, and we can easily find out the answer step by step through debugging.
|
|
590
|
+
- Start debugging for v8 report with option `logging: 'debug'`
|
|
591
|
+
```js
|
|
592
|
+
const coverageOptions = {
|
|
593
|
+
logging: 'debug',
|
|
594
|
+
reports: [
|
|
595
|
+
['v8'],
|
|
596
|
+
['console-summary']
|
|
597
|
+
]
|
|
598
|
+
};
|
|
599
|
+
```
|
|
600
|
+
When `logging` is `debug`, the raw report data will be preserved in `[outputDir]/.cache` or `[outputDir]/raw` if `raw` report is used. And the dist file will be preserved in the V8 list, and by opening the browser's devtool, it makes data verification visualization effortless.
|
|
601
|
+

|
|
602
|
+
|
|
603
|
+
- Check sourcemap with [Source Map Visualization](https://evanw.github.io/source-map-visualization/)
|
|
604
|
+
|
|
605
|
+

|
|
606
|
+
|
|
580
607
|
## Integration
|
|
581
608
|
- [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)
|
|
582
609
|
- [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - A [Jest](https://github.com/jestjs/jest/) custom reporter for coverage reports
|
|
@@ -601,6 +628,12 @@ We implemented new converter instead of v8-to-istanbul:
|
|
|
601
628
|
```
|
|
602
629
|
- [Coveralls](https://coveralls.io/)
|
|
603
630
|
- [](https://coveralls.io/github/cenfun/monocart-coverage-reports?branch=main)
|
|
631
|
+
```js
|
|
632
|
+
const coverageOptions = {
|
|
633
|
+
outputDir: "./coverage-reports",
|
|
634
|
+
lcov: true
|
|
635
|
+
};
|
|
636
|
+
```
|
|
604
637
|
- Github Actions example:
|
|
605
638
|
```yml
|
|
606
639
|
- name: Coveralls
|
|
@@ -627,13 +660,10 @@ We implemented new converter instead of v8-to-istanbul:
|
|
|
627
660
|
-Dsonar.tests=test
|
|
628
661
|
-Dsonar.exclusions=dist/*,packages/*
|
|
629
662
|
```
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
- [
|
|
634
|
-
- [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul)
|
|
635
|
-
- [istanbul-reports](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
|
|
636
|
-
- [Code Coverage Introduction](https://docs.cypress.io/guides/tooling/code-coverage)
|
|
663
|
+
- Integration with any testing framework
|
|
664
|
+
- First, you need to collect coverage data when any stage of the test is completed. Then, add the coverage data to the coverage report.
|
|
665
|
+
- Upon the completion of all tests, generate the coverage report.
|
|
666
|
+
- see [Multiprocessing Support](#multiprocessing-support)
|
|
637
667
|
|
|
638
668
|
## Thanks
|
|
639
669
|
- Special thanks to [@edumserrano](https://github.com/edumserrano)
|