-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsuite.js
153 lines (125 loc) · 2.95 KB
/
testsuite.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var Category = function(suite,level,name,tests)
{
var self = this;
this.children = [];
this.level = level;
this.name = name;
this.suite = suite;
if( typeof(tests) == "string" )
throw "Malformed tests.js";
var keys = [];
$.each(tests,function(part) {
keys.push(part);
});
$.each(keys.sort(),function(i,part) {
self.children.push(
(part.indexOf(".") != -1)
? new Test(suite,part,tests[part])
: new Category(suite,level+1,part,tests[part])
);
});
this.execute = function(node)
{
var elem = document.createElement("div");
elem.className = "category category-level-" + this.level;
if( this.level )
{
elem.innerHTML += "<h" + this.level + ">" + this.name + "</h" + this.level + ">";
}
$(this.children).each(function(i,child) {
child.execute(elem);
});
node.appendChild(elem);
}
};
var Test = function(suite,name,script)
{
var self = this;
this.name = name;
this.script = script;
this.suite = suite;
this.status = "pending";
suite.addTest(this);
function parseMessage(req)
{
if( /^\s*<!-- Railo/.test(req.responseText) )
{
var match = req.responseText.match(/>Message<\/td>\s*.*?">(.*?)<\/td>/);
return match ? match[1] : "";
}
return req.statusText;
}
function finishTest(status,message)
{
self.element.removeClass("status-pending");
self.element.addClass("status-" + status.toLowerCase());
$("span",self.element).html(status.toUpperCase() + ":");
$(".message",self.element).html(message);
self.status = status;
self.suite.finishTest(self);
}
this.execute = function(node)
{
var elem = document.createElement("div");
elem.className = "test status-pending";
elem.id = this.name;
elem.innerHTML = "<span class='status'>PENDING:</span><a></a><div class='message'></div>";
this.element = $(elem);
$("a",this.element)
.attr("href",this.script)
.attr("target","_blank")
.text(this.name);
$.ajax({
url:this.script,
success:function(data)
{
if( /^\s*success.\s*$/.test(data) )
{
finishTest("pass","");
}
else
{
finishTest("fail",data);
}
},
error:function(req,status)
{
finishTest("fail",parseMessage(req));
}
});
node.appendChild(elem);
}
};
var TestSuite = function(tests)
{
var self = this;
function updateStatus(values)
{
$("#run-status")
.data({"pending":values.pending,"pass":values.pass,"fail":values.fail})
.html(
" (Pass: " + values.pass
+ ", Fail: " + values.fail
+ (values.pending ? (", Pending: " + values.pending) : "")
+ ")"
);
}
this.execute = function()
{
updateStatus({"pending":this.tests.length,"pass":0,"fail":0});
this.categories.execute(document.body);
}
this.addTest = function(test)
{
this.tests.push(test);
}
this.finishTest = function(test)
{
var data = $("#run-status").data();
data.pending--;
data[test.status]++;
updateStatus(data);
}
this.tests = [];
this.categories = new Category(this,0,"",tests);
};