monocart-reporter 2.4.0 → 2.4.1

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
@@ -168,7 +168,7 @@ Separated metadata file (Already included in the above HTML and compressed, it c
168
168
 
169
169
  // onEnd hook
170
170
  onEnd: null
171
- // onEnd: async (reportData, capability) => {}
171
+ // onEnd: async (reportData, helper) => {}
172
172
  }
173
173
  ```
174
174
 
@@ -1036,7 +1036,7 @@ await merge(reportDataList, {
1036
1036
  attachmentPath: (currentPath, extras) => {
1037
1037
  // return `https://cenfun.github.io/monocart-reporter/${currentPath}`;
1038
1038
  },
1039
- onEnd: async (reportData, capability) => {
1039
+ onEnd: async (reportData, helper) => {
1040
1040
  // send email or third party integration
1041
1041
  }
1042
1042
  });
@@ -1061,9 +1061,12 @@ The `onEnd` function will be executed after report generated. Arguments:
1061
1061
  - `cwd`, `outputDir` and `outputFile` (String)
1062
1062
  - `htmlPath`, `jsonPath` and `summaryTable` (String)
1063
1063
  - ...
1064
- - `capability` APIs:
1065
- - `capability.forEach(callback)` Iterate over all rows of data (suites/cases/steps), return `false` will `break` loop.
1066
- - `capability.sendEmail(emailOptions)`
1064
+ - `helper` APIs:
1065
+ - `helper.find(callback)` Find item like array `find` function.
1066
+ - `helper.filter(callback)` Filter list like array `filter` function.
1067
+ - `helper.forEach(callback)` Iterate all rows of data (suites/cases/steps), return `break` will break the iteration.
1068
+ - `helper.sendEmail(emailOptions)`
1069
+
1067
1070
  ```js
1068
1071
  // playwright.config.js
1069
1072
  module.exports = {
@@ -1072,13 +1075,33 @@ module.exports = {
1072
1075
  name: "My Test Report",
1073
1076
  outputFile: './test-results/report.html',
1074
1077
  // async hook after report data generated
1075
- onEnd: async (reportData, capability) => {
1078
+ onEnd: async (reportData, helper) => {
1076
1079
  // console.log(reportData.summary);
1080
+
1081
+ // find a test by title
1082
+ const myCase = helper.find((item, parent) => item.type === 'case' && item.title.includes('inline tag'));
1083
+ console.log(myCase && myCase.title);
1084
+
1085
+ // find a suite by title
1086
+ const mySuite = helper.find((item, parent) => item.type === 'suite' && item.title.includes('new syntax'));
1087
+ console.log(mySuite && mySuite.title);
1088
+
1089
+ // filter failed cases
1090
+ const failedCases = helper.filter((item, parent) => item.type === 'case' && item.caseType === 'failed');
1091
+ console.log(failedCases.map((it) => it.title));
1092
+
1093
+ // Iterate all items
1094
+ helper.forEach((item, parent) => {
1095
+ // do something
1096
+ });
1097
+
1098
+
1077
1099
  }
1078
1100
  }]
1079
1101
  ]
1080
1102
  };
1081
1103
  ```
1104
+
1082
1105
  ## Send Email
1083
1106
  - Simply send email with [nodemailer](https://nodemailer.com)
1084
1107
  - Example: [send-email](https://github.com/cenfun/monocart-reporter-examples/tree/main/integrations/send-email)
@@ -64,5 +64,5 @@ module.exports = {
64
64
 
65
65
  // onEnd hook
66
66
  onEnd: null
67
- // onEnd: async (reportData, capability) => {}
67
+ // onEnd: async (reportData, helper) => {}
68
68
  };
@@ -40,16 +40,6 @@ const generateHtml = async (outputDir, htmlFile, reportData, inline) => {
40
40
  return htmlPath;
41
41
  };
42
42
 
43
- const sendEmail = (emailOptions) => {
44
- if (!emailOptions.transport || !emailOptions.message) {
45
- Util.logError('invalid email options, transport and message are required (https://nodemailer.com/)');
46
- return;
47
- }
48
- Util.logInfo('sending email ...');
49
- const transporter = nodemailer.createTransport(emailOptions.transport);
50
- return transporter.sendMail(emailOptions.message);
51
- };
52
-
53
43
  const showTestResults = (reportData) => {
54
44
  Util.logInfo(EC.cyan(reportData.name));
55
45
 
@@ -155,15 +145,46 @@ const onEndHandler = async (reportData, options) => {
155
145
  // generate email data
156
146
  emailPlugin(reportData);
157
147
 
158
- // forEach rows API
159
- const forEach = (callback) => {
160
- Util.forEach(reportData.rows, callback);
148
+ // helper APIs
149
+ const helper = {
150
+
151
+ find: (callback) => {
152
+ let foundItem;
153
+ Util.forEach(reportData.rows, (item, parent) => {
154
+ if (callback(item, parent)) {
155
+ foundItem = item;
156
+ return 'break';
157
+ }
158
+ });
159
+ return foundItem;
160
+ },
161
+
162
+ filter: (callback) => {
163
+ const list = [];
164
+ Util.forEach(reportData.rows, (item, parent) => {
165
+ if (callback(item, parent)) {
166
+ list.push(item);
167
+ }
168
+ });
169
+ return list;
170
+ },
171
+
172
+ forEach: (callback) => {
173
+ Util.forEach(reportData.rows, callback);
174
+ },
175
+
176
+ sendEmail: (emailOptions) => {
177
+ if (!emailOptions.transport || !emailOptions.message) {
178
+ Util.logError('invalid email options, transport and message are required (https://nodemailer.com/)');
179
+ return;
180
+ }
181
+ Util.logInfo('sending email ...');
182
+ const transporter = nodemailer.createTransport(emailOptions.transport);
183
+ return transporter.sendMail(emailOptions.message);
184
+ }
161
185
  };
162
186
 
163
- await onEnd(reportData, {
164
- sendEmail,
165
- forEach
166
- });
187
+ await onEnd(reportData, helper);
167
188
  };
168
189
 
169
190
 
package/lib/index.d.ts CHANGED
@@ -27,6 +27,23 @@ export type {
27
27
  AddedResults
28
28
  }
29
29
 
30
+ export interface Helper {
31
+
32
+ find: (callback: ((item: any, parent: any) => void)) => any;
33
+ filter: (callback: ((item: any, parent: any) => void)) => any[];
34
+ /** Traverse all cases, suites, and steps. */
35
+ forEach: (callback: ((item: any, parent: any) => void | "break")) => void;
36
+
37
+ /** send email with nodemailer: https://nodemailer.com/ */
38
+ sendEmail: (emailOptions: {
39
+ /** email transport: https://nodemailer.com/smtp/ */
40
+ transport: any,
41
+ /** email message: https://nodemailer.com/message/ */
42
+ message: any
43
+ }) => Promise<void>;
44
+
45
+ }
46
+
30
47
  export type MonocartReporterOptions = {
31
48
  /** the report name */
32
49
  name?: string,
@@ -112,17 +129,7 @@ export type MonocartReporterOptions = {
112
129
  }
113
130
 
114
131
  /** onEnd hook: https://github.com/cenfun/monocart-reporter?#onend-hook */
115
- onEnd?: (reportData: any, capability: {
116
- /** send email with nodemailer: https://nodemailer.com/ */
117
- sendEmail?: (emailOptions: {
118
- /** email transport: https://nodemailer.com/smtp/ */
119
- transport: any,
120
- /** email message: https://nodemailer.com/message/ */
121
- message: any
122
- }) => Promise<void>,
123
- /** Traverse all cases, suites, and steps. */
124
- forEach?: (callback: ((item: any) => void)) => void
125
- }) => Promise<void>
132
+ onEnd?: (reportData: any, helper: Helper) => Promise<void>
126
133
 
127
134
  }
128
135
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "A playwright test reporter. Shows suites/cases/steps with tree style, markdown annotations, custom columns/formatters/data collection visitors, console logs, style tags, send email.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -42,18 +42,18 @@
42
42
  "url": "git+https://github.com/cenfun/monocart-reporter.git"
43
43
  },
44
44
  "dependencies": {
45
- "console-grid": "~2.2.1",
45
+ "console-grid": "~2.2.2",
46
46
  "eight-colors": "~1.3.0",
47
47
  "koa": "~2.15.0",
48
48
  "koa-static-resolver": "~1.0.5",
49
49
  "lz-utils": "~2.0.2",
50
- "monocart-coverage-reports": "~2.5.8",
50
+ "monocart-coverage-reports": "~2.6.5",
51
51
  "monocart-formatter": "~2.3.2",
52
- "nodemailer": "~6.9.10",
52
+ "nodemailer": "~6.9.11",
53
53
  "turbogrid": "~3.0.13"
54
54
  },
55
55
  "devDependencies": {
56
- "@playwright/test": "^1.42.0",
56
+ "@playwright/test": "^1.42.1",
57
57
  "axios": "^1.6.7",
58
58
  "dotenv": "^16.4.5",
59
59
  "eslint": "^8.57.0",
@@ -61,8 +61,8 @@
61
61
  "eslint-plugin-html": "^8.0.0",
62
62
  "eslint-plugin-vue": "^9.22.0",
63
63
  "open": "8.4.2",
64
- "stylelint": "^15.11.0",
65
- "stylelint-config-plus": "^1.0.4",
64
+ "stylelint": "^16.2.1",
65
+ "stylelint-config-plus": "^1.1.0",
66
66
  "vine-ui": "^3.1.13"
67
67
  }
68
68
  }