monocart-coverage-reports 2.5.7 → 2.5.9

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/index.d.ts CHANGED
@@ -220,19 +220,41 @@ declare namespace MCR {
220
220
 
221
221
  /** (V8 only)
222
222
  *
223
- * {string} `minimatch` pattern for entry url; multiple patterns: "{pattern1,pattern2}";
223
+ * {string} `minimatch` pattern for entry url; {object} multiple patterns;
224
224
  *
225
225
  * {function} A filter function for each entry file in the V8 list.
226
226
  * */
227
- entryFilter?: string | ((entry: V8CoverageEntry) => boolean);
227
+ entryFilter?: string | {
228
+ [pattern: string]: boolean;
229
+ } | ((entry: V8CoverageEntry) => boolean);
228
230
 
229
231
  /** (V8 only)
230
232
  *
231
- * {string} `minimatch` pattern for source path; multiple patterns: "{pattern1,pattern2}";
233
+ * {string} `minimatch` pattern for source path; {object} multiple patterns;
232
234
  *
233
235
  * {function} A filter function for each source path when the source is unpacked from the source map.
234
236
  * */
235
- sourceFilter?: string | ((sourcePath: string) => boolean);
237
+ sourceFilter?: string | {
238
+ [pattern: string]: boolean;
239
+ } | ((sourcePath: string) => boolean);
240
+
241
+ /**
242
+ * options for adding empty coverage for all files
243
+ */
244
+ all?: string | string[] | {
245
+ /** the dir(s) of all files */
246
+ dir: string | string[];
247
+ /** the coverage data type, v8 or istanbul */
248
+ type?: "v8" | "istanbul";
249
+ /**
250
+ * the file filter, return the file type, if true, defaults to css if ".css" otherwise is js
251
+ *
252
+ * {string} `minimatch` pattern for file path; {object} multiple patterns; {function} A filter function for file path;
253
+ */
254
+ filter?: string | {
255
+ [pattern: string]: "js" | "css" | boolean;
256
+ } | ((filePath: string) => "js" | "css" | boolean)
257
+ };
236
258
 
237
259
  /** (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop */
238
260
  v8Ignore?: boolean;
@@ -258,9 +280,16 @@ declare namespace MCR {
258
280
  * {object} { bytes:[50,80], statements:[50,80], branches:[50,80], functions:[50,80], lines:[50,80] } */
259
281
  watermarks?: Watermarks;
260
282
 
261
- /** {boolean} clean previous files in output dir before generating report. Defaults to true. */
283
+ /** {boolean} Indicates whether to clean previous files in output dir before generating report. Defaults to true. */
262
284
  clean?: boolean;
263
285
 
286
+ /**
287
+ * {boolean} Indicates whether to clean previous cache in output dir before generating report. Defaults to false.
288
+ *
289
+ * If true, the API `cleanCache()` will execute automatically.
290
+ */
291
+ cleanCache?: boolean;
292
+
264
293
  /** {function} onEnd hook */
265
294
  onEnd?: (reportData: CoverageResults) => Promise<void>;
266
295
  }
package/lib/index.js CHANGED
@@ -14,6 +14,13 @@ class CoverageReport {
14
14
  ... defaultOptions,
15
15
  ... options
16
16
  };
17
+
18
+ this.initOptions();
19
+ // If true, the API `cleanCache()` will execute automatically.
20
+ if (this.options.cleanCache) {
21
+ this.cleanCache();
22
+ }
23
+
17
24
  }
18
25
 
19
26
  initOptions() {
@@ -83,7 +90,10 @@ class CoverageReport {
83
90
 
84
91
  this.initOptions();
85
92
 
86
- const { inputDir, cacheDir } = this.options;
93
+ const {
94
+ all, inputDir, cacheDir
95
+ } = this.options;
96
+
87
97
  const inputDirs = Util.toList(inputDir, ',');
88
98
  if (this.hasCache()) {
89
99
  inputDirs.push(cacheDir);
@@ -92,16 +102,16 @@ class CoverageReport {
92
102
  const inputList = inputDirs.filter((dir) => {
93
103
  const hasDir = fs.existsSync(dir);
94
104
  if (!hasDir) {
95
- Util.logError(`Not found coverage data dir: ${Util.relativePath(dir)}`);
105
+ // could be empty
106
+ Util.logInfo(`Not found coverage data dir: ${Util.relativePath(dir)}`);
96
107
  }
97
108
  return hasDir;
98
109
  });
99
110
 
100
- if (!inputList.length) {
101
- return;
102
- }
111
+ const { dataList, sourceCache } = await getInputData(inputList, all, cacheDir, (emptyData) => {
112
+ return this.add(emptyData);
113
+ });
103
114
 
104
- const { dataList, sourceCache } = await getInputData(inputList);
105
115
  if (!dataList.length) {
106
116
  const dirs = inputList.map((dir) => Util.relativePath(dir));
107
117
  Util.logError(`Not found coverage data in dir(s): ${dirs.join(', ')}`);