-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsanity-report-dev11.js
More file actions
55 lines (45 loc) · 1.38 KB
/
sanity-report-dev11.js
File metadata and controls
55 lines (45 loc) · 1.38 KB
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
import dotenv from "dotenv";
import fs from "fs";
dotenv.config();
const mochawesomeJsonOutput = fs.readFileSync(
"./mochawesome-report/mochawesome.json",
"utf-8"
);
const mochawesomeReport = JSON.parse(mochawesomeJsonOutput);
const totalTests = mochawesomeReport.stats.tests;
const passedTests = mochawesomeReport.stats.passes;
const failedTests = mochawesomeReport.stats.failures;
const resultMessage =
passedTests === totalTests
? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)`
: `:x: Failure (${passedTests} / ${totalTests} Passed)`;
const slackMessage = {
text: `
*Dev11, CMA SDK Full Sanity*
Result: ${resultMessage}
Failed Tests: ${failedTests}
View Report: <file://${process.cwd()}/mochawesome-report/sanity-report.html>
`,
};
const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL;
const sendSlackMessage = async (message) => {
const payload = {
text: message,
};
try {
const response = await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`Error sending message to Slack: ${response.statusText}`);
}
console.log("Message sent to Slack successfully");
} catch (error) {
console.error("Error:", error);
}
};
sendSlackMessage(slackMessage.text);