monocart-coverage-reports 2.11.0 โ†’ 2.11.2

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
@@ -1,10 +1,12 @@
1
1
  # Monocart Coverage Reports
2
2
 
3
- [![](https://img.shields.io/npm/v/monocart-coverage-reports)](https://www.npmjs.com/package/monocart-coverage-reports)
4
- [![](https://devimg.vercel.app/npm/downloads/monocart-coverage-reports?label={total}%20downloads/month)](https://www.npmjs.com/package/monocart-coverage-reports)
5
- ![](https://img.shields.io/librariesio/github/cenfun/monocart-coverage-reports)
6
- ![](https://img.shields.io/github/license/cenfun/monocart-coverage-reports)
7
- ![](https://img.shields.io/github/actions/workflow/status/cenfun/monocart-coverage-reports/ci.yml)
3
+ [![npm](https://img.shields.io/npm/v/monocart-coverage-reports)](https://www.npmjs.com/package/monocart-coverage-reports)
4
+ ![license](https://img.shields.io/github/license/cenfun/monocart-coverage-reports)
5
+ ![build](https://img.shields.io/github/actions/workflow/status/cenfun/monocart-coverage-reports/ci.yml)
6
+ [![install size](https://packagephobia.com/badge?p=monocart-coverage-reports)](https://packagephobia.com/result?p=monocart-coverage-reports)
7
+ [![npm graph](https://img.shields.io/badge/npm-graph-blue)](https://npmgraph.js.org/?q=monocart-coverage-reports)
8
+ ![dependencies](https://img.shields.io/librariesio/github/cenfun/monocart-coverage-reports)
9
+ [![downloads](https://devimg.vercel.app/npm/downloads/monocart-coverage-reports?label={total}%20downloads/month)](https://www.npmjs.com/package/monocart-coverage-reports)
8
10
 
9
11
  ๐ŸŒ English | [็ฎ€ไฝ“ไธญๆ–‡](README.zh-Hans.md)
10
12
 
@@ -485,6 +487,16 @@ export interface ScriptCoverage {
485
487
  export type V8CoverageData = ScriptCoverage[];
486
488
  ```
487
489
 
490
+ | JavaScript Runtime | V8 Coverage | |
491
+ | :--------------| :----: | :---------------------- |
492
+ | Chrome (65%) | โœ… | Chromium-based |
493
+ | Safari (18%) | โŒ | |
494
+ | Edge (5%) | โœ… | Chromium-based |
495
+ | Firefox (2%) | โŒ | |
496
+ | Node.js | โœ… | |
497
+ | Deno | โŒ | [issue](https://github.com/denoland/deno/issues/23359) |
498
+ | Bun | โŒ | |
499
+
488
500
  ## Filtering Results
489
501
  ### Using `entryFilter` and `sourceFilter` to filter the results for V8 report
490
502
  When V8 coverage data collected, it actually contains the data of all entry files, for example:
package/README.zh-Hans.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Monocart Coverage Reports
2
2
 
3
- [![](https://img.shields.io/npm/v/monocart-coverage-reports)](https://www.npmjs.com/package/monocart-coverage-reports)
4
- [![](https://devimg.vercel.app/npm/downloads/monocart-coverage-reports?label={total}%20downloads/month)](https://www.npmjs.com/package/monocart-coverage-reports)
5
- ![](https://img.shields.io/librariesio/github/cenfun/monocart-coverage-reports)
6
- ![](https://img.shields.io/github/license/cenfun/monocart-coverage-reports)
7
- ![](https://img.shields.io/github/actions/workflow/status/cenfun/monocart-coverage-reports/ci.yml)
3
+ [![npm](https://img.shields.io/npm/v/monocart-coverage-reports)](https://www.npmjs.com/package/monocart-coverage-reports)
4
+ ![license](https://img.shields.io/github/license/cenfun/monocart-coverage-reports)
5
+ ![build](https://img.shields.io/github/actions/workflow/status/cenfun/monocart-coverage-reports/ci.yml)
6
+ [![install size](https://packagephobia.com/badge?p=monocart-coverage-reports)](https://packagephobia.com/result?p=monocart-coverage-reports)
7
+ [![npm graph](https://img.shields.io/badge/npm-graph-blue)](https://npmgraph.js.org/?q=monocart-coverage-reports)
8
+ ![dependencies](https://img.shields.io/librariesio/github/cenfun/monocart-coverage-reports)
9
+ [![downloads](https://devimg.vercel.app/npm/downloads/monocart-coverage-reports?label={total}%20downloads/month)](https://www.npmjs.com/package/monocart-coverage-reports)
8
10
 
9
11
  ๐ŸŒ [English](README.md) | ็ฎ€ไฝ“ไธญๆ–‡
10
12
 
@@ -489,6 +491,16 @@ export interface ScriptCoverage {
489
491
  export type V8CoverageData = ScriptCoverage[];
490
492
  ```
491
493
 
494
+ | JavaScript Runtime | V8 Coverage | |
495
+ | :--------------| :----: | :---------------------- |
496
+ | Chrome (65%) | โœ… | Chromium-based |
497
+ | Safari (18%) | โŒ | |
498
+ | Edge (5%) | โœ… | Chromium-based |
499
+ | Firefox (2%) | โŒ | |
500
+ | Node.js | โœ… | |
501
+ | Deno | โŒ | [issue](https://github.com/denoland/deno/issues/23359) |
502
+ | Bun | โŒ | |
503
+
492
504
  ## Filtering Results
493
505
  ## Using `entryFilter` and `sourceFilter` to filter the results for V8 report
494
506
  ๅฝ“ๆ”ถ้›†ๅˆฐV8็š„่ฆ†็›–ๆ•ฐๆฎๆ—ถ๏ผŒๅฎƒๅฎž้™…ไธŠๅŒ…ๅซไบ†ๆ‰€ๆœ‰็š„ๅ…ฅๅฃๆ–‡ไปถ็š„่ฆ†็›–็އๆ•ฐๆฎ, ๆฏ”ๅฆ‚ๆœ‰ไปฅไธ‹3ไธชๆ–‡ไปถ:
@@ -1348,7 +1348,7 @@ const convertCoverages = (list, options, untested) => {
1348
1348
  }
1349
1349
  }
1350
1350
 
1351
- logConvertTime(` โ”Œ [convert] parsed ast: ${sourcePath} (${EC.cyan(Util.BSF(maxContentLength))})`, time_start_ast, untested);
1351
+ logConvertTime(`${EC.magenta('โ”‚ ')}${EC.cyan('โ”œ')} [convert] parsed ast: ${sourcePath} (${EC.cyan(Util.BSF(maxContentLength))})`, time_start_ast, untested);
1352
1352
 
1353
1353
  // console.log(sourcePath, astInfo.statements.length);
1354
1354
  // ============================
@@ -1390,7 +1390,7 @@ const convertCoverages = (list, options, untested) => {
1390
1390
 
1391
1391
  stateList.push(state);
1392
1392
 
1393
- logConvertTime(` โ”Œ [convert] unpacked sourcemap: ${sourcePath} (${unpackedFiles})`, time_start_unpack, untested);
1393
+ logConvertTime(`${EC.magenta('โ”‚ ')}${EC.cyan('โ”œ')} [convert] unpacked sourcemap: ${sourcePath} (${unpackedFiles})`, time_start_unpack, untested);
1394
1394
 
1395
1395
  }
1396
1396
 
@@ -1616,7 +1616,7 @@ const addUntestedFiles = async (stateList, options) => {
1616
1616
 
1617
1617
  // console.log('untestedList', untestedList);
1618
1618
 
1619
- Util.logTime(` โ”Œ [convert] added untested files: ${EC.yellow(untestedList.length)}`, time_start_untested);
1619
+ Util.logTime(`${EC.magenta('โ”‚ ')}${EC.cyan('โ”œ')} [convert] added untested files: ${EC.yellow(untestedList.length)}`, time_start_untested);
1620
1620
 
1621
1621
 
1622
1622
  };
@@ -1708,7 +1708,7 @@ const convertV8List = async (v8list, options) => {
1708
1708
  const time_start_convert = Date.now();
1709
1709
  const dataList = generateV8DataList(stateList, options);
1710
1710
  const dataFiles = EC.cyan(`${dataList.v8DataList.length} files`);
1711
- Util.logTime(` โ”Œ [convert] converted data list (${dataFiles})`, time_start_convert);
1711
+ Util.logTime(`${EC.magenta('โ”‚ ')}${EC.cyan('โ”œ')} [convert] converted data list (${dataFiles})`, time_start_convert);
1712
1712
 
1713
1713
  return dataList;
1714
1714
  };
@@ -88,6 +88,9 @@ module.exports = {
88
88
  // {boolean} Indicates whether to clean previous cache in output dir before generating report. Defaults to false.
89
89
  cleanCache: false,
90
90
 
91
+ // {number} gc threshold
92
+ gc: null,
93
+
91
94
  // {function} onEntry hook
92
95
  // onEntry: async (entry) => {}
93
96
  onEntry: null,
package/lib/generate.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { fileURLToPath } = require('url');
4
+ const EC = require('eight-colors');
4
5
 
5
6
  const Util = require('./utils/util.js');
6
7
  const { convertV8List } = require('./converter/converter.js');
@@ -172,12 +173,12 @@ const getCoverageResults = async (dataList, sourceCache, options) => {
172
173
  // merge v8list first
173
174
  const t1 = Date.now();
174
175
  const v8list = await mergeV8Coverage(dataList, sourceCache, options);
175
- Util.logTime('โ”Œ [generate] merged v8 coverage data', t1);
176
+ Util.logTime(`${EC.magenta('โ”œ')} [generate] merged v8 coverage data`, t1);
176
177
  // console.log('after merge', v8list.map((it) => it.url));
177
178
 
178
179
  const t2 = Date.now();
179
180
  const results = await convertV8List(v8list, options);
180
- Util.logTime('โ”Œ [generate] converted coverage data', t2);
181
+ Util.logTime(`${EC.magenta('โ”œ')} [generate] converted coverage data`, t2);
181
182
 
182
183
  const {
183
184
  v8DataList, coverageData, fileSources
@@ -189,7 +190,7 @@ const getCoverageResults = async (dataList, sourceCache, options) => {
189
190
  const t3 = Date.now();
190
191
  const istanbulData = await mergeIstanbulCoverage(dataList, options);
191
192
  const { coverageData, fileSources } = initIstanbulData(istanbulData, options);
192
- Util.logTime('โ”Œ [generate] prepared istanbul coverage data', t3);
193
+ Util.logTime(`${EC.magenta('โ”œ')} [generate] prepared istanbul coverage data`, t3);
193
194
  const results = await saveIstanbulReports(coverageData, fileSources, options);
194
195
  return results;
195
196
  };
@@ -210,7 +211,7 @@ const generateCoverageReports = async (dataList, sourceCache, options) => {
210
211
  } else {
211
212
  await customReport(reportName, coverageResults, reportOptions, options);
212
213
  }
213
- Util.logTime(`โ”Œ [generate] saved report: ${reportName}`, t1);
214
+ Util.logTime(`${EC.magenta('โ”œ')} [generate] saved report: ${reportName}`, t1);
214
215
  }
215
216
  }
216
217
 
@@ -340,7 +341,7 @@ const resolveEntrySource = (entry, sourceMapCache, sourceCache) => {
340
341
  const url = entry.url;
341
342
 
342
343
  // source from `source-id.json`
343
- const sourceData = sourceCache[url];
344
+ const sourceData = sourceCache.get(url);
344
345
  if (sourceData) {
345
346
  entry.source = sourceData.source;
346
347
  return;
@@ -424,7 +425,7 @@ const readCoverageData = async (dir, filename, entryFilter, sourceCache) => {
424
425
  };
425
426
 
426
427
  const readSourceList = async (dir, sourceList) => {
427
- const sourceCache = {};
428
+ const sourceCache = new Map();
428
429
 
429
430
  for (const filename of sourceList) {
430
431
  const content = await Util.readFile(path.resolve(dir, filename));
@@ -436,7 +437,7 @@ const readSourceList = async (dir, sourceList) => {
436
437
  continue;
437
438
  }
438
439
  if (json.url) {
439
- sourceCache[json.url] = json;
440
+ sourceCache.set(json.url, json);
440
441
  }
441
442
  }
442
443
 
@@ -476,16 +477,16 @@ const readFromDir = async (mcr, dir) => {
476
477
 
477
478
  const entryFilter = mcr.getEntryFilter();
478
479
 
479
- const results = [];
480
480
  for (const filename of coverageList) {
481
481
  const coverageData = await readCoverageData(dir, filename, entryFilter, sourceCache);
482
482
  if (coverageData) {
483
- const res = await mcr.add(coverageData);
484
- results.push(res);
483
+ await mcr.add(coverageData);
485
484
  }
486
485
  }
487
486
 
488
- return results;
487
+ // GC
488
+ sourceCache.clear();
489
+
489
490
  };
490
491
 
491
492
  module.exports = {
package/lib/index.d.ts CHANGED
@@ -404,6 +404,13 @@ declare namespace MCR {
404
404
  */
405
405
  cleanCache?: boolean;
406
406
 
407
+ /**
408
+ * {number} gc threshold
409
+ * for example: sets gc to 1024 means that force gc when the memory > 1024M at certain critical stages
410
+ * https://nodejs.org/docs/latest/api/v8.html#v8setflagsfromstringflags
411
+ */
412
+ gc?: number;
413
+
407
414
  /** (V8 only) {function} onEntry hook */
408
415
  onEntry?: (entry: V8CoverageEntry) => Promise<void>;
409
416
 
package/lib/index.js CHANGED
@@ -68,6 +68,10 @@ class CoverageReport {
68
68
  // init logging for clean after generated
69
69
  this.logging = Util.initLoggingLevel(this.options.logging);
70
70
 
71
+ if (Util.isNum(this.options.gc)) {
72
+ Util.setGC(this.options.gc);
73
+ }
74
+
71
75
  // init outputDir
72
76
  const outputDir = `${this.options.outputDir || defaultOptions.outputDir}`;
73
77
  this.options.outputDir = outputDir;
@@ -124,9 +128,8 @@ class CoverageReport {
124
128
  // add coverage from dir
125
129
  async addFromDir(dir) {
126
130
  const time_start = Date.now();
127
- const results = await readFromDir(this, dir);
131
+ await readFromDir(this, dir);
128
132
  Util.logTime(`added from dir: ${dir}`, time_start);
129
- return results;
130
133
  }
131
134
 
132
135
  // generate report
@@ -165,7 +168,7 @@ class CoverageReport {
165
168
  });
166
169
  }
167
170
 
168
- Util.logTime('โ”Œ [generate] prepared coverage data', time_start);
171
+ Util.logTime(`${EC.magenta('โ”œ')} [generate] prepared coverage data`, time_start);
169
172
 
170
173
  const coverageResults = await generateCoverageReports(dataList, sourceCache, this.options);
171
174
 
@@ -249,7 +252,7 @@ class CoverageReport {
249
252
  return;
250
253
  }
251
254
 
252
- Util.logInfo(`Loaded: ${EC.cyan(configPath)}`);
255
+ Util.logInfo(`Loaded: ${EC.cyan(Util.relativePath(configPath))}`);
253
256
 
254
257
  // init options again
255
258
  this.options = {
@@ -3,6 +3,7 @@ const path = require('path');
3
3
  const istanbulReports = require('istanbul-reports');
4
4
  const istanbulLibCoverage = require('istanbul-lib-coverage');
5
5
  const istanbulLibReport = require('istanbul-lib-report');
6
+ const EC = require('eight-colors');
6
7
 
7
8
  const Util = require('../utils/util.js');
8
9
  const IstanbulSummary = require('./istanbul-summary.js');
@@ -95,7 +96,7 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
95
96
  const t1 = Date.now();
96
97
  const report = istanbulReports.create(reportName, reportOptions);
97
98
  report.execute(context);
98
- Util.logTime(`โ”Œ [generate] saved report: ${reportName}`, t1);
99
+ Util.logTime(`${EC.magenta('โ”œ')} [generate] saved report: ${reportName}`, t1);
99
100
  }
100
101
  }
101
102
 
@@ -144,7 +145,7 @@ const addUntestedFiles = async (istanbulData, options) => {
144
145
 
145
146
  };
146
147
 
147
- const mergeIstanbulDataList = (dataList) => {
148
+ const mergeIstanbulDataList = (dataList, options) => {
148
149
  const istanbulCoverageList = dataList.map((it) => it.data);
149
150
  const coverageMap = istanbulLibCoverage.createCoverageMap();
150
151
  istanbulCoverageList.forEach((coverage) => {
@@ -155,7 +156,7 @@ const mergeIstanbulDataList = (dataList) => {
155
156
  };
156
157
 
157
158
  const mergeIstanbulCoverage = async (dataList, options) => {
158
- const istanbulData = mergeIstanbulDataList(dataList);
159
+ const istanbulData = mergeIstanbulDataList(dataList, options);
159
160
  await addUntestedFiles(istanbulData, options);
160
161
  return istanbulData;
161
162
  };