forked from avidit/newman-reporter-slack
/
index.js
76 lines (61 loc) · 2.17 KB
/
index.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
73
74
75
76
class LineReporter {
constructor(emitter, reporterOptions) {
const token = process.env.LINE_TOKEN || reporterOptions.token;
const summaryFlag = process.env.LINE_SUMMARY || reporterOptions.summary;
const resultFlag = process.env.LINE_RESULT || reporterOptions.result;
if (!token) {
console.log('please provide Line token');
return;
}
emitter.on('done', (err, summary) => {
if (err) {
return;
}
let run = summary.run;
let executions = summary.run.executions;
let totalFailures = summary.run.failures;
let text = '\n\nRun: ' + summary.collection.name;
text += '\nEnv: ' + summary.environment.name;
if (summaryFlag) {
text += '\n\nSummary: ';
text += '\nTotal of script: ' + run.stats['testScripts'].total;
text += '\nTotal of failed script: ' + run.stats['testScripts'].failed;
text += '\n\nTotal of assertions: ' + run.stats['assertions'].total;
text += '\nTotal of failed assertions: ' + run.stats['assertions'].failed;
}
if (resultFlag) {
text += '\n\nResult: ';
for (let execution of executions) {
for (let item of execution.assertions) {
if (item.error == null) {
text += '\nCase: ' + item.assertion;
}
}
}
}
let message;
if (totalFailures.length > 0) {
text += '\n\nAlert:';
for (let failure of totalFailures) {
text += '\nCase: ' + failure.error.test;
}
message = {
message: text,
stickerPackageId: 11538,
stickerId: 51626518
}
} else {
message = {
message: text,
stickerPackageId: 11537,
stickerId: 52002740
}
}
const lineNotify = require('line-notify-nodejs')(token);
lineNotify.notify(message).then(() => {
console.log('send completed!');
});
});
}
}
module.exports = LineReporter;