monocart-reporter 1.6.23 → 1.6.24

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
@@ -34,6 +34,7 @@
34
34
  * [Attach Lighthouse Audit Report](#attach-lighthouse-audit-report)
35
35
  * [Attach Code Coverage Report](#attach-code-coverage-report)
36
36
  - [Compare Istanbul, V8 and V8 to Istanbul](#compare-istanbul-v8-and-v8-to-istanbul)
37
+ - [Global Coverage Report](#global-coverage-report) for Component Testing
37
38
  * [Attach Network Report](#attach-network-report)
38
39
  * [Merge Shard Reports](#merge-shard-reports)
39
40
  * [onEnd hook](#onend-hook)
@@ -725,7 +726,7 @@ const report = await attachCoverageReport(coverageList, test.info(), {
725
726
  | Minified code | N/A | ✅ | ❌ |
726
727
  | Code formatting | N/A | ✅ | ❌ |
727
728
 
728
- ## Global Coverage Report
729
+ ### Global Coverage Report
729
730
  If you want to generate a global coverage report, you can use the API `addCoverageReport(v8list, testInfo)`. When all the tests are finished, all added reports will be automatically merged into a global report. Currently supported `V8` only. Here is an example for Playwright Component Testing [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue).
730
731
  ```js
731
732
  // playwright.config.js
@@ -5,6 +5,7 @@ const { getTickInfo } = require('./utils/system.js');
5
5
  const Visitor = require('./visitor.js');
6
6
  const { calculateSummary } = require('./common.js');
7
7
  const { generateCoverageReport } = require('./plugins/coverage/coverage.js');
8
+ const { generateNetworkReport } = require('./plugins/network/network.js');
8
9
 
9
10
  const getReportName = (options, config, metadata) => {
10
11
  const reportName = options.name || config.name || metadata.name;
@@ -16,11 +17,14 @@ const getReportName = (options, config, metadata) => {
16
17
 
17
18
  const artifactsHandler = async (visitor, options) => {
18
19
  const artifacts = [];
19
- const { coverage } = visitor.artifacts;
20
+ const { coverage, network } = visitor.artifacts;
20
21
  visitor.artifacts = null;
21
22
  if (coverage) {
22
23
  const report = await generateCoverageReport(coverage, options);
23
- report.name = 'coverage';
24
+ artifacts.push(report);
25
+ }
26
+ if (network) {
27
+ const report = await generateNetworkReport(coverage, options);
24
28
  artifacts.push(report);
25
29
  }
26
30
  return artifacts;
@@ -144,17 +144,19 @@ const showTestResults = (reportData) => {
144
144
  const generateReport = (reportData, onEnd) => {
145
145
 
146
146
  console.log('[MCR] generating test report ...');
147
-
148
147
  showTestResults(reportData);
149
148
 
150
- // console.log(config);
151
149
  const {
152
150
  outputFile, outputDir, artifacts
153
151
  } = reportData;
154
152
 
155
153
  if (artifacts) {
156
154
  artifacts.forEach((report) => {
157
- console.log(`[MCR] ${report.name} report: ${EC.cyan(report.htmlPath)}`);
155
+ console.log(`[MCR] ${report.type} report: ${EC.cyan(report.htmlPath)}`);
156
+
157
+ // convert htmlPath to relative reporter
158
+ report.htmlPath = Util.relativePath(report.htmlPath, outputDir);
159
+
158
160
  });
159
161
  }
160
162
 
@@ -242,7 +242,7 @@ const generateCoverageReport = async (dataList, reporterOptions) => {
242
242
  v8list = v8list.concat(item.data);
243
243
  });
244
244
 
245
- // merge list, maybe collected multiple times
245
+ // merge list again for multiple v8list, maybe collected multiple times
246
246
  v8list = await mergeV8List(v8list, options);
247
247
 
248
248
  // const v8Path = path.resolve(__dirname, '../../.temp/v8-data.js');
@@ -254,7 +254,8 @@ const generateCoverageReport = async (dataList, reporterOptions) => {
254
254
  const report = await saveV8Report(v8list, options);
255
255
 
256
256
  return {
257
- type: report.type,
257
+ type: 'coverage',
258
+ name: 'Coverage',
258
259
  htmlPath: report.htmlPath,
259
260
  summary: report.summary
260
261
  };
@@ -91,11 +91,12 @@ const initV8List = async (v8list, options) => {
91
91
  const filename = path.basename(sourcePath);
92
92
  item.filename = filename;
93
93
  item.sourcePath = sourcePath;
94
-
94
+ item.id = Util.calculateSha1(item.url + item.source);
95
95
  // console.log(sourcePath);
96
-
97
96
  });
98
97
 
98
+ v8list = await mergeV8List(v8list, options);
99
+
99
100
  return v8list;
100
101
  };
101
102
 
@@ -142,27 +143,14 @@ const mergeV8Item = async (lastItem, item) => {
142
143
 
143
144
  const mergeV8List = async (v8list, options) => {
144
145
 
145
- // sort by url
146
+ // sort by id, id is hash from url and source
146
147
  v8list.sort((a, b) => {
147
- if (a.url === b.url) {
148
- if (a.source === b.source) {
149
- return 0;
150
- }
151
- return a.source > b.source ? 1 : -1;
152
- }
153
- return a.url > b.url ? 1 : -1;
148
+ return a.id > b.id ? 1 : -1;
154
149
  });
155
150
 
156
- // console.log(v8list.map((it) => {
157
- // return {
158
- // url: it.url,
159
- // source: it.source.slice(0, 30)
160
- // };
161
- // }));
162
-
163
151
  let lastItem = {};
164
152
  for (const item of v8list) {
165
- if (item.url === lastItem.url && item.source === lastItem.source) {
153
+ if (item.id === lastItem.id) {
166
154
  item.dedupe = true;
167
155
  lastItem = await mergeV8Item(lastItem, item);
168
156
  continue;
@@ -161,7 +161,17 @@ const attachNetworkReport = async (har, testInfo, options = {}) => {
161
161
  return report;
162
162
  };
163
163
 
164
+ // TODO
165
+ const addNetworkReport = async () => {
166
+
167
+ };
168
+
169
+ const generateNetworkReport = async () => {
170
+
171
+ };
164
172
 
165
173
  module.exports = {
174
+ addNetworkReport,
175
+ generateNetworkReport,
166
176
  attachNetworkReport
167
177
  };