monocart-coverage-reports 2.8.5 â 2.8.6
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 +1 -1
- package/README.zh-Hans.md +1 -1
- package/lib/converter/collect-source-maps.js +15 -22
- package/lib/converter/converter.js +31 -15
- package/lib/converter/find-original-range.js +81 -33
- package/lib/default/template.html +1 -1
- package/lib/generate.js +161 -71
- package/lib/index.js +20 -40
- package/lib/istanbul/istanbul.js +2 -0
- package/lib/packages/monocart-coverage-app.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +26 -23
- package/lib/platform/share.js +7 -10
- package/lib/utils/util.js +13 -7
- package/lib/v8/v8.js +23 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/monocart-coverage-reports)
|
|
5
5
|

|
|
6
6
|

|
|
7
|
-

|
|
8
8
|
|
|
9
9
|
đ English | [įŽäŊ䏿](README.zh-Hans.md)
|
|
10
10
|
|
package/README.zh-Hans.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/monocart-coverage-reports)
|
|
5
5
|

|
|
6
6
|

|
|
7
|
-

|
|
8
8
|
|
|
9
9
|
đ [English](README.md) | įŽäŊ䏿
|
|
10
10
|
|
|
@@ -128,18 +128,6 @@ const resolveSourceMap = (data, url) => {
|
|
|
128
128
|
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
const saveSourceFile = async (filePath, data) => {
|
|
132
|
-
await Util.writeFile(filePath, JSON.stringify(data));
|
|
133
|
-
|
|
134
|
-
// save source and sourcemap file for debug
|
|
135
|
-
// https://evanw.github.io/source-map-visualization
|
|
136
|
-
// if (data.sourceMap) {
|
|
137
|
-
// await Util.writeFile(`${filePath}.js`, data.source);
|
|
138
|
-
// await Util.writeFile(`${filePath}.js.map`, JSON.stringify(data.sourceMap));
|
|
139
|
-
// }
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
|
|
143
131
|
const getInlineSourceMap = (content) => {
|
|
144
132
|
let smc;
|
|
145
133
|
try {
|
|
@@ -153,7 +141,8 @@ const getInlineSourceMap = (content) => {
|
|
|
153
141
|
|
|
154
142
|
const collectSourceMaps = async (v8list, options) => {
|
|
155
143
|
|
|
156
|
-
const
|
|
144
|
+
const sourceList = [];
|
|
145
|
+
const sourcemapList = [];
|
|
157
146
|
const concurrency = new Concurrency();
|
|
158
147
|
for (const item of v8list) {
|
|
159
148
|
|
|
@@ -168,8 +157,8 @@ const collectSourceMaps = async (v8list, options) => {
|
|
|
168
157
|
delete item.sourceMap;
|
|
169
158
|
|
|
170
159
|
// source and sourceMap already saved
|
|
171
|
-
const
|
|
172
|
-
if (fs.existsSync(
|
|
160
|
+
const { cachePath } = Util.getCacheFileInfo('source', id, options.cacheDir);
|
|
161
|
+
if (fs.existsSync(cachePath)) {
|
|
173
162
|
continue;
|
|
174
163
|
}
|
|
175
164
|
|
|
@@ -192,11 +181,11 @@ const collectSourceMaps = async (v8list, options) => {
|
|
|
192
181
|
const smc = getInlineSourceMap(source);
|
|
193
182
|
if (smc) {
|
|
194
183
|
sourceData.sourceMap = resolveSourceMap(smc.sourcemap, url);
|
|
195
|
-
|
|
184
|
+
sourcemapList.push({
|
|
196
185
|
url,
|
|
197
186
|
inline: true
|
|
198
187
|
});
|
|
199
|
-
|
|
188
|
+
sourceList.push(sourceData);
|
|
200
189
|
continue;
|
|
201
190
|
}
|
|
202
191
|
// from url async
|
|
@@ -204,7 +193,6 @@ const collectSourceMaps = async (v8list, options) => {
|
|
|
204
193
|
if (sourceMapUrl) {
|
|
205
194
|
concurrency.addItem({
|
|
206
195
|
sourceMapUrl,
|
|
207
|
-
sourcePath,
|
|
208
196
|
sourceData
|
|
209
197
|
});
|
|
210
198
|
continue;
|
|
@@ -212,7 +200,7 @@ const collectSourceMaps = async (v8list, options) => {
|
|
|
212
200
|
}
|
|
213
201
|
|
|
214
202
|
// no need check sourceMap
|
|
215
|
-
|
|
203
|
+
sourceList.push(sourceData);
|
|
216
204
|
|
|
217
205
|
}
|
|
218
206
|
|
|
@@ -223,15 +211,20 @@ const collectSourceMaps = async (v8list, options) => {
|
|
|
223
211
|
const data = await loadSourceMap(sourceMapUrl);
|
|
224
212
|
if (data) {
|
|
225
213
|
sourceData.sourceMap = resolveSourceMap(data, url);
|
|
226
|
-
|
|
214
|
+
sourcemapList.push({
|
|
227
215
|
url,
|
|
228
216
|
sourceMapUrl
|
|
229
217
|
});
|
|
230
218
|
}
|
|
231
|
-
|
|
219
|
+
|
|
220
|
+
sourceList.push(sourceData);
|
|
221
|
+
|
|
232
222
|
});
|
|
233
223
|
|
|
234
|
-
return
|
|
224
|
+
return {
|
|
225
|
+
sourceList,
|
|
226
|
+
sourcemapList
|
|
227
|
+
};
|
|
235
228
|
|
|
236
229
|
};
|
|
237
230
|
|
|
@@ -1239,15 +1239,17 @@ const initJsCoverageList = (item) => {
|
|
|
1239
1239
|
inUncoveredRange.coveredList.push(range);
|
|
1240
1240
|
}
|
|
1241
1241
|
}
|
|
1242
|
-
|
|
1243
|
-
if (count === 0) {
|
|
1244
|
-
uncoveredBlocks.push({
|
|
1245
|
-
... range,
|
|
1246
|
-
index: i,
|
|
1247
|
-
ranges: block.ranges
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1242
|
+
return;
|
|
1250
1243
|
}
|
|
1244
|
+
|
|
1245
|
+
if (count === 0) {
|
|
1246
|
+
uncoveredBlocks.push({
|
|
1247
|
+
... range,
|
|
1248
|
+
index: i,
|
|
1249
|
+
ranges: block.ranges
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1251
1253
|
});
|
|
1252
1254
|
});
|
|
1253
1255
|
|
|
@@ -1283,7 +1285,7 @@ const initJsCoverageList = (item) => {
|
|
|
1283
1285
|
});
|
|
1284
1286
|
}
|
|
1285
1287
|
|
|
1286
|
-
ranges.splice
|
|
1288
|
+
ranges.splice(... args);
|
|
1287
1289
|
|
|
1288
1290
|
});
|
|
1289
1291
|
}
|
|
@@ -1493,6 +1495,8 @@ const convertV8List = (v8list, options) => {
|
|
|
1493
1495
|
for (const item of v8list) {
|
|
1494
1496
|
// console.log([item.id]);
|
|
1495
1497
|
|
|
1498
|
+
const time_start_ast = Date.now();
|
|
1499
|
+
|
|
1496
1500
|
const {
|
|
1497
1501
|
type, source, fake, sourcePath
|
|
1498
1502
|
} = item;
|
|
@@ -1513,7 +1517,6 @@ const convertV8List = (v8list, options) => {
|
|
|
1513
1517
|
}
|
|
1514
1518
|
|
|
1515
1519
|
// ============================
|
|
1516
|
-
const time_start_ast = Date.now();
|
|
1517
1520
|
// move functions and ranges to coverageList
|
|
1518
1521
|
let coverageList = [];
|
|
1519
1522
|
let astInfo;
|
|
@@ -1532,11 +1535,14 @@ const convertV8List = (v8list, options) => {
|
|
|
1532
1535
|
delete item.ranges;
|
|
1533
1536
|
}
|
|
1534
1537
|
}
|
|
1535
|
-
|
|
1538
|
+
|
|
1539
|
+
Util.logTime(` â [convert] parsed ast: ${sourcePath} (${EC.cyan(Util.BSF(maxContentLength))})`, time_start_ast);
|
|
1536
1540
|
|
|
1537
1541
|
// console.log(sourcePath, astInfo.statements.length);
|
|
1538
1542
|
// ============================
|
|
1539
1543
|
|
|
1544
|
+
const time_start_unpack = Date.now();
|
|
1545
|
+
|
|
1540
1546
|
// current file and it's sources from sourceMap
|
|
1541
1547
|
// see const originalState
|
|
1542
1548
|
const state = {
|
|
@@ -1549,7 +1555,11 @@ const convertV8List = (v8list, options) => {
|
|
|
1549
1555
|
locator,
|
|
1550
1556
|
maxContentLength,
|
|
1551
1557
|
decodedMappings: [],
|
|
1552
|
-
|
|
1558
|
+
rangeCache: new Map(),
|
|
1559
|
+
diffCache: new Map(),
|
|
1560
|
+
|
|
1561
|
+
// alignTextList: [],
|
|
1562
|
+
|
|
1553
1563
|
// coverage info
|
|
1554
1564
|
bytes: [],
|
|
1555
1565
|
functions: [],
|
|
@@ -1563,19 +1573,25 @@ const convertV8List = (v8list, options) => {
|
|
|
1563
1573
|
v8Data: item
|
|
1564
1574
|
};
|
|
1565
1575
|
|
|
1566
|
-
const time_start_unpack = Date.now();
|
|
1567
1576
|
unpackDistFile(item, state, options);
|
|
1568
1577
|
const unpackedFiles = EC.cyan(`${state.originalList.length} files`);
|
|
1569
|
-
Util.logTime(`- unpacked dist: ${sourcePath} (${unpackedFiles})`, time_start_unpack);
|
|
1570
1578
|
|
|
1571
1579
|
stateList.push(state);
|
|
1572
1580
|
|
|
1581
|
+
Util.logTime(` â [convert] unpacked sourcemap: ${sourcePath} (${unpackedFiles})`, time_start_unpack);
|
|
1582
|
+
|
|
1573
1583
|
}
|
|
1574
1584
|
|
|
1575
1585
|
const time_start_convert = Date.now();
|
|
1586
|
+
|
|
1576
1587
|
const dataList = generateV8DataList(stateList, options);
|
|
1577
1588
|
const dataFiles = EC.cyan(`${dataList.v8DataList.length} files`);
|
|
1578
|
-
|
|
1589
|
+
|
|
1590
|
+
// stateList.forEach((st, i) => {
|
|
1591
|
+
// Util.writeFileSync(`align-text-${i}.js`, `window.gridData = ${JSON.stringify(st.alignTextList, null, 4)}`);
|
|
1592
|
+
// });
|
|
1593
|
+
|
|
1594
|
+
Util.logTime(` â [convert] converted data list (${dataFiles})`, time_start_convert);
|
|
1579
1595
|
|
|
1580
1596
|
return dataList;
|
|
1581
1597
|
};
|
|
@@ -39,7 +39,16 @@ const findMapping = (list, offset) => {
|
|
|
39
39
|
|
|
40
40
|
// ========================================================================================================
|
|
41
41
|
|
|
42
|
-
const alignText = (gt, ot) => {
|
|
42
|
+
const alignText = (gt, ot, info) => {
|
|
43
|
+
|
|
44
|
+
const { diffCache } = info.state;
|
|
45
|
+
|
|
46
|
+
if (diffCache.has(gt)) {
|
|
47
|
+
const subMap = diffCache.get(gt);
|
|
48
|
+
if (subMap.has(ot)) {
|
|
49
|
+
return subMap.get(ot);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
43
52
|
|
|
44
53
|
const toList = (s) => {
|
|
45
54
|
return s.split('').map((v, i) => {
|
|
@@ -115,6 +124,15 @@ const alignText = (gt, ot) => {
|
|
|
115
124
|
mergeList(gList, oList);
|
|
116
125
|
}
|
|
117
126
|
|
|
127
|
+
if (diffCache.has(gt)) {
|
|
128
|
+
const subMap = diffCache.get(gt);
|
|
129
|
+
subMap.set(ot, gl);
|
|
130
|
+
} else {
|
|
131
|
+
const subMap = new Map();
|
|
132
|
+
diffCache.set(gt, subMap);
|
|
133
|
+
subMap.set(ot, gl);
|
|
134
|
+
}
|
|
135
|
+
|
|
118
136
|
// console.log(gl);
|
|
119
137
|
return gl;
|
|
120
138
|
};
|
|
@@ -136,10 +154,19 @@ const getWordEndPosition = (list, gp, direction) => {
|
|
|
136
154
|
}
|
|
137
155
|
};
|
|
138
156
|
|
|
139
|
-
const getAlignPosition = (
|
|
157
|
+
const getAlignPosition = (info, direction) => {
|
|
158
|
+
|
|
159
|
+
const gt = info.generatedText;
|
|
160
|
+
const gp = info.generatedPos;
|
|
161
|
+
const ot = info.originalText;
|
|
162
|
+
|
|
163
|
+
// const alignTextItem = {
|
|
164
|
+
// gt, ot, gp
|
|
165
|
+
// };
|
|
166
|
+
// info.state.alignTextList.push(it);
|
|
140
167
|
|
|
141
168
|
// there is no need to align for long text
|
|
142
|
-
const maxLength =
|
|
169
|
+
const maxLength = 100;
|
|
143
170
|
if (gt.length > maxLength || ot.length > maxLength) {
|
|
144
171
|
// console.log(gt.length, ot.length, gp);
|
|
145
172
|
return;
|
|
@@ -155,16 +182,16 @@ const getAlignPosition = (gt, gp, ot, direction) => {
|
|
|
155
182
|
// generatedText: '1;else',
|
|
156
183
|
// generatedLeft: '1;'
|
|
157
184
|
|
|
158
|
-
// generatedText: ' var id = options.base ? item[0] + options.base : item[0];\r\n',
|
|
159
|
-
// originalText: ' var id = options.base ? item[0] + options.base : item[0];\n',
|
|
160
|
-
|
|
161
185
|
// right matched
|
|
162
186
|
// only for original first line text
|
|
163
187
|
|
|
164
188
|
// exclusive
|
|
165
|
-
const list = alignText(gt, ot);
|
|
189
|
+
const list = alignText(gt, ot, info);
|
|
166
190
|
const item = list[gp];
|
|
167
191
|
if (item && item.original) {
|
|
192
|
+
|
|
193
|
+
// alignTextItem.op = item.original.index;
|
|
194
|
+
|
|
168
195
|
return {
|
|
169
196
|
pos: item.original.index
|
|
170
197
|
};
|
|
@@ -280,10 +307,15 @@ const getComparedPosition = (info, direction) => {
|
|
|
280
307
|
}
|
|
281
308
|
|
|
282
309
|
// =============================
|
|
283
|
-
// trim
|
|
284
|
-
|
|
285
|
-
const
|
|
310
|
+
// trim
|
|
311
|
+
|
|
312
|
+
const gtt = gt.trim();
|
|
313
|
+
// no generated content after trim
|
|
314
|
+
if (!gtt) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
286
317
|
|
|
318
|
+
const ott = ot.trim();
|
|
287
319
|
// no original content after trim
|
|
288
320
|
if (!ott) {
|
|
289
321
|
return {
|
|
@@ -291,21 +323,21 @@ const getComparedPosition = (info, direction) => {
|
|
|
291
323
|
};
|
|
292
324
|
}
|
|
293
325
|
|
|
294
|
-
// no generated content after trim
|
|
295
|
-
if (!gtt) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
326
|
// same content
|
|
300
327
|
if (gtt === ott) {
|
|
328
|
+
// fix indent
|
|
329
|
+
const blankBlock = /\S/;
|
|
330
|
+
const gi = gt.search(blankBlock);
|
|
331
|
+
const oi = ot.search(blankBlock);
|
|
332
|
+
|
|
301
333
|
return {
|
|
302
|
-
pos: gp
|
|
334
|
+
pos: gp - gi + oi
|
|
303
335
|
};
|
|
304
336
|
}
|
|
305
337
|
|
|
306
338
|
// =============================
|
|
307
339
|
|
|
308
|
-
return getAlignPosition(
|
|
340
|
+
return getAlignPosition(info, direction);
|
|
309
341
|
|
|
310
342
|
};
|
|
311
343
|
|
|
@@ -325,7 +357,7 @@ const getSimilarPosition = (info, direction) => {
|
|
|
325
357
|
}
|
|
326
358
|
|
|
327
359
|
// no need comparison for fake source
|
|
328
|
-
if (info.fake) {
|
|
360
|
+
if (info.state.fake) {
|
|
329
361
|
return;
|
|
330
362
|
}
|
|
331
363
|
|
|
@@ -388,31 +420,48 @@ const getOriginalText = (m1, m2, cache) => {
|
|
|
388
420
|
|
|
389
421
|
const o1 = m1.originalOffset;
|
|
390
422
|
const o2 = m2.originalOffset;
|
|
423
|
+
const sameLine = m2.originalLine === m1.originalLine;
|
|
391
424
|
|
|
392
425
|
// o1 < o2: most of time
|
|
393
426
|
if (o1 < o2) {
|
|
427
|
+
|
|
428
|
+
// could be in comments
|
|
429
|
+
// it must be wrong sourcemap, do not fix it here
|
|
430
|
+
// if (originalLocator.lineParser.commentParser.isComment(o1, o2)) {
|
|
431
|
+
// console.log('in comments', originalLocator.getSlice(o1, o2), originalLocator.offsetToLocation(o1), originalLocator.offsetToLocation(o2), cache.originalState.sourcePath);
|
|
432
|
+
// return {
|
|
433
|
+
// originalOffset: o1,
|
|
434
|
+
// originalText: ''
|
|
435
|
+
// };
|
|
436
|
+
// }
|
|
437
|
+
|
|
438
|
+
if (sameLine) {
|
|
439
|
+
return {
|
|
440
|
+
originalOffset: o1,
|
|
441
|
+
originalText: originalLocator.getSlice(o1, o2)
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
394
445
|
// could be multiple lines for original text
|
|
395
446
|
return {
|
|
396
447
|
originalOffset: o1,
|
|
397
|
-
originalText: originalLocator.getSlice(o1,
|
|
448
|
+
originalText: originalLocator.getSlice(o1, getOriginalEndOffset(m1, cache))
|
|
398
449
|
};
|
|
399
450
|
}
|
|
400
451
|
|
|
401
452
|
// esbuild fixing two mapping have same original
|
|
402
453
|
// m1 to end line
|
|
403
454
|
if (o1 === o2) {
|
|
404
|
-
const originalEndOffset = getOriginalEndOffset(m1, cache);
|
|
405
455
|
return {
|
|
406
456
|
originalOffset: o1,
|
|
407
|
-
originalText: originalLocator.getSlice(o1,
|
|
457
|
+
originalText: originalLocator.getSlice(o1, getOriginalEndOffset(m1, cache))
|
|
408
458
|
};
|
|
409
459
|
}
|
|
410
460
|
|
|
411
461
|
// o1 > o2: should be wrong sourcemap
|
|
412
462
|
|
|
413
|
-
// just reverse offsets if
|
|
414
|
-
|
|
415
|
-
if (crossLines < 2) {
|
|
463
|
+
// just reverse offsets if same line
|
|
464
|
+
if (sameLine) {
|
|
416
465
|
return {
|
|
417
466
|
originalOffset: o2,
|
|
418
467
|
originalText: originalLocator.getSlice(o2, o1)
|
|
@@ -426,10 +475,9 @@ const getOriginalText = (m1, m2, cache) => {
|
|
|
426
475
|
// }
|
|
427
476
|
|
|
428
477
|
// should be wrong, ignore m2
|
|
429
|
-
const originalEndOffset = getOriginalEndOffset(m1, cache);
|
|
430
478
|
return {
|
|
431
479
|
originalOffset: o1,
|
|
432
|
-
originalText: originalLocator.getSlice(o1,
|
|
480
|
+
originalText: originalLocator.getSlice(o1, getOriginalEndOffset(m1, cache))
|
|
433
481
|
};
|
|
434
482
|
|
|
435
483
|
};
|
|
@@ -505,7 +553,7 @@ const getFixedOriginalStart = (start, mappings, state, cache) => {
|
|
|
505
553
|
const direction = 'start';
|
|
506
554
|
|
|
507
555
|
const info = {
|
|
508
|
-
|
|
556
|
+
state,
|
|
509
557
|
generatedText,
|
|
510
558
|
generatedPos,
|
|
511
559
|
originalText,
|
|
@@ -558,7 +606,7 @@ const getFixedOriginalEnd = (end, mappings, state, cache) => {
|
|
|
558
606
|
const direction = 'end';
|
|
559
607
|
|
|
560
608
|
const info = {
|
|
561
|
-
|
|
609
|
+
state,
|
|
562
610
|
offset: end,
|
|
563
611
|
generatedText,
|
|
564
612
|
generatedPos,
|
|
@@ -826,11 +874,11 @@ const getMappingInfo = (start, end, state) => {
|
|
|
826
874
|
|
|
827
875
|
const findOriginalRange = (start, end, state, originalMap) => {
|
|
828
876
|
|
|
829
|
-
const { sourcePath,
|
|
877
|
+
const { sourcePath, rangeCache } = state;
|
|
830
878
|
|
|
831
879
|
const key = `${start}_${end}`;
|
|
832
|
-
if (
|
|
833
|
-
return
|
|
880
|
+
if (rangeCache.has(key)) {
|
|
881
|
+
return rangeCache.get(key);
|
|
834
882
|
}
|
|
835
883
|
|
|
836
884
|
const createMappingError = (errors) => {
|
|
@@ -843,7 +891,7 @@ const findOriginalRange = (start, end, state, originalMap) => {
|
|
|
843
891
|
};
|
|
844
892
|
|
|
845
893
|
// cache error response
|
|
846
|
-
|
|
894
|
+
rangeCache.set(key, res);
|
|
847
895
|
|
|
848
896
|
return res;
|
|
849
897
|
};
|
|
@@ -884,7 +932,7 @@ const findOriginalRange = (start, end, state, originalMap) => {
|
|
|
884
932
|
};
|
|
885
933
|
|
|
886
934
|
// cache response
|
|
887
|
-
|
|
935
|
+
rangeCache.set(key, res);
|
|
888
936
|
|
|
889
937
|
return res;
|
|
890
938
|
|