-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteal-qunit.js
124 lines (107 loc) · 2.89 KB
/
steal-qunit.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
"format amd";
define([
"@loader",
"qunit/qunit/qunit",
"qunit/qunit/qunit.css"
], function(loader, QUnit){
if(loader.has("live-reload")) {
setupLiveReload();
}
setupSauceLabsReporting();
function setupLiveReload(){
QUnit.done(updateResults);
function findModule(name) {
var mods = QUnit.config.modules;
return mods.filter(function(mod){
return mod.name === name;
}).pop();
}
function findTestResult(mod, id) {
var tests = mod.tests || [];
return tests.filter(function(test){
return test.testId === id;
})[0];
}
// Check to make sure all tests have passed and update the banner class.
function updateResults() {
var tests = document.getElementById("qunit-tests").children;
var node, id, test, moduleName, mod;
passed = true, removedNodes = [];
for(var i = 0, len = tests.length; i < len; i++) {
node = tests.item(i);
id = node.id.split("-").pop();
moduleName = node.querySelector(".module-name").textContent;
mod = findModule(moduleName);
test = findTestResult(mod, id);
// If we found a test result, check if it passed.
if(test) {
removeAllButLast(node, "runtime");
if(node.hasAttribute && node.hasAttribute("class") &&
node.className !== "pass") {
passed = false;
break;
}
}
// If we didn't find a test result this test must have been removed
// so we just want to remove it from the UI.
else {
removedNodes.push(node);
}
}
removedNodes.forEach(function(node){
node.parentNode.removeChild(node);
});
document.getElementById("qunit-banner").className = passed ?
"qunit-pass" : "qunit-fail";
}
function removeAllButLast(parent, className){
var node, nodes = [];
var children = parent.children;
for(var i = 0, len = children.length; i < len; i++) {
node = children.item(i);
if(node.className === className) nodes.push(node);
}
while(nodes.length > 1) {
node = nodes.shift();
parent.removeChild(node);
}
}
}
function setupSauceLabsReporting() {
var log = [];
QUnit.done(function (test_results) {
var tests = [];
for(var i = 0, len = log.length; i < len; i++) {
var details = log[i];
tests.push({
name: details.name,
result: details.result,
expected: details.expected,
actual: details.actual,
source: details.source
});
}
test_results.tests = tests;
window.global_test_results = test_results;
});
QUnit.testStart(function(testDetails){
QUnit.log(function(details){
if (!details.result) {
details.name = testDetails.name;
log.push(details);
}
});
});
}
QUnit.config.autostart = false;
steal.done().then(function() {
if (window.Testee && window.Testee.init) {
Testee.init();
}
var qunitVersion = Number(QUnit.version.split('.')[0]);
if(qunitVersion < 2) {
QUnit.load();
}
});
return QUnit;
});