monocart-coverage-reports 2.10.5 → 2.10.7

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 CHANGED
@@ -967,6 +967,8 @@ process.env.MCR_LOG_TIME = true
967
967
  - Coverage for Next.js, both server side and client side:
968
968
  - [nextjs-with-playwright](https://github.com/cenfun/nextjs-with-playwright)
969
969
  - [nextjs-with-playwright-istanbul](https://github.com/cenfun/nextjs-with-playwright-istanbul)
970
+ - Coverage for Remix:
971
+ - [remix-with-playwright](https://github.com/cenfun/remix-with-playwright)
970
972
  - see [Collecting V8 Coverage Data with Playwright](#collecting-v8-coverage-data-with-playwright)
971
973
 
972
974
  ### [c8](https://github.com/bcoe/c8)
package/README.zh-Hans.md CHANGED
@@ -971,6 +971,8 @@ process.env.MCR_LOG_TIME = true
971
971
  - Coverage for Next.js, both server side and client side:
972
972
  - [nextjs-with-playwright](https://github.com/cenfun/nextjs-with-playwright)
973
973
  - [nextjs-with-playwright-istanbul](https://github.com/cenfun/nextjs-with-playwright-istanbul)
974
+ - Coverage for Remix:
975
+ - [remix-with-playwright](https://github.com/cenfun/remix-with-playwright)
974
976
  - see [Collecting V8 Coverage Data with Playwright](#collecting-v8-coverage-data-with-playwright)
975
977
 
976
978
  ### [c8](https://github.com/bcoe/c8)
@@ -21,7 +21,6 @@ const {
21
21
  const { getSourceType, initSourceMapSourcesPath } = require('../utils/source-path.js');
22
22
 
23
23
  const { decode } = require('@jridgewell/sourcemap-codec');
24
- const { minimatch } = require('../packages/monocart-coverage-vendor.js');
25
24
 
26
25
  const InfoBranch = require('./info-branch.js');
27
26
  const InfoFunction = require('./info-function.js');
@@ -956,50 +955,10 @@ const getOriginalDecodedMappings = (originalDecodedMap, sourceIndex, locator) =>
956
955
 
957
956
  // ========================================================================================================
958
957
 
959
- const getSourceFilter = (options) => {
960
- let input = options.sourceFilter || options.filter;
961
-
962
- // for function handler
963
- if (typeof input === 'function') {
964
- return input;
965
- }
966
-
967
- // for single minimatch pattern
968
- if (input && typeof input === 'string') {
969
- // string to multiple patterns "{...}"
970
- // mcr npx mocha --sourceFilter {'**/node_modules/**':false,'**/src/*.js':true}
971
- // mcr npx mocha --sourceFilter "{'**/node_modules/**': false, '**/src/*.js': true}"
972
- const obj = Util.strToObj(input);
973
- if (obj) {
974
- input = obj;
975
- } else {
976
- return (sourcePath) => {
977
- return minimatch(sourcePath, input);
978
- };
979
- }
980
- }
981
-
982
- // for patterns
983
- if (input && typeof input === 'object') {
984
- const patterns = Object.keys(input);
985
- return (sourcePath) => {
986
- for (const pattern of patterns) {
987
- if (minimatch(sourcePath, pattern)) {
988
- return input[pattern];
989
- }
990
- }
991
- // false if not matched
992
- };
993
- }
994
-
995
- // default
996
- return () => true;
997
- };
998
-
999
958
  const initOriginalList = (state, originalDecodedMap, options) => {
1000
959
 
1001
960
  // source filter
1002
- const sourceFilter = getSourceFilter(options);
961
+ const sourceFilter = Util.getSourceFilter(options);
1003
962
 
1004
963
  // create original content mappings
1005
964
  const originalStateMap = new Map();
@@ -5,7 +5,7 @@ const Util = require('../utils/util.js');
5
5
  const { pathToFileURL, fileURLToPath } = require('url');
6
6
 
7
7
  // const EC = require('eight-colors');
8
- const { minimatch, convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
8
+ const { minimatch } = require('../packages/monocart-coverage-vendor.js');
9
9
 
10
10
  // ========================================================================================================
11
11
 
@@ -109,63 +109,15 @@ const resolveFileType = (fileType, filePath) => {
109
109
  return 'js';
110
110
  };
111
111
 
112
- const saveUntestedFileSource = async (entryFile, options) => {
113
- const {
114
- id,
115
- url,
116
- source,
117
- sourceMap
118
- } = entryFile;
119
- // console.log('-', entry.sourcePath);
120
-
121
- const { cachePath } = Util.getCacheFileInfo('source', id, options.cacheDir);
122
- if (fs.existsSync(cachePath)) {
123
- return;
124
- }
125
-
126
- // save source and sourceMap to separated json file
127
- const sourceData = {
128
- id,
129
- url,
130
- source,
131
- sourceMap
132
- };
133
-
134
- // remove comments if not debug
135
- if (!Util.isDebug()) {
136
- sourceData.source = convertSourceMap.removeComments(source);
137
- }
138
-
139
- // console.log('save untested file', id, url);
112
+ const getUntestedCoverageData = (emptyList, options, coverageType) => {
140
113
 
141
- await Util.saveSourceCacheFile(sourceData, options);
142
-
143
- };
144
-
145
- const getUntestedCoverageData = async (emptyList, options, coverageType) => {
146
-
147
- // save all empty coverage
148
- const dataId = Util.uid();
149
- const results = {
150
- id: dataId
151
- };
152
-
153
- if (coverageType === 'istanbul') {
154
- results.type = 'istanbul';
155
- results.data = {};
156
- } else {
157
- results.type = 'v8';
158
- results.data = [];
159
- }
114
+ // NOTE: do not save untested file to raw report
160
115
 
161
116
  const emptyCoverageList = [];
162
117
 
163
118
  // save all empty source and sourcemap
164
119
  for (const entryFile of emptyList) {
165
120
 
166
- // for raw report: source file
167
- await saveUntestedFileSource(entryFile, options);
168
-
169
121
  const { type, url } = entryFile;
170
122
 
171
123
  if (coverageType === 'istanbul') {
@@ -181,7 +133,6 @@ const getUntestedCoverageData = async (emptyList, options, coverageType) => {
181
133
  b: {}
182
134
  };
183
135
  // object
184
- results.data[item.path] = item;
185
136
  emptyCoverageList.push(item);
186
137
 
187
138
  } else {
@@ -202,14 +153,6 @@ const getUntestedCoverageData = async (emptyList, options, coverageType) => {
202
153
  entryFile.ranges = entryFile.ranges || [];
203
154
  }
204
155
 
205
- const item = {
206
- ... entryFile
207
- };
208
- delete item.source;
209
- delete item.sourceMap;
210
-
211
- // array
212
- results.data.push(item);
213
156
  // will be parsed to AST and converted to V8 coverage
214
157
  emptyCoverageList.push(entryFile);
215
158
 
@@ -217,10 +160,6 @@ const getUntestedCoverageData = async (emptyList, options, coverageType) => {
217
160
 
218
161
  }
219
162
 
220
- // for raw report: coverage file
221
- const { cachePath } = Util.getCacheFileInfo('coverage', dataId, options.cacheDir);
222
- await Util.writeFile(cachePath, JSON.stringify(results));
223
-
224
163
  return emptyCoverageList;
225
164
  };
226
165
 
@@ -265,22 +204,33 @@ const getUntestedList = (testedMap, options, coverageType = 'v8') => {
265
204
  const {
266
205
  dirList, fileFilter, fileTransformer
267
206
  } = allOptions;
207
+
208
+ const sourceFilter = Util.getSourceFilter(options);
209
+
268
210
  const fileList = [];
269
211
  dirList.forEach((dir) => {
270
212
  Util.forEachFile(dir, [], (fileName, fileDir) => {
271
213
  const filePath = path.resolve(fileDir, fileName);
272
214
  // return file extname for file type
273
215
  const fileType = fileFilter(filePath);
274
- if (fileType) {
275
- const sourcePath = Util.relativePath(filePath);
276
- if (!testedMap.has(sourcePath)) {
277
- fileList.push({
278
- filePath,
279
- fileType,
280
- sourcePath
281
- });
282
- }
216
+ if (!fileType) {
217
+ return;
218
+ }
219
+
220
+ const sourcePath = Util.relativePath(filePath);
221
+ if (testedMap.has(sourcePath)) {
222
+ return;
283
223
  }
224
+
225
+ if (!sourceFilter(sourcePath)) {
226
+ return;
227
+ }
228
+
229
+ fileList.push({
230
+ filePath,
231
+ fileType,
232
+ sourcePath
233
+ });
284
234
  });
285
235
  });
286
236
  // console.log('fileList', fileList);
package/lib/index.d.ts CHANGED
@@ -361,8 +361,8 @@ declare namespace MCR {
361
361
  dir: string | string[];
362
362
 
363
363
  /**
364
- * the file filter, return the file type, if true, defaults to css if ".css" otherwise is js
365
- *
364
+ * the file filter is triggered before `sourceFilter`, no need to use it in normal case
365
+ * the filter could return the file type, if true, defaults to css if ".css" otherwise is js
366
366
  * {string} `minimatch` pattern for file path; {object} multiple patterns; {function} A filter function for file path;
367
367
  */
368
368
  filter?: string | {
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@ const EC = require('eight-colors');
6
6
  const defaultOptions = require('./default/options.js');
7
7
  const Util = require('./utils/util.js');
8
8
 
9
- const { initV8ListAndSourcemap, getEntryFilter } = require('./v8/v8.js');
9
+ const { initV8ListAndSourcemap } = require('./v8/v8.js');
10
10
  const {
11
11
  getInputData, readFromDir, generateCoverageReports
12
12
  } = require('./generate.js');
@@ -225,7 +225,7 @@ class CoverageReport {
225
225
 
226
226
  // get entry filter handler
227
227
  getEntryFilter() {
228
- return getEntryFilter(this.options);
228
+ return Util.getEntryFilter(this.options);
229
229
  }
230
230
 
231
231
  // load config file
package/lib/utils/util.js CHANGED
@@ -12,7 +12,9 @@ const request = require('./request.js');
12
12
  const version = require('../../package.json').version;
13
13
  const markdownGrid = require('./markdown.js');
14
14
 
15
- const { findUpSync, supportsColor } = require('../packages/monocart-coverage-vendor.js');
15
+ const {
16
+ findUpSync, supportsColor, minimatch
17
+ } = require('../packages/monocart-coverage-vendor.js');
16
18
 
17
19
  // https://github.com/chalk/supports-color
18
20
  // disabled color if Terminal stdout does not support color
@@ -161,6 +163,115 @@ const Util = {
161
163
  };
162
164
  },
163
165
 
166
+ // eslint-disable-next-line complexity
167
+ getEntryFilter: (options) => {
168
+ // for entry.url
169
+
170
+ if (options.entryFilterHandler) {
171
+ return options.entryFilterHandler;
172
+ }
173
+
174
+ let input = options.entryFilter || options.filter;
175
+
176
+ // for function handler
177
+ if (typeof input === 'function') {
178
+ options.entryFilterHandler = input;
179
+ return input;
180
+ }
181
+
182
+ // for single minimatch pattern
183
+ if (input && typeof input === 'string') {
184
+ // string to multiple patterns "{...}"
185
+ // mcr npx mocha --entryFilter {'**/node_modules/**':false,'**/src/*.js':true}
186
+ // mcr npx mocha --entryFilter "{'**/node_modules/**': false, '**/src/*.js': true}"
187
+ const obj = Util.strToObj(input);
188
+ if (obj) {
189
+ input = obj;
190
+ } else {
191
+ const handler = (entry) => {
192
+ return minimatch(entry.url, input);
193
+ };
194
+ options.entryFilterHandler = handler;
195
+ return handler;
196
+ }
197
+ }
198
+
199
+ // for patterns
200
+ if (input && typeof input === 'object') {
201
+ const patterns = Object.keys(input);
202
+ const handler = (entry) => {
203
+ const url = entry.url;
204
+ for (const pattern of patterns) {
205
+ if (minimatch(url, pattern)) {
206
+ return input[pattern];
207
+ }
208
+ }
209
+ // false if not matched
210
+ };
211
+ options.entryFilterHandler = handler;
212
+ return handler;
213
+ }
214
+
215
+ // default
216
+ const handler = () => true;
217
+ options.entryFilterHandler = handler;
218
+ return handler;
219
+ },
220
+
221
+ // eslint-disable-next-line complexity
222
+ getSourceFilter: (options) => {
223
+ // for sourcePath
224
+
225
+ if (options.sourceFilterHandler) {
226
+ return options.sourceFilterHandler;
227
+ }
228
+
229
+ let input = options.sourceFilter || options.filter;
230
+
231
+ // for function handler
232
+ if (typeof input === 'function') {
233
+ options.sourceFilterHandler = input;
234
+ return input;
235
+ }
236
+
237
+ // for single minimatch pattern
238
+ if (input && typeof input === 'string') {
239
+ // string to multiple patterns "{...}"
240
+ // mcr npx mocha --sourceFilter {'**/node_modules/**':false,'**/src/*.js':true}
241
+ // mcr npx mocha --sourceFilter "{'**/node_modules/**': false, '**/src/*.js': true}"
242
+ const obj = Util.strToObj(input);
243
+ if (obj) {
244
+ input = obj;
245
+ } else {
246
+ const handler = (sourcePath) => {
247
+ return minimatch(sourcePath, input);
248
+ };
249
+ options.sourceFilterHandler = handler;
250
+ return handler;
251
+ }
252
+ }
253
+
254
+ // for patterns
255
+ if (input && typeof input === 'object') {
256
+ const patterns = Object.keys(input);
257
+ const handler = (sourcePath) => {
258
+ for (const pattern of patterns) {
259
+ if (minimatch(sourcePath, pattern)) {
260
+ return input[pattern];
261
+ }
262
+ }
263
+ // false if not matched
264
+ };
265
+ options.sourceFilterHandler = handler;
266
+ return handler;
267
+ }
268
+
269
+ // default
270
+ const handler = () => true;
271
+ options.sourceFilterHandler = handler;
272
+ return handler;
273
+ },
274
+
164
275
  saveSourceCacheFile: async (sourceData, options, fileCache) => {
165
276
  const { cacheName, cachePath } = Util.getCacheFileInfo('source', sourceData.id, options.cacheDir);
166
277
 
package/lib/v8/v8.js CHANGED
@@ -7,7 +7,6 @@ const {
7
7
  resolveAnonymousUrl, normalizeSourcePath, getSourcePathReplacer
8
8
  } = require('../utils/source-path.js');
9
9
  const { collectSourceMaps } = require('../converter/collect-source-maps.js');
10
- const { minimatch } = require('../packages/monocart-coverage-vendor.js');
11
10
 
12
11
  const { v8Report } = require('../reports/v8.js');
13
12
  const { v8JsonReport } = require('../reports/v8-json.js');
@@ -27,53 +26,12 @@ const getWrapperSource = (offset, source) => {
27
26
  return startStr + source;
28
27
  };
29
28
 
30
- const getEntryFilter = (options) => {
31
- let input = options.entryFilter || options.filter;
32
-
33
- // for function handler
34
- if (typeof input === 'function') {
35
- return input;
36
- }
37
-
38
- // for single minimatch pattern
39
- if (input && typeof input === 'string') {
40
- // string to multiple patterns "{...}"
41
- // mcr npx mocha --entryFilter {'**/node_modules/**':false,'**/src/*.js':true}
42
- // mcr npx mocha --entryFilter "{'**/node_modules/**': false, '**/src/*.js': true}"
43
- const obj = Util.strToObj(input);
44
- if (obj) {
45
- input = obj;
46
- } else {
47
- return (entry) => {
48
- return minimatch(entry.url, input);
49
- };
50
- }
51
- }
52
-
53
- // for patterns
54
- if (input && typeof input === 'object') {
55
- const patterns = Object.keys(input);
56
- return (entry) => {
57
- const url = entry.url;
58
- for (const pattern of patterns) {
59
- if (minimatch(url, pattern)) {
60
- return input[pattern];
61
- }
62
- }
63
- // false if not matched
64
- };
65
- }
66
-
67
- // default
68
- return () => true;
69
- };
70
-
71
29
  const initV8ListAndSourcemap = async (mcr, v8list) => {
72
30
 
73
31
  const { options, fileCache } = mcr;
74
32
 
75
33
  // entry filter
76
- const entryFilter = getEntryFilter(options);
34
+ const entryFilter = Util.getEntryFilter(options);
77
35
 
78
36
  const lengthBefore = v8list.length;
79
37
  v8list = v8list.filter(entryFilter);
@@ -367,6 +325,5 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
367
325
  module.exports = {
368
326
  initV8ListAndSourcemap,
369
327
  mergeV8Coverage,
370
- saveV8Report,
371
- getEntryFilter
328
+ saveV8Report
372
329
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.10.5",
3
+ "version": "2.10.7",
4
4
  "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {