-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmocha-rp-reporter.js
135 lines (115 loc) · 3.8 KB
/
mocha-rp-reporter.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"use strict";
const mocha = require('mocha');
const path = require('path');
function RPReporter(runner, options) {
mocha.reporters.Base.call(this, runner);
let config;
let launchId = null;
let suiteIds = {};
let testIds = {};
// load config
try {
config = options.reporterOptions.configOptions ? options.reporterOptions.configOptions : require(path.join(process.cwd(), options.reporterOptions.configFile));
} catch (err) {
console.error(`Failed to load config. Error: ${err}`);
}
let connector = new (require("./rp_connector_sync"))(config);
runner.on('pass', function(test){
});
runner.on('fail', function(test, err){
try {
connector.sendLog(testIds[test.title], {
level: connector.RP_LEVEL.FAILED,
message: err.message
});
} catch (err) {
console.log(`Failed to send log for item. Error: ${err}`);
}
});
runner.on('start', function() {
try {
let res = connector.startLaunch();
launchId = res.body.id;
} catch (err) {
console.log(`Failed to launch run. Error: ${err}`);
}
});
runner.on('end', function(){
try {
connector.finishLaunch(launchId);
} catch (err) {
console.log(`Failed to finish run. Error: ${err}`);
}
});
runner.on('suite', function(suite){
if(suite.title === "") {
return true;
} else {
try {
let res = connector.startRootItem({
name: suite.title,
launch: launchId,
description: suite.fullTitle(),
type: connector.RP_ITEM_TYPE.SUITE
});
suiteIds[suite.title] = res.body.id;
} catch (err) {
console.log(`Failed to create root item. Error: ${err}`);
}
}
});
runner.on('suite end', function(suite){
try {
connector.finishItem({
status: suite.tests.filter(test => test.state === "failed").length > 0 ? "failed" : "passed",
id: suiteIds[suite.title]
});
} catch (err) {
console.log(`Failed to create child item. Error: ${err}`);
}
});
runner.on('test', function(test){
try {
let res = connector.startChildItem({
name: test.title,
launch: launchId,
description: test.fullTitle(),
type: connector.RP_ITEM_TYPE.TEST
}, suiteIds[test.parent.title]);
testIds[test.title] = res.body.id;
} catch (err) {
console.log(`Failed to create child item. Error: ${err}`);
}
});
runner.on('pending', function (test) {
try {
let res = connector.startChildItem({
name: test.title,
launch: launchId,
description: test.fullTitle(),
type: connector.RP_ITEM_TYPE.TEST
}, suiteIds[test.parent.title]);
connector.sendLog(res.body.id, {
level: connector.RP_LEVEL.SKIPPED,
message: test.title
})
connector.finishItem({
status: connector.RP_STATUS.SKIPPED,
id: res.body.id
});
} catch (err) {
console.log(`Failed to create child item. Error: ${err}`);
}
});
runner.on('test end', function(test){
try {
connector.finishItem({
status: test.state,
id: testIds[test.title]
});
} catch (err) {
console.log(`Failed to create child item. Error: ${err}`);
}
});
}
module.exports = RPReporter;