monocart-coverage-reports 2.10.9 → 2.11.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.
- package/README.md +13 -12
- package/README.zh-Hans.md +13 -11
- package/lib/cli.js +15 -0
- package/lib/converter/converter.js +1 -1
- package/lib/converter/flatten-source-maps.js +1 -1
- package/lib/converter/untested.js +315 -315
- package/lib/generate.js +52 -18
- package/lib/index.d.ts +2 -0
- package/lib/istanbul/istanbul.js +6 -2
- package/lib/packages/monocart-coverage-vendor.js +23 -23
- package/lib/reports/raw.js +85 -3
- package/lib/utils/dedupe.js +8 -3
- package/lib/utils/merge/merge.js +439 -0
- package/lib/utils/merge/range-tree.js +123 -0
- package/lib/utils/util.js +9 -0
- package/lib/v8/v8.js +13 -11
- package/package.json +118 -115
package/lib/generate.js
CHANGED
|
@@ -5,6 +5,7 @@ const { fileURLToPath } = require('url');
|
|
|
5
5
|
const Util = require('./utils/util.js');
|
|
6
6
|
const { convertV8List } = require('./converter/converter.js');
|
|
7
7
|
const { resolveSourceMap } = require('./converter/collect-source-maps.js');
|
|
8
|
+
const { StreamZip } = require('./packages/monocart-coverage-vendor.js');
|
|
8
9
|
|
|
9
10
|
// ========================================================================================================
|
|
10
11
|
// built-in reports
|
|
@@ -229,7 +230,7 @@ const getInputList = (mcr) => {
|
|
|
229
230
|
const hasDir = fs.existsSync(dir);
|
|
230
231
|
if (!hasDir) {
|
|
231
232
|
// could be empty
|
|
232
|
-
Util.logInfo(`
|
|
233
|
+
Util.logInfo(`Input coverage not exists: ${Util.relativePath(dir)}`);
|
|
233
234
|
}
|
|
234
235
|
return hasDir;
|
|
235
236
|
});
|
|
@@ -241,17 +242,16 @@ const getInputList = (mcr) => {
|
|
|
241
242
|
return inputList;
|
|
242
243
|
};
|
|
243
244
|
|
|
244
|
-
const addJsonData = async (mcr, dataList, sourceCache,
|
|
245
|
+
const addJsonData = async (mcr, dataList, sourceCache, input, filename) => {
|
|
245
246
|
const isCoverage = filename.startsWith('coverage-');
|
|
246
247
|
const isSource = filename.startsWith('source-');
|
|
247
248
|
if (isCoverage || isSource) {
|
|
248
|
-
let json;
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
json = JSON.parse(content);
|
|
249
|
+
let json = input;
|
|
250
|
+
if (typeof input === 'string') {
|
|
251
|
+
if (mcr.fileCache.has(filename)) {
|
|
252
|
+
json = mcr.fileCache.get(filename);
|
|
253
|
+
} else {
|
|
254
|
+
json = await Util.readJson(path.resolve(input, filename));
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
if (json) {
|
|
@@ -264,6 +264,41 @@ const addJsonData = async (mcr, dataList, sourceCache, dir, filename) => {
|
|
|
264
264
|
}
|
|
265
265
|
};
|
|
266
266
|
|
|
267
|
+
const addDirData = async (mcr, dataList, sourceCache, dir) => {
|
|
268
|
+
const allFiles = fs.readdirSync(dir);
|
|
269
|
+
if (!allFiles.length) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
for (const filename of allFiles) {
|
|
273
|
+
// only json file
|
|
274
|
+
if (filename.endsWith('.json')) {
|
|
275
|
+
await addJsonData(mcr, dataList, sourceCache, dir, filename);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const addZipData = async (mcr, dataList, sourceCache, dir) => {
|
|
281
|
+
const zip = new StreamZip({
|
|
282
|
+
file: dir
|
|
283
|
+
});
|
|
284
|
+
const entries = await zip.entries();
|
|
285
|
+
for (const entry of Object.values(entries)) {
|
|
286
|
+
if (entry.isDirectory) {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const entryName = entry.name;
|
|
290
|
+
const filename = path.basename(entryName);
|
|
291
|
+
// console.log('============================', filename);
|
|
292
|
+
if (filename.endsWith('.json')) {
|
|
293
|
+
const buf = await zip.entryData(entryName);
|
|
294
|
+
const json = JSON.parse(buf.toString('utf-8'));
|
|
295
|
+
await addJsonData(mcr, dataList, sourceCache, json, filename);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
// Do not forget to close the file once you're done
|
|
300
|
+
await zip.close();
|
|
301
|
+
};
|
|
267
302
|
|
|
268
303
|
const getInputData = async (mcr) => {
|
|
269
304
|
|
|
@@ -275,16 +310,15 @@ const getInputData = async (mcr) => {
|
|
|
275
310
|
|
|
276
311
|
for (const dir of inputList) {
|
|
277
312
|
|
|
278
|
-
const
|
|
279
|
-
if (
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
await addJsonData(mcr, dataList, sourceCache, dir, filename);
|
|
286
|
-
}
|
|
313
|
+
const info = fs.statSync(dir);
|
|
314
|
+
if (info.isDirectory()) {
|
|
315
|
+
await addDirData(mcr, dataList, sourceCache, dir);
|
|
316
|
+
} else if (info.isFile()) {
|
|
317
|
+
await addZipData(mcr, dataList, sourceCache, dir);
|
|
318
|
+
} else {
|
|
319
|
+
Util.logError(`Invalid input: ${dir}`);
|
|
287
320
|
}
|
|
321
|
+
|
|
288
322
|
}
|
|
289
323
|
|
|
290
324
|
if (!dataList.length) {
|
package/lib/index.d.ts
CHANGED
package/lib/istanbul/istanbul.js
CHANGED
|
@@ -144,16 +144,19 @@ const addUntestedFiles = async (istanbulData, options) => {
|
|
|
144
144
|
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
const
|
|
147
|
+
const mergeIstanbulDataList = (dataList) => {
|
|
148
148
|
const istanbulCoverageList = dataList.map((it) => it.data);
|
|
149
149
|
const coverageMap = istanbulLibCoverage.createCoverageMap();
|
|
150
150
|
istanbulCoverageList.forEach((coverage) => {
|
|
151
151
|
coverageMap.merge(coverage);
|
|
152
152
|
});
|
|
153
153
|
const istanbulData = coverageMap.toJSON();
|
|
154
|
+
return istanbulData;
|
|
155
|
+
};
|
|
154
156
|
|
|
157
|
+
const mergeIstanbulCoverage = async (dataList, options) => {
|
|
158
|
+
const istanbulData = mergeIstanbulDataList(dataList);
|
|
155
159
|
await addUntestedFiles(istanbulData, options);
|
|
156
|
-
|
|
157
160
|
return istanbulData;
|
|
158
161
|
};
|
|
159
162
|
|
|
@@ -169,6 +172,7 @@ const initIstanbulData = (istanbulData, options) => {
|
|
|
169
172
|
|
|
170
173
|
module.exports = {
|
|
171
174
|
saveIstanbulReports,
|
|
175
|
+
mergeIstanbulDataList,
|
|
172
176
|
mergeIstanbulCoverage,
|
|
173
177
|
initIstanbulData
|
|
174
178
|
};
|