monocart-reporter 1.7.0 → 1.7.1

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
@@ -123,8 +123,6 @@ Separated metadata file (Already included in the above HTML and compressed, it c
123
123
  coverage: null,
124
124
  // coverage: {
125
125
  // entryFilter: (entry) => true,
126
- // unpackSourceMap: true,
127
- // excludeDistFile: true,
128
126
  // sourceFilter: (sourceName) => sourceName.search(/src\/.+/) !== -1,
129
127
  // },
130
128
 
@@ -632,14 +630,12 @@ Attach a code coverage report with API `attachCoverageReport(data, testInfo, opt
632
630
  - `title` (String) report title.
633
631
  - `toIstanbul` (Boolean) Whether to convert to Istanbul report from V8 list.
634
632
  - `entryFilter` (Function) A filter function to execute for each element in the V8 list.
635
- - `unpackSourceMap` (Boolean) Whether to unpack all sources from the source map if a related source map file is found.
636
- - `excludeDistFile` (Boolean) Whether to exclude the dist file (usually minified) if the sources are successfully unpacked from the source map.
637
633
  - `sourceFilter` (Function) A filter function to execute for each element in the sources which unpacked from the source map.
638
634
  - `watermarks` (Object) Istanbul watermarks, see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report) | (Array) V8 watermarks, Defaults to `[50, 80]`.
639
635
  - `lcov` (Boolean) Whether to create `lcov.info`. Istanbul only.
640
636
  - `sourcePath` (Function) source path handler, return a new source path. Istanbul only.
641
- - `inline` (Boolean) Whether inline all scripts to the single HTML file.
642
- - `debug` (Boolean) The temporary artifacts will not be removed.
637
+ - `inline` (Boolean) Whether inline all scripts to the single HTML file. V8 only.
638
+ - `debug` (Boolean) The dist file which has source map will be included, and the temporary artifacts will not be removed.
643
639
 
644
640
  (see example: [report-coverage.spec.js](https://github.com/cenfun/monocart-reporter/blob/main/tests/report-coverage/report-coverage.spec.js))
645
641
 
@@ -705,7 +701,7 @@ test('Take V8 and Istanbul coverage report', async ({ page }) => {
705
701
  const coverageList = [... jsCoverage, ... cssCoverage];
706
702
 
707
703
  const v8 = await attachCoverageReport(coverageList, test.info(), {
708
- excludeDistFile: false
704
+ debug: true
709
705
  });
710
706
  console.log(v8.summary);
711
707
 
@@ -745,8 +741,6 @@ module.exports = {
745
741
  // global coverage report options
746
742
  coverage: {
747
743
  entryFilter: (entry) => true,
748
- unpackSourceMap: true,
749
- excludeDistFile: true,
750
744
  sourceFilter: (sourceName) => sourceName.search(/src\/.+/) !== -1,
751
745
  }
752
746
  }]
@@ -15,8 +15,6 @@ module.exports = {
15
15
  coverage: null,
16
16
  // coverage: {
17
17
  // entryFilter: (entry) => true,
18
- // unpackSourceMap: true,
19
- // excludeDistFile: true,
20
18
  // sourceFilter: (sourceName) => sourceName.search(/src\/.+/) !== -1,
21
19
  // },
22
20
 
package/lib/index.d.ts CHANGED
@@ -44,11 +44,6 @@ export type CoverageReportOptions = {
44
44
  // A filter function to execute for each element in the V8 list.
45
45
  entryFilter?: (entry: any) => boolean,
46
46
 
47
- // Whether to unpack all sources from the source map if a related source map file is found.
48
- unpackSourceMap?: boolean,
49
- // Whether to exclude the dist file (usually minified) if the sources are successfully unpacked from the source map.
50
- excludeDistFile?: boolean,
51
-
52
47
  // A filter function to execute for each element in the sources which unpacked from the source map.
53
48
  sourceFilter?: (sourcePath: string) => boolean,
54
49
 
@@ -5,9 +5,12 @@ const EC = require('eight-colors');
5
5
  const Util = require('../../utils/util.js');
6
6
  const { convertV8ToIstanbul, saveIstanbulReport } = require('./istanbul/istanbul.js');
7
7
  const {
8
- initV8ListAndSourcemap, unpackV8List, mergeV8Coverage, saveV8Report
8
+ initV8ListAndSourcemap, mergeV8Coverage, saveV8Report
9
9
  } = require('./v8/v8.js');
10
10
 
11
+ const { convertFunctionsToRanges } = require('./coverage-utils.js');
12
+ const { unpackSourceMaps } = require('./v8/source-map.js');
13
+
11
14
  const defaultOptions = {
12
15
 
13
16
  // Defaults to test title
@@ -20,10 +23,7 @@ const defaultOptions = {
20
23
 
21
24
  // (Function) A filter function to execute for each element in the V8 list.
22
25
  entryFilter: null,
23
- // (Boolean) Whether to unpack all sources from the source map if a related source map file is found.
24
- unpackSourceMap: true,
25
- // (Boolean) Whether to exclude the dist file (usually minified) if the sources are successfully unpacked from the source map.
26
- excludeDistFile: true,
26
+
27
27
  // (Function) A filter function to execute for each element in the sources which unpacked from the source map.
28
28
  sourceFilter: null,
29
29
 
@@ -36,19 +36,35 @@ const defaultOptions = {
36
36
  sourceFinder: null,
37
37
 
38
38
  // (Boolean) Whether to create `lcov.info`
39
- lcov: false
39
+ lcov: false,
40
40
 
41
41
  // (Object) Istanbul watermarks, see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report)
42
42
  // watermarks: {},
43
43
  // (Array) V8 watermarks, Defaults to `[50, 80]`
44
44
  // watermarks: [50, 80],
45
45
 
46
- // (Boolean) Whether inline all scripts to the single HTML file.
47
- // inline: false,
46
+ // (Boolean) Whether inline all scripts to the single HTML file. V8 only.
47
+ inline: false,
48
48
 
49
- // debug: false
49
+ // (Boolean) The dist file which has source map will be included, and the temporary artifacts will not be removed.
50
+ debug: false
50
51
  };
51
52
 
53
+ // ========================================================================================================
54
+
55
+ const unpackV8List = async (v8list, options) => {
56
+ v8list.forEach((item, i) => {
57
+ if (item.type === 'js') {
58
+ item.ranges = convertFunctionsToRanges(item.functions);
59
+ delete item.functions;
60
+ }
61
+ });
62
+
63
+ // requires ranges before unpack
64
+ await unpackSourceMaps(v8list, options);
65
+
66
+ // console.log(v8list.length);
67
+ };
52
68
 
53
69
  // ========================================================================================================
54
70
 
@@ -101,7 +117,7 @@ const generateV8Coverage = async (v8list, testInfo, options) => {
101
117
  return report;
102
118
  }
103
119
 
104
- // ================================================================
120
+ // =================================================================
105
121
 
106
122
  // functions to ranges, and unpack source maps
107
123
  await unpackV8List(v8list, options);
@@ -222,6 +238,8 @@ const getGlobalCoverageData = async (dataList, options) => {
222
238
  const v8list = await mergeV8Coverage(dataList, options);
223
239
  // console.log('after merge', v8list.map((it) => it.url));
224
240
 
241
+ // ================================================================
242
+
225
243
  if (options.toIstanbul) {
226
244
 
227
245
  const { coverageData, fileSources } = await convertV8ToIstanbul(v8list, options);
@@ -233,6 +251,8 @@ const getGlobalCoverageData = async (dataList, options) => {
233
251
  return report;
234
252
  }
235
253
 
254
+ // ================================================================
255
+
236
256
  // functions to ranges, and unpack source maps
237
257
  await unpackV8List(v8list, options);
238
258
 
@@ -43,6 +43,12 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
43
43
 
44
44
  const coverageMap = istanbulLibCoverage.createCoverageMap(data);
45
45
 
46
+ const { watermarks, defaultSummarizer } = options;
47
+ const istanbulOptions = {
48
+ watermarks,
49
+ defaultSummarizer
50
+ };
51
+
46
52
  // https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report
47
53
  const contextOptions = {
48
54
  watermarks: {
@@ -55,7 +61,7 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
55
61
  // values can be nested/flat/pkg. Defaults to 'pkg'
56
62
  defaultSummarizer: 'nested',
57
63
 
58
- ... options,
64
+ ... istanbulOptions,
59
65
 
60
66
  dir: options.htmlDir,
61
67
  sourceFinder: (filePath) => {
@@ -90,7 +96,7 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
90
96
  // create a context for report generation
91
97
  const context = istanbulLibReport.createContext(contextOptions);
92
98
 
93
- const htmlReport = istanbulReports.create('html', {});
99
+ const htmlReport = istanbulReports.create('html-spa', {});
94
100
  htmlReport.execute(context);
95
101
 
96
102
  const htmlPath = Util.relativePath(path.resolve(options.htmlDir, 'index.html'));
@@ -388,10 +388,6 @@ const saveSourceFile = async (filePath, data) => {
388
388
 
389
389
  const collectSourceMaps = async (v8list, options, inlineSourceMap) => {
390
390
 
391
- if (!options.unpackSourceMap) {
392
- return;
393
- }
394
-
395
391
  if (inlineSourceMap) {
396
392
  await collectInlineSourceMaps(v8list);
397
393
  return;
@@ -420,12 +416,8 @@ const filterSourceMapList = (v8list, options) => {
420
416
  }
421
417
 
422
418
  // do not remove in debug mode
423
- if (options.debug) {
424
- return sourceMapList;
425
- }
426
-
427
- // remove dist file if found sourceMap
428
- if (options.excludeDistFile) {
419
+ if (!options.debug) {
420
+ // remove dist file if found sourceMap
429
421
  indexes.reverse();
430
422
  indexes.forEach((i) => {
431
423
  v8list.splice(i, 1);
@@ -438,11 +430,6 @@ const filterSourceMapList = (v8list, options) => {
438
430
  // requires ranges before unpack
439
431
  const unpackSourceMaps = async (v8list, options) => {
440
432
 
441
- // collect source maps
442
- if (!options.unpackSourceMap) {
443
- return;
444
- }
445
-
446
433
  const sourceMapList = filterSourceMapList(v8list, options);
447
434
  if (!sourceMapList) {
448
435
  // nothing to unpack
@@ -3,8 +3,8 @@ const EC = require('eight-colors');
3
3
  const Util = require('../../../utils/util.js');
4
4
  const { getV8Summary } = require('./v8-summary.js');
5
5
  const { dedupeRanges } = require('./dedupe.js');
6
- const { getSourcePath, convertFunctionsToRanges } = require('../coverage-utils.js');
7
- const { collectSourceMaps, unpackSourceMaps } = require('./source-map.js');
6
+ const { getSourcePath } = require('../coverage-utils.js');
7
+ const { collectSourceMaps } = require('./source-map.js');
8
8
  const { mergeScriptCovs } = require('../../../runtime/monocart-coverage.js');
9
9
 
10
10
 
@@ -70,22 +70,6 @@ const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
70
70
 
71
71
  // ========================================================================================================
72
72
 
73
- const unpackV8List = async (v8list, options) => {
74
- v8list.forEach((item, i) => {
75
- if (item.type === 'js') {
76
- item.ranges = convertFunctionsToRanges(item.functions);
77
- delete item.functions;
78
- }
79
- });
80
-
81
- // requires ranges before unpack
82
- await unpackSourceMaps(v8list, options);
83
-
84
- // console.log(v8list.length);
85
- };
86
-
87
- // ========================================================================================================
88
-
89
73
  // force to async
90
74
  const mergeCssRanges = (itemList) => {
91
75
  return new Promise((resolve) => {
@@ -262,7 +246,6 @@ const saveV8Report = async (v8list, options) => {
262
246
 
263
247
  module.exports = {
264
248
  initV8ListAndSourcemap,
265
- unpackV8List,
266
249
  mergeV8Coverage,
267
250
  saveV8Report
268
251
  };