-
Notifications
You must be signed in to change notification settings - Fork 2
/
TestSuiteResult.js
47 lines (40 loc) · 1.29 KB
/
TestSuiteResult.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
module.exports = class TestSuiteResult {
constructor(name, success, message) {
this.name = name;
this.success = success;
this.message = message || null;
this.results = [];
}
add(input){
// when an array is passed, add all the results
if( Array.isArray(input) ){
this.results = this.results.concat(input);
// otherwise, we just append the current test
} else {
this.results.push(input);
}
}
hasSuccess(){
var testSuiteSuccess = (typeof this.success == "undefined") ? false : Boolean(this.success);
// we should return false when either the suite has failed or any of the tests have failed
return testSuiteSuccess && !this.results.some((TestResult) => !TestResult.hasSuccess())
}
errors(){
return this.results
.filter((TestResult) => !TestResult.hasSuccess())
;
}
count(){
return this.results.length;
}
totalPassed(){
return this.results.reduce((total, TestResult) => total + (TestResult.hasSuccess() ? 1 : 0 ), 0);
}
totalFailed(){
// if we have a failure, but no tests this means we could not load the suite so must show at least 1 error
if( !this.success && (this.results.length === 0) ){
return 1;
}
return this.results.reduce((total, TestResult) => total + (TestResult.hasSuccess() ? 0 : 1 ), 0);
}
}