monocart-coverage-reports 2.7.10 → 2.8.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/lib/cli.js CHANGED
@@ -193,8 +193,11 @@ program
193
193
  .option('-o, --outputDir <dir>', 'output dir for reports')
194
194
  .option('-i, --inputDir <dir>', 'input dir for merging raw files')
195
195
 
196
+ .option('-a, --all <dir>', 'include all files from dir')
197
+
196
198
  .option('--entryFilter <pattern>', 'entry url filter')
197
199
  .option('--sourceFilter <pattern>', 'source path filter')
200
+ .option('--filter <pattern>', 'the combined filter')
198
201
 
199
202
  .option('--outputFile <path>', 'output file for v8 report')
200
203
  .option('--inline', 'inline html for v8 report')
@@ -943,7 +943,7 @@ const getOriginalDecodedMappings = (originalDecodedMap, sourceIndex, locator) =>
943
943
  // ========================================================================================================
944
944
 
945
945
  const getSourceFilter = (options) => {
946
- const input = options.sourceFilter;
946
+ let input = options.sourceFilter || options.filter;
947
947
 
948
948
  // for function handler
949
949
  if (typeof input === 'function') {
@@ -952,9 +952,17 @@ const getSourceFilter = (options) => {
952
952
 
953
953
  // for single minimatch pattern
954
954
  if (input && typeof input === 'string') {
955
- return (sourcePath) => {
956
- return minimatch(sourcePath, input);
957
- };
955
+ // string to multiple patterns "{...}"
956
+ // mcr npx mocha --sourceFilter {'**/node_modules/**':false,'**/src/*.js':true}
957
+ // mcr npx mocha --sourceFilter "{'**/node_modules/**': false, '**/src/*.js': true}"
958
+ const obj = Util.strToObj(input);
959
+ if (obj) {
960
+ input = obj;
961
+ } else {
962
+ return (sourcePath) => {
963
+ return minimatch(sourcePath, input);
964
+ };
965
+ }
958
966
  }
959
967
 
960
968
  // for patterns
@@ -37,6 +37,9 @@ module.exports = {
37
37
  // sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
38
38
  sourceFilter: null,
39
39
 
40
+ // The combined filter for entryFilter and sourceFilter
41
+ filter: null,
42
+
40
43
  // {function} Source path handler.
41
44
  // sourcePath: (filePath) => `wwwroot/${filePath}`,
42
45
  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
- return (filePath) => {
505
- return minimatch(filePath, input);
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
- if (typeof input === 'string' || Array.isArray(input)) {
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
@@ -232,8 +232,8 @@ declare namespace MCR {
232
232
 
233
233
  /** (V8 only)
234
234
  *
235
- * {string} `minimatch` pattern for entry url; {object} multiple patterns;
236
- *
235
+ * {string} `minimatch` pattern for entry url;
236
+ * {object} multiple patterns;
237
237
  * {function} A filter function for each entry file in the V8 list.
238
238
  */
239
239
  entryFilter?: string | {
@@ -242,14 +242,21 @@ declare namespace MCR {
242
242
 
243
243
  /** (V8 only)
244
244
  *
245
- * {string} `minimatch` pattern for source path; {object} multiple patterns;
246
- *
245
+ * {string} `minimatch` pattern for source path;
246
+ * {object} multiple patterns;
247
247
  * {function} A filter function for each source path when the source is unpacked from the source map.
248
248
  */
249
249
  sourceFilter?: string | {
250
250
  [pattern: string]: boolean;
251
251
  } | ((sourcePath: string) => boolean);
252
252
 
253
+ /**
254
+ * The combined filter for entryFilter and sourceFilter
255
+ */
256
+ filter?: string | {
257
+ [pattern: string]: boolean;
258
+ } | ((input: string | V8CoverageEntry) => boolean);
259
+
253
260
  /**
254
261
  * {function} Source path handler.
255
262
  *
@@ -378,8 +385,6 @@ declare namespace MCR {
378
385
  'mcr.config.cjs',
379
386
  'mcr.config.mjs',
380
387
  'mcr.config.json',
381
- '.mcrrc.js',
382
- '.mcrrc',
383
388
  'mcr.config.ts'
384
389
  */
385
390
  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
- // order by priority
242
- const configList = customConfigFile ? [customConfigFile] : [
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
- // no config
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