forked from Slobo989/jasmine-2-testrail
/
jasmine-2-testrail.js
84 lines (72 loc) · 2.21 KB
/
jasmine-2-testrail.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
const JasmineConsoleReporter = require('jasmine-console-reporter');
const TestRail = require('testrail');
const Credentials = require('../../testrail-credentials');
const api = new TestRail({
host: Credentials.networkURL,
user: Credentials.username,
password: Credentials.password,
});
class Reporter extends JasmineConsoleReporter {
constructor() {
super()
this.caseids = []
this.results = []
}
createRun(projectId, suiteId) {
let now = new Date();
let options = {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
}
api.addRun(projectId, {
suite_id: suiteId, name: now.toLocaleString(['en-GB'], options), include_all: false, case_ids: this.caseids,
}).then((r) => {
console.log('Created new test run: ' + now.toLocaleString(['en-GB'], options))
api.addResultsForCases(r.id, { results: this.results })
.then(console.log('Added test results'))
.catch(error => { (error && error.message) ? console.log(error.message) : console.log(error); })
}).catch(error => { (error && error.message) ? console.log(error.message) : console.log(error);
})
}
specDone(spec) {
super.specDone(spec)
const id = spec.description.split(':')[0]
if (this.verbosity.specs) {
this.caseids.push(
parseInt(id, 10),
)
switch (spec.status) {
case 'pending':
this.results.push({
case_id: parseInt(id, 10),
status_id: 2,
comment: 'Intentionally skipped (xit).',
})
break;
case 'failed':
this.results.push({
case_id: parseInt(id, 10),
status_id: 5,
comment: spec.failedExpectations[0].message,
})
break;
case 'passed':
this.results.push({
case_id: parseInt(id, 10),
status_id: 1,
comment: 'Test passed successfully.',
})
break;
default:
// unknown status
break;
}
}
}
}
module.exports = Reporter;