monocart-coverage-reports 2.5.6 → 2.5.7

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
@@ -492,7 +492,15 @@ const coverageOptions = {
492
492
  }
493
493
  };
494
494
  ```
495
- see example: [./test/test-merge.js](./test/test-merge.js)
495
+ It also supports simple key/value replacement:
496
+ ```js
497
+ const coverageOptions = {
498
+ sourcePath: {
499
+ 'my-dist-file1/': '',
500
+ 'my-dist-file2/': ''
501
+ }
502
+ };
503
+ ```
496
504
 
497
505
  ## Adding Empty Coverage for Untested Files
498
506
  By default the untested files will not be included in the coverage report, we can first add empty coverage data for all files, so the files with coverage data will be merged, and untested files will retain 0% coverage.
@@ -649,12 +657,24 @@ When `logging` is `debug`, the raw report data will be preserved in `[outputDir]
649
657
  ![](./assets/debug-sourcemap.png)
650
658
 
651
659
  ## Integration
660
+
652
661
  ### [Playwright](https://github.com/microsoft/playwright)
653
662
  - [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)
663
+ - Coverage for component testing:
664
+ - [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue)
665
+ - [playwright-ct-react](https://github.com/cenfun/playwright-ct-react)
666
+ - [playwright-ct-svelte](https://github.com/cenfun/playwright-ct-svelte)
667
+ - Coverage for Next.js, both server side and client side:
668
+ - [nextjs-with-playwright](https://github.com/cenfun/nextjs-with-playwright)
669
+ - [nextjs-with-playwright-istanbul](https://github.com/cenfun/nextjs-with-playwright-istanbul)
670
+
654
671
  ### [Jest](https://github.com/jestjs/jest/)
655
672
  - [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - A Jest custom reporter for coverage reports
673
+ - Example for Jest (unit) + Puppeteer (e2e) + Codecov: [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js)
674
+
656
675
  ### [Vitest](https://github.com/vitest-dev/vitest)
657
676
  - [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - A Vitest custom provider module for coverage reports
677
+
658
678
  ### [Codecov](https://codecov.com/)
659
679
  [![codecov](https://codecov.io/gh/cenfun/monocart-coverage-reports/graph/badge.svg?token=H0LW7UKYU3)](https://codecov.io/gh/cenfun/monocart-coverage-reports)
660
680
  - Supports native `codecov` built-in report ([specification](https://docs.codecov.com/docs/codecov-custom-coverage-format))
@@ -3,23 +3,10 @@ const path = require('path');
3
3
  const EC = require('eight-colors');
4
4
  const { fileURLToPath, pathToFileURL } = require('url');
5
5
  const Concurrency = require('../platform/concurrency.js');
6
- const { convertSourceMap, axios } = require('../packages/monocart-coverage-vendor.js');
6
+ const { convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
7
7
 
8
8
  const Util = require('../utils/util.js');
9
9
 
10
- const request = async (options) => {
11
- if (typeof options === 'string') {
12
- options = {
13
- url: options
14
- };
15
- }
16
- let err;
17
- const res = await axios(options).catch((e) => {
18
- err = e;
19
- });
20
- return [err, res];
21
- };
22
-
23
10
  const loadSourceMap = async (url = '') => {
24
11
 
25
12
  if (url.startsWith('file:')) {
@@ -32,7 +19,7 @@ const loadSourceMap = async (url = '') => {
32
19
  return JSON.parse(content);
33
20
  }
34
21
 
35
- const [err, res] = await request({
22
+ const [err, res] = await Util.request({
36
23
  url
37
24
  });
38
25
 
@@ -14,7 +14,9 @@ const { getIgnoredRanges } = require('./ignore.js');
14
14
  const {
15
15
  sortRanges, dedupeCountRanges, mergeRangesWith
16
16
  } = require('../utils/dedupe.js');
17
- const { getSourceType, initSourceMapSourcePath } = require('../utils/source-path.js');
17
+ const {
18
+ getSourceType, getSourcePathHandler, initSourceMapSourcePath
19
+ } = require('../utils/source-path.js');
18
20
  const { decode, minimatch } = require('../packages/monocart-coverage-vendor.js');
19
21
 
20
22
  const InfoBranch = require('./info-branch.js');
@@ -968,7 +970,7 @@ const unpackSourceMap = (state, options) => {
968
970
 
969
971
  // keep original urls
970
972
  const fileUrls = {};
971
- const sourcePathHandler = options.sourcePath;
973
+ const sourcePathHandler = getSourcePathHandler(options);
972
974
  initSourceMapSourcePath(sourceMap, fileUrls, sourcePathHandler);
973
975
  state.fileUrls = fileUrls;
974
976
 
package/lib/index.d.ts CHANGED
@@ -242,8 +242,14 @@ declare namespace MCR {
242
242
  /** {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false. */
243
243
  lcov?: boolean;
244
244
 
245
- /** {function} Source path handler. */
246
- sourcePath?: (filePath: string) => string;
245
+ /**
246
+ * {function} Source path handler.
247
+ *
248
+ * {object} Replace key with value.
249
+ * */
250
+ sourcePath?: ((filePath: string) => string) | {
251
+ [key: string]: string;
252
+ };
247
253
 
248
254
  /** {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html. */
249
255
  reportPath?: string | (() => string);
@@ -7,7 +7,7 @@ const istanbulLibReport = require('istanbul-lib-report');
7
7
  const Util = require('../utils/util.js');
8
8
  const IstanbulSummary = require('./istanbul-summary.js');
9
9
 
10
- const { initIstanbulSourcePath } = require('../utils/source-path.js');
10
+ const { getSourcePathHandler, initIstanbulSourcePath } = require('../utils/source-path.js');
11
11
 
12
12
  const findHtmlPath = (outputDir) => {
13
13
  const defaultHtml = path.resolve(outputDir, 'index.html');
@@ -129,7 +129,7 @@ const mergeIstanbulCoverage = (dataList) => {
129
129
  const initIstanbulData = (istanbulData, options) => {
130
130
 
131
131
  const fileSources = options.fileSources || {};
132
- const sourcePathHandler = options.sourcePath;
132
+ const sourcePathHandler = getSourcePathHandler(options);
133
133
 
134
134
  const coverageData = initIstanbulSourcePath(istanbulData, fileSources, sourcePathHandler);
135
135