monocart-reporter 1.6.23 → 1.6.25

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
@@ -18,8 +18,8 @@
18
18
  * [Playwright Config](#playwright-config)
19
19
  * [Examples](#examples)
20
20
  * [Output](#output) HTML and JSON
21
- * [View Trace Online](#view-trace-online)
22
21
  * [Reporter Options](#reporter-options)
22
+ * [View Trace Online](#view-trace-online)
23
23
  * [Custom Columns](#custom-columns) (Extra properties for suite/case/step)
24
24
  - [Custom Formatter](#custom-formatter)
25
25
  - [Searchable Fields](#searchable-fields)
@@ -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)
@@ -104,12 +105,6 @@ module.exports = {
104
105
  - path-to/your-filename.json
105
106
  Separated metadata file (Already included in the above HTML and compressed, it can be deleted). Can be used for debugging or custom data collection.
106
107
 
107
- ## View Trace Online
108
- > The [Trace Viewer](https://trace.playwright.dev/) requires that the trace file must be loaded over the http:// or https:// protocols without [CORS](https://developer.mozilla.org/en-US/docs/Glossary/CORS) issue, try following start a local web server:
109
- ```sh
110
- npx monocart show-report <your-outputFile-path>
111
- ```
112
-
113
108
  ## Reporter Options
114
109
  ```js
115
110
  {
@@ -123,6 +118,17 @@ npx monocart show-report <your-outputFile-path>
123
118
  attachmentPath: null,
124
119
  // attachmentPath: (currentPath, extras) => `https://another-path/${currentPath}`,
125
120
 
121
+ traceViewerUrl: 'https://trace.playwright.dev/?trace={traceUrl}',
122
+
123
+ // global coverage settings for addCoverageReport API
124
+ coverage: null,
125
+ // coverage: {
126
+ // unpackSourceMap: true,
127
+ // excludeDistFile: true,
128
+ // sourceFilter: (sourceName) => sourceName.search(/\/src\/.+/) !== -1,
129
+ // entryFilter: (entry) => {}
130
+ // },
131
+
126
132
  // trend data handler
127
133
  trend: null,
128
134
  // trend: () => './test-results/report.json',
@@ -152,6 +158,13 @@ npx monocart show-report <your-outputFile-path>
152
158
  }
153
159
  ```
154
160
 
161
+ ## View Trace Online
162
+ > The [Trace Viewer](https://trace.playwright.dev/) requires that the trace file must be loaded over the http:// or https:// protocols without [CORS](https://developer.mozilla.org/en-US/docs/Glossary/CORS) issue, try following start a local web server:
163
+ ```sh
164
+ npx monocart show-report <your-outputFile-path>
165
+ ```
166
+ Or customize your own trace viewer url with option `traceViewerUrl` defaults to `https://trace.playwright.dev/?trace={traceUrl}`
167
+
155
168
  ## Custom Columns
156
169
  The report will be displayed in a `Tree Grid`. The `columns` function is used to customize the grid columns. The column properties following:
157
170
  - `id` (String) Column id (required)
@@ -623,8 +636,17 @@ Attach a code coverage report with API `attachCoverageReport(data, testInfo, opt
623
636
  - `data` There are two supported data inputs `Istanbul` (Object) or `V8` (Array)
624
637
  - `testInfo` see [TestInfo](https://playwright.dev/docs/api/class-testinfo)
625
638
  - `options` (Object)
626
- - `watermarks` By default, watermarks of Istanbul see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report) (Object), watermarks of V8 is `[50, 80]` (Array)
627
- - `toIstanbul` (Boolean) for V8 data conversion
639
+ - Istanbul only:
640
+ - `watermarks` (Object) Istanbul watermarks, see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report)
641
+ - `lcov` (Boolean) Whether to create `lcov.info`
642
+ - V8 only:
643
+ - `toIstanbul` (Boolean) Whether to convert to Istanbul report
644
+ - `watermarks` (Array) Defaults to `[50, 80]`
645
+ - `unpackSourceMap` (Boolean) Whether to unpack all sources from the source map if a related source map file is found.
646
+ - `excludeDistFile` (Boolean) Whether to exclude the dist file (usually minified) if the sources are successfully unpacked from the source map.
647
+ - `sourceFilter` (Function) A filter function to execute for each element in the sources which unpacked from the source map.
648
+ - `entryFilter` (Function) A filter function to execute for each element in the V8 list.
649
+ - `inline` (Boolean) Whether inline all scripts to the single HTML file.
628
650
 
629
651
  (see example: [report-coverage.spec.js](https://github.com/cenfun/monocart-reporter/blob/main/tests/report-coverage/report-coverage.spec.js))
630
652
 
@@ -725,7 +747,7 @@ const report = await attachCoverageReport(coverageList, test.info(), {
725
747
  | Minified code | N/A | ✅ | ❌ |
726
748
  | Code formatting | N/A | ✅ | ❌ |
727
749
 
728
- ## Global Coverage Report
750
+ ### Global Coverage Report
729
751
  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
752
  ```js
731
753
  // playwright.config.js
@@ -9,10 +9,13 @@ module.exports = {
9
9
  attachmentPath: null,
10
10
  // attachmentPath: (currentPath, extras) => `https://cenfun.github.io/monocart-reporter/${currentPath}`,
11
11
 
12
+ traceViewerUrl: 'https://trace.playwright.dev/?trace={traceUrl}',
13
+
12
14
  // global coverage settings for addCoverageReport API
13
15
  coverage: null,
14
16
  // coverage: {
15
17
  // unpackSourceMap: true,
18
+ // excludeDistFile: true,
16
19
  // sourceFilter: (sourceName) => sourceName.search(/\/src\/.+/) !== -1,
17
20
  // entryFilter: (entry) => {}
18
21
  // },
@@ -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;
@@ -70,6 +74,7 @@ const generateData = async (results) => {
70
74
  // suite and case types
71
75
  data.suiteTypes = ['project', 'file', 'describe', 'shard'];
72
76
  data.caseTypes = ['passed', 'flaky', 'skipped', 'failed'];
77
+ data.traceViewerUrl = options.traceViewerUrl;
73
78
 
74
79
  calculateSummary(data, options);
75
80
 
@@ -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
 
@@ -21,22 +21,34 @@ const defaultSourceFilter = (sourceName) => {
21
21
  };
22
22
 
23
23
  const defaultV8Options = {
24
+ // (Boolean) Whether to convert to Istanbul report
24
25
  toIstanbul: false,
25
26
 
27
+ // (Boolean) Whether to unpack all sources from the source map if a related source map file is found.
26
28
  unpackSourceMap: true,
29
+ // (Boolean) Whether to exclude the dist file (usually minified) if the sources are successfully unpacked from the source map.
27
30
  excludeDistFile: true,
31
+ // (Function) A filter function to execute for each element in the sources which unpacked from the source map.
28
32
  sourceFilter: defaultSourceFilter,
33
+ // (Function) A filter function to execute for each element in the V8 list.
29
34
  entryFilter: null
30
35
 
36
+ // (Array) Defaults to `[50, 80]`
31
37
  // watermarks: [50, 80],
38
+
39
+ // (Boolean) Whether inline all scripts to the single HTML file.
32
40
  // inline: false
33
41
  };
34
42
 
35
43
  const defaultIstanbulOptions = {
36
- entryFilter: null,
44
+
45
+ // (usually not used) source finder for Istanbul HTML report
37
46
  sourceFinder: null,
47
+
48
+ // (Boolean) Whether to create `lcov.info`
38
49
  lcov: false
39
50
 
51
+ // (Object) Istanbul watermarks, see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report)
40
52
  // watermarks: {},
41
53
  };
42
54
 
@@ -242,7 +254,7 @@ const generateCoverageReport = async (dataList, reporterOptions) => {
242
254
  v8list = v8list.concat(item.data);
243
255
  });
244
256
 
245
- // merge list, maybe collected multiple times
257
+ // merge list again for multiple v8list, maybe collected multiple times
246
258
  v8list = await mergeV8List(v8list, options);
247
259
 
248
260
  // const v8Path = path.resolve(__dirname, '../../.temp/v8-data.js');
@@ -254,7 +266,8 @@ const generateCoverageReport = async (dataList, reporterOptions) => {
254
266
  const report = await saveV8Report(v8list, options);
255
267
 
256
268
  return {
257
- type: report.type,
269
+ type: 'coverage',
270
+ name: 'Coverage',
258
271
  htmlPath: report.htmlPath,
259
272
  summary: report.summary
260
273
  };
@@ -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
  };