monocart-reporter 2.9.8 → 2.9.10

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
@@ -19,6 +19,7 @@
19
19
  * [Install](#install)
20
20
  * [Playwright Config](#playwright-config)
21
21
  * [Examples](#examples)
22
+ * [Tutorial](#tutorial)
22
23
  * [Output](#output)
23
24
  * [Reporter Options](#reporter-options)
24
25
  * [View Trace Online](#view-trace-online)
@@ -48,6 +49,7 @@
48
49
  - [Send and Receive Messages between Processes](#send-and-receive-messages-between-processes)
49
50
  * [Merge Shard Reports](#merge-shard-reports)
50
51
  * [onEnd Hook](#onend-hook)
52
+ * [onData Hook](#ondata-hook)
51
53
  * [Integration Examples](#integration-examples)
52
54
  * [Contributing](#contributing)
53
55
  * [Changelog](CHANGELOG.md)
@@ -87,6 +89,11 @@ Playwright Docs [https://playwright.dev/docs/test-reporters](https://playwright.
87
89
  - [monocart-reporter-examples](https://github.com/cenfun/monocart-reporter-examples)
88
90
  - [playwright-reporter-integrations](https://github.com/cenfun/playwright-reporter-integrations)
89
91
 
92
+ ## Tutorial
93
+ - [Playwright + Monocart = Next-Level Custom Reports! | Step-by-Step Tutorial!](https://www.youtube.com/watch?v=8Ae-lkFAG5Q)
94
+ - [Optimising Playwright Reporting Through Monocart](https://engineering.kablamo.com.au/posts/2024/optimising-playwright-reporting-through-monocart/)
95
+ - [Leveraging Playwright's Powerful End-to-End Testing, MongoDB, Data Fixtures for Live Execution Insights](https://www.linkedin.com/pulse/leveraging-playwrights-powerful-end-to-end-testing-data-kandukuri-ak6ac/)
96
+
90
97
  ## Output
91
98
  - path-to/your-filename.html
92
99
  Single HTML file (data compressed), easy to transfer/deploy or open directly anywhere
@@ -845,7 +852,7 @@ Attach a network report with API `attachNetworkReport(har, testInfo)`. Arguments
845
852
  - `har` HAR path (String) or HAR file buffer (Buffer). see [HAR 1.2 Spec](http://www.softwareishard.com/blog/har-12-spec/)
846
853
  - `testInfo` see [TestInfo](https://playwright.dev/docs/api/class-testinfo)
847
854
 
848
- Generate HAR with `recordHar` option in browser.newContext() (see example: [report-network.spec.js](https://github.com/cenfun/monocart-reporter/blob/main/tests/report-network/report-network.spec.js) preview [report](https://cenfun.github.io/monocart-reporter/network-1a18723ee59b36867898/index.html))
855
+ Generate HAR with `recordHar` option in browser.newContext() (see example: [report-network.spec.js](https://github.com/cenfun/monocart-reporter/blob/main/tests/report-network/report-network.spec.js) preview [report](https://cenfun.github.io/monocart-reporter/#page=report))
849
856
 
850
857
  ```js
851
858
  const fs = require('fs');
@@ -911,7 +918,7 @@ test('finally, attach HAR', async () => {
911
918
  await attachNetworkReport(harPath, test.info());
912
919
  });
913
920
  ```
914
- Preview [Network HTML Report](https://cenfun.github.io/monocart-reporter/network-da7f5b4cceb1e6280782/index.html)
921
+ Preview [Network HTML Report](https://cenfun.github.io/monocart-reporter/#page=report)
915
922
 
916
923
  ## Global State Management
917
924
  When tests are executed in [isolation](https://playwright.dev/docs/browser-contexts) mode, the reporter and each test may run in a different process, they cannot share data with each other. we can start a local WebSocket server to serve the global data, and read/write the global data with `useState` API from a test.
@@ -1145,6 +1152,24 @@ module.exports = {
1145
1152
  };
1146
1153
  ```
1147
1154
 
1155
+ ## onData hook
1156
+ The `onData` function will be executed after report data generated (before `onEnd`).
1157
+ ```js
1158
+ // playwright.config.js
1159
+ module.exports = {
1160
+ reporter: [
1161
+ ['monocart-reporter', {
1162
+ name: "My Test Report",
1163
+ outputFile: './monocart-report/index.html',
1164
+ onData: (reportData) => {
1165
+ // console.log('onData', reportData);
1166
+ reportData.name = 'My New Report Name';
1167
+ }
1168
+ }]
1169
+ ]
1170
+ };
1171
+ ```
1172
+
1148
1173
  ## Integration Examples
1149
1174
  By using the `onEnd` hook, we can integrate Playwright report with any other tools, such as:
1150
1175
  - [Email](https://github.com/cenfun/playwright-reporter-integrations/tree/main/send-email)
package/lib/common.js CHANGED
@@ -230,8 +230,13 @@ const getTrends = async (input) => {
230
230
  return [];
231
231
  }
232
232
 
233
+ // filter with one year ago
234
+ const date = new Date();
235
+ const oneYearAgo = date.setFullYear(date.getFullYear() - 1);
236
+
233
237
  // copy previous trends
234
- const trends = [].concat(data.trends || []);
238
+ const trends = [].concat(data.trends || []).filter((it) => it.date > oneYearAgo);
239
+
235
240
  trends.push(Util.getCurrentTrendInfo(data));
236
241
 
237
242
  return trends;
@@ -4,10 +4,10 @@ module.exports = () => ({
4
4
  value: 0,
5
5
  nav: true
6
6
  },
7
- passed: {
8
- name: 'Passed',
7
+ failed: {
8
+ name: 'Failed',
9
9
  value: 0,
10
- color: 'green',
10
+ color: '#d00',
11
11
  nav: true
12
12
  },
13
13
  flaky: {
@@ -22,10 +22,10 @@ module.exports = () => ({
22
22
  color: 'gray',
23
23
  nav: true
24
24
  },
25
- failed: {
26
- name: 'Failed',
25
+ passed: {
26
+ name: 'Passed',
27
27
  value: 0,
28
- color: '#d00',
28
+ color: 'green',
29
29
  nav: true
30
30
  },
31
31
 
@@ -60,21 +60,27 @@ module.exports = () => ({
60
60
  value: 0
61
61
  },
62
62
 
63
- retries: {
64
- name: 'Retries',
63
+ errors: {
64
+ name: 'Errors',
65
+ icon: 'error',
65
66
  value: 0
66
67
  },
67
68
 
68
- errors: {
69
- name: 'Errors',
69
+ retries: {
70
+ name: 'Retries',
71
+ icon: 'retry',
70
72
  value: 0
71
73
  },
74
+
72
75
  logs: {
73
76
  name: 'Logs',
77
+ icon: 'log',
74
78
  value: 0
75
79
  },
80
+
76
81
  attachments: {
77
82
  name: 'Attachments',
83
+ icon: 'attachment',
78
84
  value: 0
79
85
  }
80
86
  });
@@ -97,7 +97,7 @@ const generateData = async (results) => {
97
97
 
98
98
  // suite and case types
99
99
  data.suiteTypes = ['project', 'file', 'describe', 'shard'];
100
- data.caseTypes = ['passed', 'flaky', 'skipped', 'failed'];
100
+ data.caseTypes = ['failed', 'flaky', 'skipped', 'passed'];
101
101
  data.traceViewerUrl = options.traceViewerUrl;
102
102
  data.mermaid = generateMermaid(options);
103
103
  data.groupOptions = options.groupOptions;
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ const fs = require('fs');
1
2
  const path = require('path');
2
3
  const EC = require('eight-colors');
3
4
  const { getSystemInfo, getTickInfo } = require('./utils/system.js');
@@ -95,8 +96,30 @@ class MonocartReporter {
95
96
  }
96
97
 
97
98
  cleanOutputDir() {
98
- Util.initDir(this.options.outputDir);
99
- // console.log('=========================== ', 'cleanOutputDir');
99
+
100
+ // after trends
101
+ const outputDir = this.options.outputDir;
102
+ if (!fs.existsSync(outputDir)) {
103
+ return;
104
+ }
105
+
106
+ const list = fs.readdirSync(outputDir);
107
+ if (!list.length) {
108
+ return;
109
+ }
110
+
111
+ Util.logInfo('clean output dir ...');
112
+ for (const item of list) {
113
+
114
+ // console.log('remove', item);
115
+ try {
116
+ Util.rmSync(path.resolve(outputDir, item));
117
+ } catch (e) {
118
+ // console.log('=======================', e);
119
+ }
120
+
121
+ }
122
+
100
123
  }
101
124
 
102
125
  // ==========================================================================