monocart-coverage-reports 2.7.7 → 2.7.8

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
@@ -50,6 +50,8 @@
50
50
  - [Codecov](#codecov)
51
51
  - [Coveralls](#coveralls)
52
52
  - [Sonar Cloud](#sonar-cloud)
53
+ * [Contributing](#contributing)
54
+ * [Changelog](CHANGELOG.md)
53
55
  * [Thanks](#thanks)
54
56
 
55
57
  ## Usage
@@ -222,19 +224,24 @@ const mcr = MCR(coverageOptions);
222
224
  - vite: [vite-plugin-istanbul](https://github.com/ifaxity/vite-plugin-istanbul)
223
225
  - rollup: [rollup-plugin-istanbul](https://github.com/artberri/rollup-plugin-istanbul)
224
226
  - swc: [swc-plugin-coverage-instrument](https://github.com/kwonoj/swc-plugin-coverage-instrument)
227
+
225
228
  - Browser
226
229
  - Collecting coverage data from `window.__coverage__`, example: [test-istanbul.js](./test/test-istanbul.js)
230
+
227
231
  - Node.js
228
232
  - Collecting coverage data from `global.__coverage__`
229
233
 
234
+ - CDP
235
+ - `getIstanbulCoverage()` see [`CDPClient` API](#collecting-v8-coverage-data-with-cdpclient-api)
236
+
230
237
  ## Collecting V8 Coverage Data
231
238
  - Before coverage collection: Enabling `sourcemap` for source code
232
239
  - [webpack](https://webpack.js.org/configuration/): `devtool: source-map` and `mode: development`, example [webpack.config-v8.js](./test/build/webpack.config-v8.js)
233
- - [rollup](https://rollupjs.org/configuration-options/): `sourcemap: true`
240
+ - [rollup](https://rollupjs.org/configuration-options/): `sourcemap: true` and `treeshake: false`
241
+ - [esbuild](https://esbuild.github.io/api/): `sourcemap: true`, `treeShaking: false` and `minify: false`
234
242
  - [vite](https://vitejs.dev/config/build-options.html): `sourcemap: true` and `minify: false`
235
- - [esbuild](https://esbuild.github.io/api/): `sourcemap: true` and `minify: false`
236
243
 
237
- - Browser (Chromium Only)
244
+ - Browser (Chromium-based Only)
238
245
  - [Collecting V8 Coverage Data with Playwright](#collecting-v8-coverage-data-with-playwright)
239
246
  - [Collecting Raw V8 Coverage Data with Puppeteer](#collecting-raw-v8-coverage-data-with-puppeteer)
240
247
 
@@ -331,7 +338,27 @@ Possible solutions:
331
338
  - see [Command Line](#command-line)
332
339
 
333
340
  ### Collecting V8 Coverage Data with `CDPClient` API
334
- - Work with node debugger port `--inspect=9229`
341
+ - `CDPClient` available APIs
342
+ ```js
343
+ startJSCoverage: () => Promise<void>;
344
+ stopJSCoverage: () => Promise<V8CoverageEntry[]>;
345
+
346
+ startCSSCoverage: () => Promise<void>;
347
+ stopCSSCoverage: () => Promise<V8CoverageEntry[]>;
348
+
349
+ /** start both js and css coverage */
350
+ startCoverage: () => Promise<void>;
351
+ /** stop and return both js and css coverage */
352
+ stopCoverage: () => Promise<V8CoverageEntry[]>;
353
+
354
+ /** write the coverage started by NODE_V8_COVERAGE to disk on demand, returns v8 coverage dir */
355
+ writeCoverage: () => Promise<string>;
356
+
357
+ /** get istanbul coverage data */
358
+ getIstanbulCoverage: (coverageKey?: string) => Promise<any>;
359
+ ```
360
+
361
+ - Work with node debugger port `--inspect=9229` or browser debugging port `--remote-debugging-port=9229`
335
362
  ```js
336
363
  const MCR = require('monocart-coverage-reports');
337
364
  const client = await MCR.CDPClient({
@@ -341,6 +368,7 @@ await client.startJSCoverage();
341
368
  // run your test here
342
369
  const coverageData = await client.stopJSCoverage();
343
370
  ```
371
+
344
372
  - Work with [Playwright CDPSession](https://playwright.dev/docs/api/class-cdpsession)
345
373
  ```js
346
374
  const { chromium } = require('playwright');
@@ -357,6 +385,7 @@ await client.startCoverage();
357
385
  await page.goto("your page url");
358
386
  const coverageData = await client.stopCoverage();
359
387
  ```
388
+
360
389
  - Work with [Puppeteer CDPSession](https://pptr.dev/api/puppeteer.cdpsession)
361
390
  ```js
362
391
  const puppeteer = require('puppeteer');
@@ -373,6 +402,7 @@ await client.startCoverage();
373
402
  await page.goto("your page url");
374
403
  const coverageData = await client.stopCoverage();
375
404
  ```
405
+
376
406
  - Work with [Selenium Webdriver](https://www.selenium.dev/documentation/webdriver/) WebSocket (Chrome/Edge Browser)
377
407
  ```js
378
408
  const { Builder, Browser } = require('selenium-webdriver');
@@ -384,29 +414,6 @@ const client = await MCR.CDPClient({
384
414
  session
385
415
  })
386
416
  ```
387
- - `CDPClient` available APIs
388
- ```js
389
- /** start js coverage */
390
- startJSCoverage: () => Promise<void>;
391
- /** stop and return js coverage */
392
- stopJSCoverage: () => Promise<V8CoverageEntry[]>;
393
-
394
- /** start css coverage */
395
- startCSSCoverage: () => Promise<void>;
396
- /** stop and return css coverage */
397
- stopCSSCoverage: () => Promise<V8CoverageEntry[]>;
398
-
399
- /** start both js and css coverage */
400
- startCoverage: () => Promise<void>;
401
- /** stop and return both js and css coverage */
402
- stopCoverage: () => Promise<V8CoverageEntry[]>;
403
-
404
- /** write the coverage started by NODE_V8_COVERAGE to disk on demand, returns v8 coverage dir */
405
- writeCoverage: () => Promise<string>;
406
-
407
- /** get istanbul coverage data */
408
- getIstanbulCoverage: (coverageKey?: string) => Promise<any>;
409
- ```
410
417
 
411
418
  ### V8 Coverage Data API
412
419
  - [JavaScript code coverage in V8](https://v8.dev/blog/javascript-code-coverage)
@@ -700,6 +707,12 @@ Options:
700
707
  mcr -c mcr.config.js -- sub-cli -c sub-cli.config.js
701
708
  ```
702
709
 
710
+ - Examples
711
+ - [Mocha](#mocha)
712
+ - [tsx](#tsx)
713
+ - [ts-node](#ts-node)
714
+ - [AVA](#ava)
715
+
703
716
  ## Config File
704
717
  Loading config file by priority:
705
718
  - Custom config file:
@@ -969,6 +982,18 @@ const coverageOptions = {
969
982
  -Dsonar.exclusions=dist/*,packages/*
970
983
  ```
971
984
 
985
+ ## Contributing
986
+ ```sh
987
+ # Node.js 20+
988
+ npm install starfall-cli -g
989
+ npm install
990
+
991
+ npm run build
992
+ npm run test
993
+
994
+ npm run dev
995
+ ```
996
+
972
997
  ### VSCode Extension
973
998
  - [Coverage Gutters](https://github.com/ryanluker/vscode-coverage-gutters) - Display test coverage generated by lcov or xml in VSCode editor.
974
999
 
@@ -12,10 +12,7 @@ const getDebuggerUrl = async (options) => {
12
12
  const protocol = options.secure ? 'https' : 'http';
13
13
 
14
14
  const url = `${protocol}://${options.host}:${options.port}/json/list`;
15
- const [err, res] = await Util.request({
16
- url,
17
- timeout: options.timeout
18
- });
15
+ const [err, res] = await Util.request(url);
19
16
  if (err) {
20
17
  return [err];
21
18
  }
@@ -19,9 +19,7 @@ const loadSourceMap = async (url = '') => {
19
19
  return JSON.parse(content);
20
20
  }
21
21
 
22
- const [err, res] = await Util.request({
23
- url
24
- });
22
+ const [err, res] = await Util.request(url);
25
23
 
26
24
  if (err) {
27
25
  Util.logDebug(EC.red(`${err.message} ${url}`));
@@ -5,8 +5,8 @@
5
5
  */
6
6
 
7
7
  const EC = require('eight-colors');
8
- const { Locator } = require('monocart-formatter');
9
8
 
9
+ const { Locator } = require('monocart-locator');
10
10
  const Util = require('../utils/util.js');
11
11
 
12
12
  const findOriginalRange = require('./find-original-range.js');
@@ -984,9 +984,13 @@ const initOriginalList = (state, originalDecodedMap, options) => {
984
984
 
985
985
  const { sources, sourcesContent } = state.sourceMap;
986
986
 
987
+ const lengthBefore = sources.length;
988
+ let lengthAfter = 0;
989
+
987
990
  sources.forEach((sourcePath, sourceIndex) => {
988
991
 
989
992
  // filter
993
+ // do not change for sourceIndex
990
994
  if (!sourceFilter(sourcePath)) {
991
995
  // console.log('-', sourcePath);
992
996
  return;
@@ -1034,8 +1038,11 @@ const initOriginalList = (state, originalDecodedMap, options) => {
1034
1038
  };
1035
1039
 
1036
1040
  originalStateMap.set(sourceIndex, originalState);
1041
+ lengthAfter += 1;
1037
1042
  });
1038
1043
 
1044
+ Util.logFilter(`source filter (${state.sourcePath}):`, lengthBefore, lengthAfter);
1045
+
1039
1046
  return originalStateMap;
1040
1047
  };
1041
1048
 
@@ -1044,6 +1051,8 @@ const collectOriginalList = (state, originalStateMap) => {
1044
1051
  const { fileUrls } = state;
1045
1052
  const distFile = state.sourcePath;
1046
1053
 
1054
+ let added = 0;
1055
+
1047
1056
  // collect original files
1048
1057
  originalStateMap.forEach((originalState) => {
1049
1058
 
@@ -1070,8 +1079,11 @@ const collectOriginalList = (state, originalStateMap) => {
1070
1079
  // save v8 data and add to originalList
1071
1080
  originalState.v8Data = sourceItem;
1072
1081
  state.originalList.push(originalState);
1082
+ added += 1;
1073
1083
  });
1074
1084
 
1085
+ Util.logDebug(`added source files: ${EC.yellow(added)}`);
1086
+
1075
1087
  };
1076
1088
 
1077
1089
  // ========================================================================================================
package/lib/generate.js CHANGED
@@ -686,6 +686,7 @@ const getInputData = async (inputList, all, cacheDir, addHandler) => {
686
686
  // dataList for data type, before `add` we don't which one is tested, because using hash id
687
687
  const emptyData = getEmptyData(all, dataList);
688
688
  if (emptyData) {
689
+ Util.logDebug(`added empty files for all: ${EC.yellow(emptyData.length)}`);
689
690
  const coverageResults = await addHandler(emptyData);
690
691
  // after `add`
691
692
  if (coverageResults) {
@@ -782,7 +783,11 @@ const readCoverageData = (filePath, entryFilter, sourceCache) => {
782
783
 
783
784
  // filter node internal files, should no anonymous for nodejs
784
785
  coverageData = coverageData.filter((entry) => entry.url && entry.url.startsWith('file:'));
786
+
787
+ const lengthBefore = coverageData.length;
785
788
  coverageData = coverageData.filter(entryFilter);
789
+ const lengthAfter = coverageData.length;
790
+ Util.logFilter('entry filter (addFromDir):', lengthBefore, lengthAfter);
786
791
 
787
792
  if (!Util.isList(coverageData)) {
788
793
  // Util.logDebug('No coverage data after filter');
package/lib/index.js CHANGED
@@ -61,6 +61,9 @@ class CoverageReport {
61
61
  return;
62
62
  }
63
63
 
64
+ // before clean cache, do no call initOptions again in hasCache
65
+ this.fixedOptions = true;
66
+
64
67
  // init logging for clean after generated
65
68
  this.logging = Util.initLoggingLevel(this.options.logging);
66
69
 
@@ -79,7 +82,6 @@ class CoverageReport {
79
82
  this.cleanCache();
80
83
  }
81
84
 
82
- this.fixedOptions = true;
83
85
  }
84
86
 
85
87
  // add coverage data: {array} V8 format, {object} Istanbul format