monocart-coverage-reports 2.10.3 → 2.10.5

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.
@@ -1,34 +1,34 @@
1
- const { pathToFileURL } = require('url');
2
- const Util = require('../utils/util.js');
3
-
4
- const customReport = async (reportName, reportData, reportOptions, globalOptions) => {
5
- let CustomReporter;
6
- let err;
7
- try {
8
- CustomReporter = await import(reportName);
9
- } catch (e) {
10
- err = e;
11
- try {
12
- CustomReporter = await import(pathToFileURL(reportName));
13
- } catch (ee) {
14
- err = ee;
15
- }
16
- }
17
-
18
- if (!CustomReporter) {
19
- Util.logError(err.message);
20
- return;
21
- }
22
-
23
- CustomReporter = CustomReporter.default || CustomReporter;
24
-
25
- const reporter = new CustomReporter(reportOptions, globalOptions);
26
-
27
- const results = await reporter.generate(reportData);
28
-
29
- return results;
30
- };
31
-
32
- module.exports = {
33
- customReport
34
- };
1
+ const { pathToFileURL } = require('url');
2
+ const Util = require('../utils/util.js');
3
+
4
+ const customReport = async (reportName, reportData, reportOptions, globalOptions) => {
5
+ let CustomReporter;
6
+ let err;
7
+ try {
8
+ CustomReporter = await import(reportName);
9
+ } catch (e) {
10
+ err = e;
11
+ try {
12
+ CustomReporter = await import(pathToFileURL(reportName));
13
+ } catch (ee) {
14
+ err = ee;
15
+ }
16
+ }
17
+
18
+ if (!CustomReporter) {
19
+ Util.logError(err.message);
20
+ return;
21
+ }
22
+
23
+ CustomReporter = CustomReporter.default || CustomReporter;
24
+
25
+ const reporter = new CustomReporter(reportOptions, globalOptions);
26
+
27
+ const results = await reporter.generate(reportData);
28
+
29
+ return results;
30
+ };
31
+
32
+ module.exports = {
33
+ customReport
34
+ };
@@ -1,22 +1,22 @@
1
- const path = require('path');
2
- const Util = require('../utils/util.js');
3
-
4
- const v8JsonReport = async (reportData, reportOptions, options) => {
5
- const v8JsonOptions = {
6
- outputFile: 'coverage-report.json',
7
- ... reportOptions
8
- };
9
-
10
- // console.log(mergedOptions);
11
- const jsonPath = path.resolve(options.outputDir, v8JsonOptions.outputFile);
12
- const reportPath = Util.relativePath(jsonPath);
13
-
14
- reportData.reportPath = reportPath;
15
-
16
- await Util.writeFile(jsonPath, JSON.stringify(reportData));
17
- return reportPath;
18
- };
19
-
20
- module.exports = {
21
- v8JsonReport
22
- };
1
+ const path = require('path');
2
+ const Util = require('../utils/util.js');
3
+
4
+ const v8JsonReport = async (reportData, reportOptions, options) => {
5
+ const v8JsonOptions = {
6
+ outputFile: 'coverage-report.json',
7
+ ... reportOptions
8
+ };
9
+
10
+ // console.log(mergedOptions);
11
+ const jsonPath = path.resolve(options.outputDir, v8JsonOptions.outputFile);
12
+ const reportPath = Util.relativePath(jsonPath);
13
+
14
+ reportData.reportPath = reportPath;
15
+
16
+ await Util.writeFile(jsonPath, JSON.stringify(reportData));
17
+ return reportPath;
18
+ };
19
+
20
+ module.exports = {
21
+ v8JsonReport
22
+ };
package/lib/reports/v8.js CHANGED
@@ -1,51 +1,51 @@
1
- const path = require('path');
2
- const Assets = require('../assets.js');
3
-
4
- const v8Report = async (reportData, reportOptions, options) => {
5
-
6
- // V8 only options, merged with root options
7
- const v8HtmlOptions = {
8
- outputFile: options.outputFile,
9
- inline: options.inline,
10
- assetsPath: options.assetsPath,
11
- metrics: options.metrics,
12
- ... reportOptions
13
- };
14
-
15
- // add metrics to data for UI
16
- reportData.metrics = v8HtmlOptions.metrics;
17
-
18
- const {
19
- outputFile, inline, assetsPath
20
- } = v8HtmlOptions;
21
-
22
- // resolve full report path
23
- const reportPath = path.resolve(options.outputDir, outputFile);
24
- const outputDir = path.dirname(reportPath);
25
- const htmlFile = path.basename(reportPath);
26
-
27
- const jsFiles = ['monocart-coverage-app'];
28
- // console.log(jsFiles);
29
-
30
- const htmlOptions = {
31
- reportData,
32
- jsFiles,
33
- inline,
34
- assetsPath,
35
- outputDir,
36
- htmlFile,
37
-
38
- saveReportPath: 'reportPath',
39
-
40
- reportDataFile: 'coverage-data.js'
41
- };
42
-
43
- // compress json data for html
44
- const htmlPath = await Assets.saveHtmlReport(htmlOptions);
45
-
46
- return htmlPath;
47
- };
48
-
49
- module.exports = {
50
- v8Report
51
- };
1
+ const path = require('path');
2
+ const Assets = require('../assets.js');
3
+
4
+ const v8Report = async (reportData, reportOptions, options) => {
5
+
6
+ // V8 only options, merged with root options
7
+ const v8HtmlOptions = {
8
+ outputFile: options.outputFile,
9
+ inline: options.inline,
10
+ assetsPath: options.assetsPath,
11
+ metrics: options.metrics,
12
+ ... reportOptions
13
+ };
14
+
15
+ // add metrics to data for UI
16
+ reportData.metrics = v8HtmlOptions.metrics;
17
+
18
+ const {
19
+ outputFile, inline, assetsPath
20
+ } = v8HtmlOptions;
21
+
22
+ // resolve full report path
23
+ const reportPath = path.resolve(options.outputDir, outputFile);
24
+ const outputDir = path.dirname(reportPath);
25
+ const htmlFile = path.basename(reportPath);
26
+
27
+ const jsFiles = ['monocart-coverage-app'];
28
+ // console.log(jsFiles);
29
+
30
+ const htmlOptions = {
31
+ reportData,
32
+ jsFiles,
33
+ inline,
34
+ assetsPath,
35
+ outputDir,
36
+ htmlFile,
37
+
38
+ saveReportPath: 'reportPath',
39
+
40
+ reportDataFile: 'coverage-data.js'
41
+ };
42
+
43
+ // compress json data for html
44
+ const htmlPath = await Assets.saveHtmlReport(htmlOptions);
45
+
46
+ return htmlPath;
47
+ };
48
+
49
+ module.exports = {
50
+ v8Report
51
+ };
package/lib/utils/util.js CHANGED
@@ -161,6 +161,25 @@ const Util = {
161
161
  };
162
162
  },
163
163
 
164
+ saveSourceCacheFile: async (sourceData, options, fileCache) => {
165
+ const { cacheName, cachePath } = Util.getCacheFileInfo('source', sourceData.id, options.cacheDir);
166
+
167
+ // file cache for add() to generate()
168
+ if (fileCache) {
169
+ fileCache.set(cacheName, sourceData);
170
+ }
171
+
172
+ await Util.writeFile(cachePath, JSON.stringify(sourceData));
173
+
174
+ // save source and sourcemap file for debug
175
+ // https://evanw.github.io/source-map-visualization
176
+ if (options.sourceMap && sourceData.sourceMap) {
177
+ const filePath = cachePath.slice(0, -5);
178
+ await Util.writeFile(`${filePath}.js`, sourceData.source);
179
+ await Util.writeFile(`${filePath}.js.map`, JSON.stringify(sourceData.sourceMap));
180
+ }
181
+ },
182
+
164
183
  findUpConfig: (customConfigFile) => {
165
184
  if (customConfigFile) {
166
185
  if (fs.existsSync(customConfigFile)) {
package/lib/v8/v8.js CHANGED
@@ -70,7 +70,7 @@ const getEntryFilter = (options) => {
70
70
 
71
71
  const initV8ListAndSourcemap = async (mcr, v8list) => {
72
72
 
73
- const { options } = mcr;
73
+ const { options, fileCache } = mcr;
74
74
 
75
75
  // entry filter
76
76
  const entryFilter = getEntryFilter(options);
@@ -102,6 +102,7 @@ const initV8ListAndSourcemap = async (mcr, v8list) => {
102
102
  }
103
103
  return true;
104
104
  }
105
+
105
106
  // 404 css, text will be empty
106
107
  Util.logDebug(EC.red(`Invalid source or coverage data: ${entry.url}`));
107
108
  // console.log(entry);
@@ -186,17 +187,7 @@ const initV8ListAndSourcemap = async (mcr, v8list) => {
186
187
 
187
188
  // save source list
188
189
  for (const sourceData of sourceList) {
189
-
190
- const { cacheName, cachePath } = Util.getCacheFileInfo('source', sourceData.id, options.cacheDir);
191
- mcr.fileCache.set(cacheName, sourceData);
192
- await Util.writeFile(cachePath, JSON.stringify(sourceData));
193
-
194
- // save source and sourcemap file for debug
195
- // https://evanw.github.io/source-map-visualization
196
- // if (sourceData.sourceMap) {
197
- // await Util.writeFile(`${sourcePath}.js`, sourceData.source);
198
- // await Util.writeFile(`${sourcePath}.js.map`, JSON.stringify(sourceData.sourceMap));
199
- // }
190
+ await Util.saveSourceCacheFile(sourceData, options, fileCache);
200
191
  }
201
192
 
202
193
  return v8list;
@@ -242,9 +233,10 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
242
233
 
243
234
  // connect all functions and ranges
244
235
  const itemMap = {};
236
+ const sourcePathMap = {};
245
237
  const mergeMap = {};
246
238
  coverageList.forEach((item) => {
247
- const { id } = item;
239
+ const { id, sourcePath } = item;
248
240
  const prev = itemMap[id];
249
241
  if (prev) {
250
242
  if (mergeMap[id]) {
@@ -254,6 +246,7 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
254
246
  }
255
247
  } else {
256
248
  itemMap[id] = item;
249
+ sourcePathMap[sourcePath] = item;
257
250
  }
258
251
  });
259
252
 
@@ -271,16 +264,22 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
271
264
 
272
265
  // first time filter for empty, (not for sources)
273
266
  // empty and not in item map
274
- const emptyList = allList.filter((it) => it.empty).filter((it) => !itemMap[it.id]);
267
+ const emptyList = allList.filter((it) => it.empty).filter((it) => {
268
+ if (itemMap[it.id]) {
269
+ return false;
270
+ }
271
+ if (sourcePathMap[it.sourcePath]) {
272
+ return false;
273
+ }
274
+ return true;
275
+ });
275
276
 
276
277
  // empty list + merged list
277
278
  const mergedList = emptyList.concat(Object.values(itemMap));
278
279
 
279
280
  // try to load coverage and source by id
280
281
  for (const item of mergedList) {
281
- const {
282
- id, type, empty
283
- } = item;
282
+ const { id } = item;
284
283
  const json = sourceCache.get(id);
285
284
  if (json) {
286
285
  item.source = json.source;
@@ -289,24 +288,6 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
289
288
  Util.logError(`Not found source data: ${Util.relativePath(item.sourcePath)}`);
290
289
  item.source = '';
291
290
  }
292
-
293
- // add empty coverage after merged
294
- if (empty) {
295
- if (type === 'js') {
296
- item.functions = [{
297
- functionName: '',
298
- ranges: [{
299
- startOffset: 0,
300
- endOffset: item.source.length,
301
- count: 0
302
- }]
303
- }];
304
- } else {
305
- // empty css
306
- item.ranges = [];
307
- }
308
- }
309
-
310
291
  }
311
292
 
312
293
  return mergedList;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.10.3",
3
+ "version": "2.10.5",
4
4
  "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -10,13 +10,11 @@
10
10
  ".": {
11
11
  "types": "./lib/index.d.ts",
12
12
  "import": "./lib/index.mjs",
13
- "require": "./lib/index.js",
14
- "default": "./lib/index.js"
13
+ "require": "./lib/index.js"
15
14
  },
16
15
  "./register": {
17
16
  "import": "./lib/register/register.mjs",
18
- "require": "./lib/register/register.js",
19
- "default": "./lib/register/register.js"
17
+ "require": "./lib/register/register.js"
20
18
  },
21
19
  "./converter": "./lib/converter/converter.js",
22
20
  "./util": "./lib/utils/util.js",
@@ -79,7 +77,7 @@
79
77
  "@jridgewell/sourcemap-codec": "^1.5.0",
80
78
  "acorn": "^8.12.1",
81
79
  "acorn-loose": "^8.4.0",
82
- "acorn-walk": "^8.3.3",
80
+ "acorn-walk": "^8.3.4",
83
81
  "commander": "^12.1.0",
84
82
  "console-grid": "^2.2.2",
85
83
  "eight-colors": "^1.3.0",
@@ -94,21 +92,21 @@
94
92
  "async-tick": "^1.0.0",
95
93
  "convert-source-map": "^2.0.0",
96
94
  "diff-sequences": "^29.6.3",
97
- "esbuild": "^0.23.0",
98
- "eslint": "~9.9.0",
95
+ "esbuild": "^0.23.1",
96
+ "eslint": "~9.10.0",
99
97
  "eslint-config-plus": "^2.0.2",
100
98
  "eslint-plugin-html": "^8.1.1",
101
- "eslint-plugin-vue": "^9.27.0",
99
+ "eslint-plugin-vue": "^9.28.0",
102
100
  "find-up": "^7.0.0",
103
101
  "minimatch": "^9.0.5",
104
102
  "monocart-code-viewer": "^1.1.4",
105
103
  "monocart-formatter": "^3.0.0",
106
- "postcss": "^8.4.41",
104
+ "postcss": "^8.4.47",
107
105
  "starfall-cli": "^2.0.20",
108
- "stylelint": "^16.8.1",
109
- "stylelint-config-plus": "^1.1.2",
106
+ "stylelint": "^16.9.0",
107
+ "stylelint-config-plus": "^1.1.3",
110
108
  "supports-color": "^9.4.0",
111
- "tsx": "^4.17.0",
109
+ "tsx": "^4.19.1",
112
110
  "turbogrid": "^3.2.0",
113
111
  "vine-ui": "^3.1.16",
114
112
  "ws": "^8.18.0"