-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
72 lines (64 loc) · 2.15 KB
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const axios = require("axios");
const newman = require("newman");
require("dotenv").config();
const fs = require("fs");
// Run the API tests using Newman
newman.run(
{
collection: require("./collection/Dmoney-Users-B6.postman_collection.json"), // pointing to local JSON file.
iterationCount: 1,
reporters: ["cli", "htmlextra"],
reporter: {
htmlextra: {
export: "./Reports/report.html", // If not specified, the file will be written to `newman/` in the current working directory.
},
},
},
async function (err, summary) {
if (err) {
// console.log("I am From Error!!!.............");
// console.error(err);
// process.exit(1);
}
// Check if any test has failed
const failures = summary.run.failures.length;
//stats
// Extract stats
const { stats } = summary.run;
const summaryf = `
Total Requests:${stats.requests.total},
Failed Requests:${stats.requests.failed},
Total Assertions:${stats.assertions.total},
Failed Assertion:${failures}
`;
// if (failures > 0) {
// console.log("I am From Summary......");
// // console.log(summary.run);
// const message = `:x: ${failures} API request(s) failed assertion in Postman collection \n
// ${summaryf}
// `;
// axios.post(process.env.DISCORD_URL, {
// content: message,
// });
// } else {
// axios.post(process.env.DISCORD_URL, {
// content: "All API requests passed assertion in Postman collection",
// });
// }
try {
if (failures > 0) {
const message = `:x: ${failures} API request(s) failed assertion in Postman collection \n\n${summaryf}`;
await axios.post(process.env.DISCORD_URL, {
content: message,
});
} else {
await axios.post(process.env.DISCORD_URL, {
content: "All API requests passed assertion in Postman collection",
});
}
console.log("Discord message sent successfully");
} catch (error) {
console.error("Error sending Discord message:", error);
}
}
);