This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqooxdoo-adapter.js
204 lines (172 loc) · 6.31 KB
/
qooxdoo-adapter.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
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
(function(window) {
var formatError = function (error) {
var trace = [];
if (error instanceof qx.core.AssertionError) {
trace = error.getStackTrace();
if (error.getComment()) {
trace.unshift(error.getComment()+": "+error.message);
} else {
trace.unshift(error.message);
}
} else {
trace = qx.dev.StackTrace.getStackTraceFromError(error);
trace.unshift(error.message);
}
return trace.join("\n\t");
};
var createQooxdooStartFn = function(tc) {
return function () {
var suiteResults = {};
var totalTests;
var testCount;
var testList = [];
var testResult;
var currentTest;
var runNext = function() {
if (currentTest) {
var results = suiteResults[currentTest.getFullName()];
if (results && (results.status === "failure" || results.status === "error")) {
if (currentTest.getTestClass().getSandbox) {
// restore sandbox on failed tests, because if the test is using spies/stubs/mockups
// which have been initialized + restored inside the test function and not in setUp/tearDown
// the restore part might not have been executed
currentTest.getTestClass().getSandbox().restore();
}
}
}
currentTest = testList.shift();
setTimeout(function runTest() {
currentTest.run(testResult);
}, 5);
};
var addListeners = function(testResult) {
testResult.addListener("startTest", function(e) {
var testName = e.getData().getFullName();
// if we aready have a result, this is a resumed async test
if (!suiteResults[testName]) {
suiteResults[testName] = {
startTime: Date.now(),
exceptions: []
};
} else if (suiteResults[testName].status !== "wait") {
// test was executed before, clear old exceptions
suiteResults[testName].exceptions = [];
}
suiteResults[testName].status = "startTest";
});
testResult.addListener("failure", function(e) {
e.getData().forEach(function(errMap) {
var suiteResult = suiteResults[errMap.test.getFullName()];
suiteResult.status = "failure";
suiteResult.exceptions.push(formatError(errMap.exception));
});
});
testResult.addListener("error", function(e) {
e.getData().forEach(function(errMap) {
window.console.warn(errMap.test.getFullName() + " : Unexpected exception");
var suiteResult = suiteResults[errMap.test.getFullName()];
suiteResult.status = "error";
suiteResult.exceptions.push(formatError(errMap.exception));
});
});
testResult.addListener("skip", function(e) {
e.getData().forEach(function(errMap) {
window.console.warn(errMap.test.getFullName() + " skipped: " + errMap.exception.toString());
var suiteResult = suiteResults[errMap.test.getFullName()];
suiteResult.status = "skip";
suiteResult.exceptions.push(formatError(errMap.exception));
});
});
testResult.addListener("wait", function(e) {
var testName = e.getData().getFullName();
suiteResults[testName].status = "wait";
});
testResult.addListener("endTest", function(e) {
testCount--;
var testName = e.getData().getFullName();
var suiteResult = suiteResults[testName];
var log = suiteResult.exceptions.map(function(ex) {
return ex.toString();
});
var suite, description;
var match = /(.*?)\.([a-zA-Z]+:.*)/.exec(testName);
if (match) {
suite = [match[1]];
description = match[2];
} else {
suite = [];
description = testName;
}
var skipped = suiteResult.status === "skip";
var success = suiteResult.status === "startTest";
var result = {
id : (totalTests-testCount),
description: description,
suite: suite,
success: success,
skipped: skipped,
log: success ? [] : log,
time: skipped ? 0 : Date.now() - suiteResult.startTime,
assertionErrors: log
};
tc.result(result);
if (testCount === 0) {
tc.complete({
coverage: window.__coverage__
});
} else {
runNext();
}
});
};
window.onload = function() {
var delay = window.__karma__.config.startDelay ? window.__karma__.config.startDelay : 0;
setTimeout(function() {
var loader = qx.core.Init.getApplication();
var classes = loader.getSuite().getTestClasses();
var filters = null;
if (window.__karma__.config.testClass) {
filters = new qx.data.Array();
window.__karma__.config.testClass.split(",").forEach(function(filter) {
filters.push(new RegExp(filter));
});
}
// sort by classname
classes.sort(function(a,b) {
if (a.getName() < b.getName()) return -1;
if (a.getName() > b.getName()) return 1;
return 0;
});
for (var i=0; i<classes.length; i++) {
var skip = true;
if (filters) {
filters.some(function(filter) {
if (filter.test(classes[i].getName())) {
skip = false;
return true;
}
})
} else {
skip = false;
}
if (skip === false) {
var methods = classes[i].getTestMethods();
for (var j = 0; j < methods.length; j++) {
testList.push(methods[j]);
}
}
}
totalTests = testCount = testList.length;
tc.info({
total: totalTests
});
testResult = new qx.dev.unit.TestResult();
addListeners(testResult);
// start the queue
runNext();
}, delay);
};
};
};
window.__karma__.start = createQooxdooStartFn(window.__karma__);
})(window);