monocart-reporter 2.0.3 → 2.0.4

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.
@@ -11,7 +11,6 @@ const generateJson = (outputDir, htmlFile, reportData) => {
11
11
  let jsonPath = path.resolve(outputDir, `${filename}.json`);
12
12
  Util.writeJSONSync(jsonPath, reportData);
13
13
  jsonPath = Util.relativePath(jsonPath);
14
- Util.logInfo(`json report: ${EC.cyan(jsonPath)}`);
15
14
  return jsonPath;
16
15
  };
17
16
 
@@ -37,10 +36,6 @@ const generateHtml = async (outputDir, htmlFile, reportData, inline) => {
37
36
  };
38
37
 
39
38
  const htmlPath = await Util.saveHtmlReport(options);
40
- Util.logInfo(`html report: ${EC.cyan(htmlPath)}`);
41
-
42
- const cmd = `npx monocart show-report ${htmlPath}`;
43
- Util.logInfo(`view report: ${EC.cyan(cmd)}`);
44
39
 
45
40
  return htmlPath;
46
41
  };
@@ -56,19 +51,20 @@ const sendEmail = (emailOptions) => {
56
51
  };
57
52
 
58
53
  const showTestResults = (reportData) => {
59
- Util.logInfo(`test results: ${EC.cyan(reportData.name)}`);
54
+ Util.logInfo(`test results: ${reportData.name}`);
60
55
 
61
56
  const summary = reportData.summary;
62
57
 
63
58
  const colorHandler = (item, row) => {
64
59
 
65
- if (['failed', 'errors'].includes(item.id) && item.value > 0) {
60
+ // do not show 'errors' in red
61
+ if (['failed'].includes(item.id) && item.value > 0) {
66
62
  row.name = EC.red(row.name);
67
63
  row.value = EC.red(row.value);
68
64
  return;
69
65
  }
70
66
 
71
- if (['flaky', 'retries'].includes(item.id) && item.value > 0) {
67
+ if (['flaky'].includes(item.id) && item.value > 0) {
72
68
  row.name = EC.yellow(row.name);
73
69
  row.value = EC.yellow(row.value);
74
70
  return;
@@ -121,9 +117,12 @@ const showTestResults = (reportData) => {
121
117
  };
122
118
  });
123
119
 
120
+ // for shards
121
+ const system = Array.isArray(reportData.system) ? reportData.system[0] : reportData.system;
122
+
124
123
  rows = rows.concat([{
125
124
  name: 'Playwright',
126
- value: `v${reportData.system.playwright}`
125
+ value: `v${system.playwright}`
127
126
  }, {
128
127
  name: 'Date',
129
128
  value: new Date(reportData.date).toLocaleString()
@@ -146,11 +145,31 @@ const showTestResults = (reportData) => {
146
145
 
147
146
  };
148
147
 
148
+ const onEndHandler = async (reportData, options) => {
149
+ // onEnd callback
150
+ const onEnd = options.onEnd;
151
+ if (typeof onEnd !== 'function') {
152
+ return;
153
+ }
154
+
155
+ // generate email data
156
+ emailPlugin(reportData);
157
+
158
+ // forEach rows API
159
+ const forEach = (callback) => {
160
+ Util.forEach(reportData.rows, callback);
161
+ };
162
+
163
+ await onEnd(reportData, {
164
+ sendEmail,
165
+ forEach
166
+ });
167
+ };
168
+
149
169
 
150
170
  const generateReport = async (reportData, options) => {
151
171
 
152
172
  Util.logInfo('generating test report ...');
153
- showTestResults(reportData);
154
173
 
155
174
  const {
156
175
  outputFile, outputDir, artifacts
@@ -163,6 +182,12 @@ const generateReport = async (reportData, options) => {
163
182
  // convert path to relative reporter
164
183
  report.path = Util.relativePath(report.path, outputDir);
165
184
  });
185
+
186
+ reportData.summary.artifacts = {
187
+ name: 'Artifacts',
188
+ value: artifacts.length
189
+ };
190
+
166
191
  }
167
192
 
168
193
  // console.log(reportData);
@@ -178,30 +203,19 @@ const generateReport = async (reportData, options) => {
178
203
  }
179
204
  const htmlPath = await generateHtml(outputDir, htmlFile, reportData, inline);
180
205
 
181
- // onEnd callback
182
- const onEnd = options.onEnd;
183
- if (typeof onEnd !== 'function') {
184
- return;
185
- }
186
-
187
206
  // for onEnd after saved
188
207
  Object.assign(reportData, {
189
208
  htmlPath,
190
209
  jsonPath
191
210
  });
192
211
 
193
- // generate email data
194
- emailPlugin(reportData);
212
+ await onEndHandler(reportData, options);
195
213
 
196
- // forEach rows API
197
- const forEach = (callback) => {
198
- Util.forEach(reportData.rows, callback);
199
- };
214
+ // after onEnd for summary changes
215
+ showTestResults(reportData);
200
216
 
201
- return onEnd(reportData, {
202
- sendEmail,
203
- forEach
204
- });
217
+ Util.logInfo(`html report: ${EC.cyan(htmlPath)} (json: ${jsonPath})`);
218
+ Util.logInfo(`view report: ${EC.cyan(`npx monocart show-report ${htmlPath}`)}`);
205
219
 
206
220
  };
207
221
 
package/lib/index.js CHANGED
@@ -17,6 +17,8 @@ const Util = require('./utils/util.js');
17
17
  // https://playwright.dev/docs/test-reporters#custom-reporters
18
18
  class Reporter {
19
19
 
20
+ static Util = Util;
21
+
20
22
  static merge = merge;
21
23
 
22
24
  static attachAuditReport = attachAuditReport;
package/lib/index.mjs CHANGED
@@ -3,6 +3,8 @@ import MonocartReporter from './index.js';
3
3
  export default MonocartReporter;
4
4
  export { MonocartReporter };
5
5
 
6
+ export const Util = MonocartReporter.Util;
7
+
6
8
  export const merge = MonocartReporter.merge;
7
9
 
8
10
  export const attachAuditReport = MonocartReporter.attachAuditReport;