monocart-coverage-reports 1.0.7 → 1.0.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/README.md CHANGED
@@ -35,6 +35,7 @@ console.log(coverageResults.summary);
35
35
  ## Multiple Reports
36
36
  - v8 report
37
37
  - v8
38
+ - v8-json
38
39
  - [istanbul reports](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
39
40
  - clover
40
41
  - cobertura
@@ -101,7 +102,7 @@ console.log(coverageResults.summary);
101
102
  | :--------------| :------ | :------ | :---------------------- |
102
103
  | Input | Istanbul (Object) | V8 (Array) | V8 (Array) |
103
104
  | Output | [Istanbul HTML report](https://cenfun.github.io/monocart-coverage-reports/istanbul) | [V8 HTML report](https://cenfun.github.io/monocart-coverage-reports/v8) | [Istanbul HTML report](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/istanbul) |
104
- | Indicators | Covered Lines, Branches, Statements and Functions, Execution Counts | Covered Bytes, Lines❔, Execution Counts | Covered Lines, Branches❔, Statements and Functions, Execution Counts |
105
+ | Indicators | Covered Lines, Branches, Statements and Functions, Execution Counts | Covered Bytes, Lines❔, Execution Counts | Covered Lines, Branches❔, Statements and Functions❔, Execution Counts |
105
106
  | CSS coverage | ❌ | ✅ | ✅ |
106
107
  | Minified code | N/A | ✅ | ❌ |
107
108
  | Code formatting | N/A | ✅ | ❌ |
@@ -115,7 +116,7 @@ console.log(coverageResults.summary);
115
116
  - 3, Generating coverage report.
116
117
 
117
118
  - V8 Workflows
118
- - 1, For any runtime code: nothing to do. For source code: building code with `development` mode and sourcemap support, see [webpack.config-v8.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/mock/webpack.config-v8.js).
119
+ - 1, For any runtime code: nothing to do. For source code: building code with `development` [mode](https://webpack.js.org/configuration/mode/) and [sourcemap](https://webpack.js.org/configuration/devtool/) support, see [webpack.config-v8.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/mock/webpack.config-v8.js).
119
120
  - 2, Collecting coverage data with [Chromium Coverage API](#chromium-coverage-api), see [example](https://github.com/cenfun/monocart-coverage-reports/blob/main/tests/test-v8.js).
120
121
  - 3, Generating coverage report.
121
122
 
package/lib/generate.js CHANGED
@@ -26,7 +26,7 @@ const generateV8ListReports = async (v8list, coverageData, fileSources, options)
26
26
 
27
27
  // generate v8 report
28
28
  if (v8) {
29
- report = await saveV8Report(v8list, options, v8);
29
+ report = await saveV8Report(v8list, options);
30
30
  }
31
31
 
32
32
  return report;
@@ -68,6 +68,7 @@ const getReportGroup = (reports, lcov, dataType) => {
68
68
 
69
69
  const allSupportedReports = [
70
70
  'v8',
71
+ 'v8-json',
71
72
  'clover',
72
73
  'cobertura',
73
74
  'html',
@@ -86,13 +87,20 @@ const getReportGroup = (reports, lcov, dataType) => {
86
87
  // group v8 and istanbul
87
88
  const reportGroup = {};
88
89
  Object.keys(reportMap).forEach((k) => {
89
- if (k === 'v8') {
90
- reportGroup.v8 = reportMap.v8;
90
+ if (!allSupportedReports.includes(k)) {
91
91
  return;
92
92
  }
93
- if (!allSupportedReports.includes(k)) {
93
+
94
+ if (k.startsWith('v8')) {
95
+ // v8
96
+ if (!reportGroup.v8) {
97
+ reportGroup.v8 = {};
98
+ }
99
+ reportGroup.v8[k] = reportMap[k];
94
100
  return;
95
101
  }
102
+
103
+ // istanbul
96
104
  if (!reportGroup.istanbul) {
97
105
  reportGroup.istanbul = {};
98
106
  }
package/lib/index.d.ts CHANGED
@@ -25,6 +25,9 @@ export type ReportDescription =
25
25
  inline?: boolean,
26
26
  assetsPath?: string
27
27
  }] |
28
+ ['v8-json'] | ["v8-json", {
29
+ outputFile?: string
30
+ }] |
28
31
  ['clover'] | ['clover', {
29
32
  file?: string
30
33
  }] |
package/lib/utils/util.js CHANGED
@@ -103,6 +103,35 @@ const Util = {
103
103
  return htmlPathHandler();
104
104
  },
105
105
 
106
+ resolveNodeModule: (p) => {
107
+
108
+ // root
109
+ const cwd = path.resolve('node_modules', p);
110
+ if (fs.existsSync(cwd)) {
111
+ return cwd;
112
+ }
113
+
114
+ // sub node modules
115
+ const sub = path.resolve(__dirname, '../../node_modules', p);
116
+ if (fs.existsSync(sub)) {
117
+ return sub;
118
+ }
119
+
120
+ // same level dep
121
+ const dep = path.resolve(__dirname, '../../../', p);
122
+ if (fs.existsSync(dep)) {
123
+ return dep;
124
+ }
125
+
126
+ Util.logError(`Not found module: ${p}`);
127
+
128
+ return cwd;
129
+ },
130
+
131
+ resolvePackage: (p) => {
132
+ return path.resolve(__dirname, '../packages', p);
133
+ },
134
+
106
135
  saveHtmlReport: async (options) => {
107
136
 
108
137
  const {
package/lib/v8/v8.js CHANGED
@@ -167,7 +167,30 @@ const mergeV8Coverage = async (dataList, options) => {
167
167
 
168
168
  // ============================================================
169
169
 
170
- const saveV8HtmlReport = async (reportData, options, v8MergedOptions) => {
170
+ const saveV8JsonReport = async (reportData, options, v8JsonOptions) => {
171
+ const v8MergedOptions = {
172
+ outputFile: 'coverage-report.json',
173
+ ... v8JsonOptions
174
+ };
175
+
176
+ // console.log(v8MergedOptions);
177
+ const jsonPath = path.resolve(options.outputDir, v8MergedOptions.outputFile);
178
+ // console.log(reportPath);
179
+ await Util.writeFile(jsonPath, JSON.stringify(reportData));
180
+
181
+ return Util.relativePath(jsonPath);
182
+ };
183
+
184
+
185
+ const saveV8HtmlReport = async (reportData, options, v8HtmlOptions) => {
186
+
187
+ // V8 only options, merged with root options
188
+ const v8MergedOptions = {
189
+ outputFile: options.outputFile,
190
+ inline: options.inline,
191
+ assetsPath: options.assetsPath,
192
+ ... v8HtmlOptions
193
+ };
171
194
 
172
195
  const {
173
196
  outputFile, inline, assetsPath
@@ -180,11 +203,11 @@ const saveV8HtmlReport = async (reportData, options, v8MergedOptions) => {
180
203
 
181
204
  // deps
182
205
  const jsFiles = ['monocart-code-viewer', 'monocart-formatter', 'turbogrid'].map((it) => {
183
- return path.resolve(`node_modules/${it}/dist/${it}.js`);
206
+ return Util.resolveNodeModule(`${it}/dist/${it}.js`);
184
207
  });
185
208
 
186
209
  // package v8 ui
187
- jsFiles.push(path.resolve(__dirname, '../packages/monocart-coverage-v8.js'));
210
+ jsFiles.push(Util.resolvePackage('monocart-coverage-v8.js'));
188
211
 
189
212
  // console.log(jsFiles);
190
213
 
@@ -204,8 +227,7 @@ const saveV8HtmlReport = async (reportData, options, v8MergedOptions) => {
204
227
  return htmlPath;
205
228
  };
206
229
 
207
-
208
- const saveV8Report = async (v8list, options, v8Options) => {
230
+ const saveV8Report = async (v8list, options) => {
209
231
  const defaultWatermarks = {
210
232
  bytes: [50, 80]
211
233
  };
@@ -245,24 +267,32 @@ const saveV8Report = async (v8list, options, v8Options) => {
245
267
  status
246
268
  };
247
269
 
248
- // V8 only options, merged with root options
249
- const v8MergedOptions = {
250
- outputFile: options.outputFile,
251
- inline: options.inline,
252
- assetsPath: options.assetsPath,
253
- ... v8Options
254
- };
255
-
256
- const htmlOptions = {
270
+ const reportData = {
257
271
  name: options.name,
258
272
  watermarks,
259
273
  summary,
260
274
  files: v8list
261
275
  };
262
276
 
263
- const htmlPath = await saveV8HtmlReport(htmlOptions, options, v8MergedOptions);
277
+ let outputPath;
278
+
279
+ // v8 reports
280
+ const v8Map = options.reportGroup.v8;
281
+
282
+ // v8 json
283
+ const v8JsonOptions = v8Map['v8-json'];
284
+ if (v8JsonOptions) {
285
+ outputPath = await saveV8JsonReport(reportData, options, v8JsonOptions);
286
+ }
287
+
288
+ // v8 html
289
+ const v8HtmlOptions = v8Map.v8;
290
+ if (v8HtmlOptions) {
291
+ outputPath = await saveV8HtmlReport(reportData, options, v8HtmlOptions);
292
+ }
293
+
264
294
  const reportPath = Util.resolveReportPath(options, () => {
265
- return htmlPath;
295
+ return outputPath;
266
296
  });
267
297
 
268
298
  const report = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -52,12 +52,12 @@
52
52
  "eslint-config-plus": "^1.0.6",
53
53
  "eslint-plugin-html": "^7.1.0",
54
54
  "eslint-plugin-vue": "^9.19.2",
55
- "github-markdown-css": "^5.4.0",
55
+ "github-markdown-css": "^5.5.0",
56
56
  "koa": "^2.14.2",
57
57
  "koa-static-resolver": "^1.0.4",
58
- "marked": "^11.0.0",
58
+ "marked": "^11.0.1",
59
59
  "playwright": "^1.40.1",
60
- "stylelint": "^15.11.0",
60
+ "stylelint": "^16.0.2",
61
61
  "stylelint-config-plus": "^1.0.4",
62
62
  "webpack": "^5.89.0",
63
63
  "webpack-cli": "^5.1.4"