monocart-reporter 1.7.12 → 2.0.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.
Files changed (42) hide show
  1. package/README.md +10 -26
  2. package/lib/generate-data.js +7 -19
  3. package/lib/generate-report.js +13 -6
  4. package/lib/index.d.ts +5 -46
  5. package/lib/index.js +1 -4
  6. package/lib/index.mjs +0 -1
  7. package/lib/packages/monocart-common.js +1 -0
  8. package/lib/packages/monocart-network.js +1 -0
  9. package/lib/packages/monocart-reporter.js +1 -0
  10. package/lib/packages/monocart-vendor.js +22 -0
  11. package/lib/platform/share.js +0 -5
  12. package/lib/plugins/audit/audit.js +2 -2
  13. package/lib/plugins/coverage/coverage.js +63 -249
  14. package/lib/plugins/network/network.js +17 -13
  15. package/lib/plugins/state/client.js +1 -1
  16. package/lib/plugins/state/state.js +1 -1
  17. package/lib/utils/parse-source.js +1 -1
  18. package/lib/utils/util.js +25 -38
  19. package/lib/visitor.js +6 -26
  20. package/package.json +10 -8
  21. package/lib/plugins/coverage/converter/collect-source-maps.js +0 -194
  22. package/lib/plugins/coverage/converter/converter.js +0 -565
  23. package/lib/plugins/coverage/converter/dedupe.js +0 -110
  24. package/lib/plugins/coverage/converter/find-original-range.js +0 -581
  25. package/lib/plugins/coverage/converter/info-branch.js +0 -30
  26. package/lib/plugins/coverage/converter/info-function.js +0 -29
  27. package/lib/plugins/coverage/converter/info-line.js +0 -20
  28. package/lib/plugins/coverage/converter/position-mapping.js +0 -183
  29. package/lib/plugins/coverage/converter/source-path.js +0 -140
  30. package/lib/plugins/coverage/istanbul/istanbul-summary.js +0 -49
  31. package/lib/plugins/coverage/istanbul/istanbul.js +0 -133
  32. package/lib/plugins/coverage/v8/v8-summary.js +0 -80
  33. package/lib/plugins/coverage/v8/v8.js +0 -260
  34. package/lib/runtime/monocart-code-viewer.js +0 -1
  35. package/lib/runtime/monocart-common.js +0 -1
  36. package/lib/runtime/monocart-coverage.js +0 -14
  37. package/lib/runtime/monocart-formatter.js +0 -1
  38. package/lib/runtime/monocart-network.js +0 -1
  39. package/lib/runtime/monocart-reporter.js +0 -1
  40. package/lib/runtime/monocart-v8.js +0 -1
  41. package/lib/runtime/monocart-vendor.js +0 -22
  42. package/lib/utils/decode-mappings.js +0 -49
@@ -1,260 +0,0 @@
1
- const Util = require('../../../utils/util.js');
2
- const { getV8Summary } = require('./v8-summary.js');
3
- const { dedupeRanges } = require('../converter/dedupe.js');
4
- const { getSourcePath } = require('../converter/source-path.js');
5
- const { mergeScriptCovs } = require('../../../runtime/monocart-coverage.js');
6
- const collectSourceMaps = require('../converter/collect-source-maps.js');
7
-
8
- const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
9
-
10
- // filter list first
11
- const entryFilter = options.entryFilter;
12
- if (typeof entryFilter === 'function') {
13
- v8list = v8list.filter(entryFilter);
14
- }
15
-
16
- // filter no source or text
17
- // init type and css source from text
18
- // keep functions
19
-
20
- v8list = v8list.filter((item) => {
21
- if (typeof item.source === 'string' && item.functions) {
22
- return true;
23
- }
24
- if (typeof item.text === 'string' && item.ranges) {
25
- return true;
26
- }
27
- // 404 css, text will be empty
28
- // Util.logError(`Invalid source: ${item.url}`);
29
- // console.log(item);
30
- });
31
-
32
-
33
- // do not change original v8list, to work for multiple APIs
34
-
35
- const sourcePathHandler = options.sourcePath;
36
-
37
- // init id, sourcePath
38
- v8list = v8list.map((item, i) => {
39
-
40
- const data = {
41
- url: item.url
42
- };
43
-
44
- if (item.functions) {
45
- data.type = 'js';
46
- data.functions = item.functions;
47
- data.source = item.source;
48
- // useless here
49
- // data.scriptId = item.scriptId;
50
- } else if (item.ranges) {
51
- data.type = 'css';
52
- data.ranges = item.ranges;
53
- data.source = item.text;
54
- }
55
-
56
- data.id = Util.calculateSha1(data.url + data.source);
57
-
58
- let sourcePath = getSourcePath(data.url, i + 1, data.type);
59
- if (typeof sourcePathHandler === 'function') {
60
- const newSourcePath = sourcePathHandler(sourcePath, data.url);
61
- if (typeof newSourcePath === 'string' && newSourcePath) {
62
- sourcePath = newSourcePath;
63
- }
64
- }
65
-
66
- data.sourcePath = sourcePath;
67
-
68
- return data;
69
- });
70
-
71
- // collect sourcemap first
72
- const time_start = Date.now();
73
- const count = await collectSourceMaps(v8list, options, inlineSourceMap);
74
- if (count) {
75
- Util.logTime(`loaded ${count} sourcemaps`, time_start);
76
- }
77
-
78
- return v8list;
79
- };
80
-
81
- // ========================================================================================================
82
-
83
- // force to async
84
- const mergeCssRanges = (itemList) => {
85
- return new Promise((resolve) => {
86
-
87
- let concatRanges = [];
88
- itemList.forEach((item) => {
89
- concatRanges = concatRanges.concat(item.ranges);
90
- });
91
-
92
- // ranges: [ {start, end} ]
93
- const ranges = dedupeRanges(concatRanges);
94
-
95
- resolve(ranges || []);
96
- });
97
- };
98
-
99
- const mergeJsFunctions = (itemList) => {
100
- return new Promise((resolve) => {
101
-
102
- const res = mergeScriptCovs(itemList);
103
- const functions = res && res.functions;
104
-
105
- resolve(functions || []);
106
- });
107
- };
108
-
109
- const mergeV8Coverage = async (dataList, options) => {
110
-
111
- let list = [];
112
- dataList.forEach((d) => {
113
- list = list.concat(d.data);
114
- });
115
-
116
- // console.log('before merge', list.map((it) => it.url));
117
-
118
- // connect all functions and ranges
119
- const itemMap = {};
120
- const mergeMap = {};
121
- list.forEach((item) => {
122
- const { id } = item;
123
- const prev = itemMap[id];
124
- if (prev) {
125
- if (mergeMap[id]) {
126
- mergeMap[id].push(item);
127
- } else {
128
- mergeMap[id] = [prev, item];
129
- }
130
- } else {
131
- itemMap[id] = item;
132
- }
133
- });
134
-
135
- // merge functions and ranges
136
- const mergeIds = Object.keys(mergeMap);
137
- for (const id of mergeIds) {
138
- const itemList = mergeMap[id];
139
- const item = itemMap[id];
140
- if (item.type === 'js') {
141
- item.functions = await mergeJsFunctions(itemList);
142
- } else {
143
- item.ranges = await mergeCssRanges(itemList);
144
- }
145
- }
146
-
147
- list = Object.values(itemMap);
148
-
149
- // try to load coverage and source by id
150
- for (const item of list) {
151
- const { id } = item;
152
- const sourcePath = Util.resolveArtifactSourcePath(options.artifactsDir, id);
153
- const content = await Util.readFile(sourcePath);
154
- if (content) {
155
- const json = JSON.parse(content);
156
- item.source = json.source;
157
- item.sourceMap = json.sourceMap;
158
- } else {
159
- Util.logError(`failed to read source: ${item.url}`);
160
- item.source = '';
161
- }
162
- }
163
-
164
- return list;
165
- };
166
-
167
- // ============================================================
168
-
169
- const saveV8HtmlReport = async (reportData, _options) => {
170
-
171
- const {
172
- htmlDir, outputDir, inline
173
- } = _options;
174
-
175
- const options = {
176
- inline,
177
- reportData,
178
- jsFiles: ['monocart-code-viewer.js', 'monocart-formatter.js', 'monocart-common.js', 'monocart-v8.js'],
179
- htmlDir,
180
- htmlFile: 'index.html',
181
-
182
- outputDir,
183
- reportDataFile: 'coverage-data.js',
184
- assetsRelative: '../'
185
- };
186
-
187
- const htmlPath = await Util.saveHtmlReport(options);
188
-
189
- return htmlPath;
190
- };
191
-
192
- const saveV8Report = async (v8list, options) => {
193
- options = {
194
-
195
- watermarks: [50, 80],
196
- inline: false,
197
-
198
- ... options
199
- };
200
-
201
- const watermarks = options.watermarks;
202
-
203
- // init summary
204
- v8list.forEach((entry) => {
205
- entry.summary = getV8Summary(entry);
206
- });
207
-
208
- // calculate pct, status and summary
209
- const summaryList = v8list.map((entry) => entry.summary);
210
- let total = 0;
211
- let covered = 0;
212
- summaryList.forEach((item) => {
213
-
214
- total += item.total;
215
- covered += item.covered;
216
-
217
- item.pct = Util.PNF(item.covered, item.total, 2);
218
- item.status = Util.getStatus(item.pct, watermarks);
219
-
220
- });
221
-
222
- const uncovered = total - covered;
223
-
224
- const pct = Util.PNF(covered, total, 2);
225
- const status = Util.getStatus(pct, watermarks);
226
-
227
- const summary = {
228
- total,
229
- covered,
230
- uncovered,
231
- pct,
232
- status
233
- };
234
-
235
- const htmlReport = {
236
- title: options.title,
237
- watermarks,
238
- summary,
239
- files: v8list
240
- };
241
-
242
- const htmlPath = await saveV8HtmlReport(htmlReport, options);
243
-
244
- const report = {
245
- title: options.title,
246
- type: 'v8',
247
- htmlPath,
248
- watermarks,
249
- summary,
250
- files: summaryList
251
- };
252
-
253
- return report;
254
- };
255
-
256
- module.exports = {
257
- initV8ListAndSourcemap,
258
- mergeV8Coverage,
259
- saveV8Report
260
- };