-
Notifications
You must be signed in to change notification settings - Fork 2
/
reporter.js
115 lines (105 loc) · 3.17 KB
/
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
function getUniqueBrowserNames(jsonstr){
var browserArray = new Array();
for (var j = 0; j < jsonstr.length; j++) {
var browsername = getBrowserNameFromResult(jsonstr[j]);
browserArray.push(browsername);
}
return browserArray.filter(uniqueFilter);
}
function getBrowserNameFromResult(result){
return result.description.split('|')[1];
}
function getTestNameFromResult(result){
return result.description.split('|')[0]
}
function uniqueFilter(value, index, self) {
return self.indexOf(value) === index;
}
function determineTestStatus(run){
var assertions = run.assertions;
var runDuration = run.duration;
var assertionsArray = new Array();
var passed = "";
var failedAssertions = new Array();
for (var i = 0; i < assertions.length; i++) {
assertionsArray.push(assertions[i].passed);
}
if (assertionsArray.length > 0) {
for (var j = 0; j < assertionsArray.length; j++) {
if (assertionsArray[j] == false) {
failedAssertions.push("failed");
}
if (failedAssertions.length > 0) {
passed = "false";
}
if (failedAssertions.length <= 0) {
if(runDuration <= 1) {
passed = "Skipped";
}else {
passed = "true";
}
}
}
} else {
passed = "true";
}
return passed;
}
function countPassed(allResults){
var pass = 0;
for (var p1 = 0; p1 < allResults.length; p1++) {
if (allResults[p1] === "true")
pass++;
}
return pass;
}
function countFailed(allResults){
var fail = 0;
for (var p1 = 0; p1 < allResults.length; p1++) {
if(allResults[p1] === "false")
fail++;
}
return fail;
}
function countSkipped(allResults){
var skipped = 0;
for (var p1 = 0; p1 < allResults.length; p1++) {
if(allResults[p1] === "Skipped")
skipped++;
}
return skipped;
}
/**
* Escapes all potentially dangerous characters, so that the
* resulting string can be safely inserted into attribute or
* element text.
* @param value
* @returns {string} escaped text
*/
function encodeEntities(value) {
var SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
// Match everything outside of normal chars and " (quote character)
NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g;
return value.
replace(/&/g, '&').
replace(SURROGATE_PAIR_REGEXP, function(value) {
var hi = value.charCodeAt(0);
var low = value.charCodeAt(1);
return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
}).
replace(NON_ALPHANUMERIC_REGEXP, function(value) {
return '&#' + value.charCodeAt(0) + ';';
}).
replace(/</g, '<').
replace(/>/g, '>');
}
module.exports = {
getUniqueBrowserNames: getUniqueBrowserNames,
getBrowserNameFromResult: getBrowserNameFromResult,
getTestNameFromResult: getTestNameFromResult,
determineTestStatus: determineTestStatus,
countPassed: countPassed,
countFailed: countFailed,
countSkipped: countSkipped,
encodeEntities: encodeEntities
};