monocart-reporter 2.4.0 → 2.4.2
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 +29 -6
- package/lib/default/options.js +1 -1
- package/lib/generate-report.js +38 -17
- package/lib/index.d.ts +18 -11
- package/lib/packages/monocart-reporter-app.js +1 -1
- package/package.json +7 -7
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,
|
|
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,
|
|
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
|
-
- `
|
|
1065
|
-
- `
|
|
1066
|
-
- `
|
|
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,
|
|
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)
|
package/lib/default/options.js
CHANGED
package/lib/generate-report.js
CHANGED
|
@@ -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
|
-
//
|
|
159
|
-
const
|
|
160
|
-
|
|
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,
|
|
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
|
|