This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
complete.html
248 lines (171 loc) · 8.79 KB
/
complete.html
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>YUIMetroTester: Completed Tests</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.1.0/css/ui-light.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0/js/base.js"></script>
<script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
<!-- YUIMetroTester references -->
<script src="/js/yui3/build/yui/yui.js"></script>
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
</head>
<body>
<h1>Tests Complete.</h1>
<h2 id="num-failed-tests"></h2>
<div id="test-results">
</div>
<button class="backToFront">Back to main test page.</button>
<script>
YUI().use('node', function (Y) {
Y.one('.backToFront').on('click', function () {
document.location.href = 'default.html';
});
});
</script>
<script>
YUI().use('node', 'event', 'test', function (Y) {
var localStorage = Y.config.win.localStorage,
results = JSON.parse(localStorage['YUI.TestResults']),
totalFailed = 0;
YUI.YUITest.TestFormat.CustomTAP = function (results) {
var currentTestNum = 1;
function serializeToTAP(results) {
var text = "";
switch (results.type) {
case "test":
if (results.result != "ignore") {
text = "ok " + (currentTestNum++) + " - " + results.name;
if (results.result == "fail") {
text = "not " + text + " - " + results.message;
}
text += "\n";
} else {
//text = "#Ignored test " + results.name + "\n";
}
break;
case "testcase":
//text = "#Begin testcase " + results.name + "(" + results.failed + " failed of " + results.total + ")\n";
for (var prop in results) {
if (results.hasOwnProperty(prop)) {
if (results[prop] && typeof results[prop] == "object" && !(results[prop] instanceof Array)) {
text += serializeToTAP(results[prop]);
}
}
}
//text += "#End testcase " + results.name + "\n";
break;
case "testsuite":
//text = "#Begin testsuite " + results.name + "(" + results.failed + " failed of " + results.total + ")\n";
for (var prop in results) {
if (results.hasOwnProperty(prop)) {
if (results[prop] && typeof results[prop] == "object" && !(results[prop] instanceof Array)) {
text += serializeToTAP(results[prop]);
}
}
}
//text += "#End testsuite " + results.name + "\n";
break;
case "report":
for (var prop in results) {
if (results.hasOwnProperty(prop)) {
if (results[prop] && typeof results[prop] == "object" && !(results[prop] instanceof Array)) {
text += serializeToTAP(results[prop]);
}
}
}
//no default
}
return text;
}
return "1.." + results.total + "\n" + serializeToTAP(results);
}
Y.Array.each(results, function (val, key, obj) {
totalFailed += val.failed;
Y.Object.each(val, function (v, k, o) {
if (Y.Lang.isObject(v)) {
//sub object could be suite or case
Y.log("type:" + v.type);
if (v.type === "testcase") {
killTestCases(v);
} else {
if (v.type === "testsuite") {
Y.Object.each(v, function (vv, kk, oo) {
if (Y.Lang.isObject(vv)) {
if (vv.type === "testcase") {
killTestCases(vv);
}
}
});
}
}
}
}); //end Y.Object
}); //end Y.Array
function killTestCases(obj) {
Y.Object.each(obj, function (v, k, o) {
if (Y.Lang.isObject(v)) {
if (v.result && v.result === "pass") {
delete (o[k]);
}
}
})
};
//Display Test Results
var displayTestResults = function () {
var tap,
totalFailed = 0,
heading = Y.one("#num-failed-tests");
Y.Array.each(results, function (item, index, array) {
totalFailed += item.failed;
YUI.YUITest.TestRunner._lastResults = item;
tap += YUI.YUITest.TestRunner.getResults(YUI.YUITest.TestFormat.CustomTAP);
});
Y.one('h1').setContent(localStorage['YUI.CurrentComponent'] + ' tests completed.');
tap.replace("\n", "<br/>");
if (totalFailed === 0) {
heading.setHTML("All tests passed!").addClass("passed");
}
else if (totalFailed === 1) {
heading.setHTML("There was " + totalFailed + " failing test.").addClass("failed");
Y.one("#test-results").set('innerText', tap);
}
else if (totalFailed > 1) {
heading.setHTML("There were " + totalFailed + " failing tests.").addClass("failed");
Y.one("#test-results").set('innerText', tap);
}
}
var saveTestResults = function () {
var pckg = Windows.ApplicationModel.Package.current;
var installedLocation = pckg.installedLocation;
var results = JSON.parse(localStorage['YUI.TestResults']);
var str = '[';
for (var j = 0; j < results.length; j++) {
str += JSON.stringify(results[j]);
if (results[j + 1]) {
str += ',';
}
}
str += ']';
installedLocation.getFolderAsync('js').done(function (folder) {
var currentComponent = window.localStorage['YUI.CurrentComponent'];
WinJS.Application.local.writeText('results-' + currentComponent + '.txt', str).done(function () {
console.log("Results written to results-" + currentComponent + ".txt");
});
clearLocalStorage();
});
}
var clearLocalStorage = function () {
localStorage.removeItem("YUI.Tests");
localStorage.removeItem("YUI.TestResults");
localStorage.removeItem("YUI.TestsHash");
localStorage.removeItem("YUI.CurrentComponent");
}
displayTestResults();
saveTestResults();
});
</script>
</body>
</html>