monocart-coverage-reports 2.7.10 → 2.8.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 +45 -56
- package/README.zh-Hans.md +1035 -0
- package/lib/cli.js +4 -0
- package/lib/converter/converter.js +14 -9
- package/lib/default/options.js +6 -0
- package/lib/generate.js +20 -5
- package/lib/index.d.ts +14 -6
- package/lib/index.js +3 -16
- package/lib/istanbul/istanbul.js +2 -4
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +32 -32
- package/lib/platform/share.js +0 -4
- package/lib/utils/source-path.js +22 -14
- package/lib/utils/util.js +54 -1
- package/lib/v8/v8.js +19 -9
- package/package.json +101 -100
package/lib/cli.js
CHANGED
|
@@ -192,9 +192,13 @@ program
|
|
|
192
192
|
|
|
193
193
|
.option('-o, --outputDir <dir>', 'output dir for reports')
|
|
194
194
|
.option('-i, --inputDir <dir>', 'input dir for merging raw files')
|
|
195
|
+
.option('-b, --baseDir <dir>', 'base dir for normalizing path')
|
|
196
|
+
|
|
197
|
+
.option('-a, --all <dir>', 'include all files from dir')
|
|
195
198
|
|
|
196
199
|
.option('--entryFilter <pattern>', 'entry url filter')
|
|
197
200
|
.option('--sourceFilter <pattern>', 'source path filter')
|
|
201
|
+
.option('--filter <pattern>', 'the combined filter')
|
|
198
202
|
|
|
199
203
|
.option('--outputFile <path>', 'output file for v8 report')
|
|
200
204
|
.option('--inline', 'inline html for v8 report')
|
|
@@ -16,9 +16,7 @@ const { getIgnoredRanges } = require('./ignore.js');
|
|
|
16
16
|
const {
|
|
17
17
|
sortRanges, dedupeCountRanges, mergeRangesWith
|
|
18
18
|
} = require('../utils/dedupe.js');
|
|
19
|
-
const {
|
|
20
|
-
getSourceType, getSourcePathHandler, initSourceMapSourcePath
|
|
21
|
-
} = require('../utils/source-path.js');
|
|
19
|
+
const { getSourceType, initSourceMapSourcesPath } = require('../utils/source-path.js');
|
|
22
20
|
const { decode, minimatch } = require('../packages/monocart-coverage-vendor.js');
|
|
23
21
|
|
|
24
22
|
const InfoBranch = require('./info-branch.js');
|
|
@@ -943,7 +941,7 @@ const getOriginalDecodedMappings = (originalDecodedMap, sourceIndex, locator) =>
|
|
|
943
941
|
// ========================================================================================================
|
|
944
942
|
|
|
945
943
|
const getSourceFilter = (options) => {
|
|
946
|
-
|
|
944
|
+
let input = options.sourceFilter || options.filter;
|
|
947
945
|
|
|
948
946
|
// for function handler
|
|
949
947
|
if (typeof input === 'function') {
|
|
@@ -952,9 +950,17 @@ const getSourceFilter = (options) => {
|
|
|
952
950
|
|
|
953
951
|
// for single minimatch pattern
|
|
954
952
|
if (input && typeof input === 'string') {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
}
|
|
953
|
+
// string to multiple patterns "{...}"
|
|
954
|
+
// mcr npx mocha --sourceFilter {'**/node_modules/**':false,'**/src/*.js':true}
|
|
955
|
+
// mcr npx mocha --sourceFilter "{'**/node_modules/**': false, '**/src/*.js': true}"
|
|
956
|
+
const obj = Util.strToObj(input);
|
|
957
|
+
if (obj) {
|
|
958
|
+
input = obj;
|
|
959
|
+
} else {
|
|
960
|
+
return (sourcePath) => {
|
|
961
|
+
return minimatch(sourcePath, input);
|
|
962
|
+
};
|
|
963
|
+
}
|
|
958
964
|
}
|
|
959
965
|
|
|
960
966
|
// for patterns
|
|
@@ -1103,8 +1109,7 @@ const unpackSourceMap = (state, options) => {
|
|
|
1103
1109
|
|
|
1104
1110
|
// keep original urls
|
|
1105
1111
|
const fileUrls = {};
|
|
1106
|
-
|
|
1107
|
-
initSourceMapSourcePath(sourceMap, fileUrls, sourcePath, sourcePathHandler);
|
|
1112
|
+
initSourceMapSourcesPath(fileUrls, sourceMap, sourcePath, options);
|
|
1108
1113
|
state.fileUrls = fileUrls;
|
|
1109
1114
|
|
|
1110
1115
|
// ===============================================
|
package/lib/default/options.js
CHANGED
|
@@ -24,6 +24,9 @@ module.exports = {
|
|
|
24
24
|
// {string|string[]} input raw dir(s)
|
|
25
25
|
inputDir: null,
|
|
26
26
|
|
|
27
|
+
// {string} base dir for normalizing the relative source path, defaults to cwd
|
|
28
|
+
baseDir: null,
|
|
29
|
+
|
|
27
30
|
// (V8 only) {function} A filter function to execute for each element in the V8 list.
|
|
28
31
|
// entryFilter: (entry) => {
|
|
29
32
|
// if (entry.url.indexOf('googleapis.com') !== -1) {
|
|
@@ -37,6 +40,9 @@ module.exports = {
|
|
|
37
40
|
// sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
|
|
38
41
|
sourceFilter: null,
|
|
39
42
|
|
|
43
|
+
// The combined filter for entryFilter and sourceFilter
|
|
44
|
+
filter: null,
|
|
45
|
+
|
|
40
46
|
// {function} Source path handler.
|
|
41
47
|
// sourcePath: (filePath) => `wwwroot/${filePath}`,
|
|
42
48
|
sourcePath: null,
|
package/lib/generate.js
CHANGED
|
@@ -501,9 +501,15 @@ const resolveAllFilter = (input) => {
|
|
|
501
501
|
|
|
502
502
|
// for single minimatch pattern
|
|
503
503
|
if (input && typeof input === 'string') {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
504
|
+
// string to multiple patterns "{...}"
|
|
505
|
+
const obj = Util.strToObj(input);
|
|
506
|
+
if (obj) {
|
|
507
|
+
input = obj;
|
|
508
|
+
} else {
|
|
509
|
+
return (filePath) => {
|
|
510
|
+
return minimatch(filePath, input);
|
|
511
|
+
};
|
|
512
|
+
}
|
|
507
513
|
}
|
|
508
514
|
|
|
509
515
|
// for patterns
|
|
@@ -543,9 +549,18 @@ const resolveAllOptions = (input, dataList) => {
|
|
|
543
549
|
let type;
|
|
544
550
|
let dir;
|
|
545
551
|
let filter;
|
|
546
|
-
|
|
552
|
+
|
|
553
|
+
if (typeof input === 'string') {
|
|
554
|
+
const obj = Util.strToObj(input);
|
|
555
|
+
if (obj) {
|
|
556
|
+
type = obj.type;
|
|
557
|
+
dir = obj.dir;
|
|
558
|
+
filter = obj.filter;
|
|
559
|
+
} else {
|
|
560
|
+
dir = input;
|
|
561
|
+
}
|
|
562
|
+
} else if (Array.isArray(input)) {
|
|
547
563
|
dir = input;
|
|
548
|
-
filter = () => true;
|
|
549
564
|
} else {
|
|
550
565
|
type = input.type;
|
|
551
566
|
dir = input.dir;
|
package/lib/index.d.ts
CHANGED
|
@@ -230,10 +230,13 @@ declare namespace MCR {
|
|
|
230
230
|
/** {string|string[]} input raw dir(s) */
|
|
231
231
|
inputDir?: string | string[];
|
|
232
232
|
|
|
233
|
+
/** {string} base dir for normalizing the relative source path, defaults to cwd */
|
|
234
|
+
baseDir?: string;
|
|
235
|
+
|
|
233
236
|
/** (V8 only)
|
|
234
237
|
*
|
|
235
|
-
* {string} `minimatch` pattern for entry url;
|
|
236
|
-
*
|
|
238
|
+
* {string} `minimatch` pattern for entry url;
|
|
239
|
+
* {object} multiple patterns;
|
|
237
240
|
* {function} A filter function for each entry file in the V8 list.
|
|
238
241
|
*/
|
|
239
242
|
entryFilter?: string | {
|
|
@@ -242,14 +245,21 @@ declare namespace MCR {
|
|
|
242
245
|
|
|
243
246
|
/** (V8 only)
|
|
244
247
|
*
|
|
245
|
-
* {string} `minimatch` pattern for source path;
|
|
246
|
-
*
|
|
248
|
+
* {string} `minimatch` pattern for source path;
|
|
249
|
+
* {object} multiple patterns;
|
|
247
250
|
* {function} A filter function for each source path when the source is unpacked from the source map.
|
|
248
251
|
*/
|
|
249
252
|
sourceFilter?: string | {
|
|
250
253
|
[pattern: string]: boolean;
|
|
251
254
|
} | ((sourcePath: string) => boolean);
|
|
252
255
|
|
|
256
|
+
/**
|
|
257
|
+
* The combined filter for entryFilter and sourceFilter
|
|
258
|
+
*/
|
|
259
|
+
filter?: string | {
|
|
260
|
+
[pattern: string]: boolean;
|
|
261
|
+
} | ((input: string | V8CoverageEntry) => boolean);
|
|
262
|
+
|
|
253
263
|
/**
|
|
254
264
|
* {function} Source path handler.
|
|
255
265
|
*
|
|
@@ -378,8 +388,6 @@ declare namespace MCR {
|
|
|
378
388
|
'mcr.config.cjs',
|
|
379
389
|
'mcr.config.mjs',
|
|
380
390
|
'mcr.config.json',
|
|
381
|
-
'.mcrrc.js',
|
|
382
|
-
'.mcrrc',
|
|
383
391
|
'mcr.config.ts'
|
|
384
392
|
*/
|
|
385
393
|
loadConfig: (configFile?: string) => Promise<void>;
|
package/lib/index.js
CHANGED
|
@@ -238,28 +238,15 @@ class CoverageReport {
|
|
|
238
238
|
// load config file
|
|
239
239
|
async loadConfig(customConfigFile) {
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
'mcr.config.js',
|
|
244
|
-
'mcr.config.cjs',
|
|
245
|
-
'mcr.config.mjs',
|
|
246
|
-
'mcr.config.json',
|
|
247
|
-
'mcr.config.ts',
|
|
248
|
-
'.mcrrc.js',
|
|
249
|
-
'.mcrrc'
|
|
250
|
-
];
|
|
251
|
-
|
|
252
|
-
const existsList = configList.filter((p) => p && fs.existsSync(p));
|
|
253
|
-
if (!existsList.length) {
|
|
241
|
+
const configPath = Util.findUpConfig(customConfigFile);
|
|
242
|
+
if (!configPath) {
|
|
254
243
|
if (customConfigFile) {
|
|
255
244
|
Util.logError(`The config file does not exist: ${customConfigFile}`);
|
|
256
245
|
}
|
|
257
|
-
//
|
|
246
|
+
// not found config
|
|
258
247
|
return;
|
|
259
248
|
}
|
|
260
249
|
|
|
261
|
-
// first one, high priority
|
|
262
|
-
const configPath = existsList[0];
|
|
263
250
|
const configOptions = await resolveConfigOptions(configPath);
|
|
264
251
|
if (!configOptions) {
|
|
265
252
|
// failed to load config options
|
package/lib/istanbul/istanbul.js
CHANGED
|
@@ -7,7 +7,7 @@ const istanbulLibReport = require('istanbul-lib-report');
|
|
|
7
7
|
const Util = require('../utils/util.js');
|
|
8
8
|
const IstanbulSummary = require('./istanbul-summary.js');
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const { initIstanbulSourcePath } = require('../utils/source-path.js');
|
|
11
11
|
|
|
12
12
|
const findHtmlPath = (outputDir) => {
|
|
13
13
|
const defaultHtml = path.resolve(outputDir, 'index.html');
|
|
@@ -129,9 +129,7 @@ const mergeIstanbulCoverage = (dataList) => {
|
|
|
129
129
|
const initIstanbulData = (istanbulData, options) => {
|
|
130
130
|
|
|
131
131
|
const fileSources = options.fileSources || {};
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, sourcePathHandler);
|
|
132
|
+
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, options);
|
|
135
133
|
|
|
136
134
|
return {
|
|
137
135
|
fileSources,
|