This repository has been archived by the owner on Sep 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
qx-phantom.js
159 lines (144 loc) · 4.63 KB
/
qx-phantom.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
// Generated by CoffeeScript 1.6.3
(function() {
var CONSOLE, RUNNER, VERBOSE, loadedBefore, page, runnerUrl, system, testClasses, url;
system = require('system');
RUNNER = "";
VERBOSE = true;
CONSOLE = false;
testClasses = system.args[1];
runnerUrl = (RUNNER != null) && RUNNER !== "" ? system.args[2] || RUNNER : system.args[2];
if (runnerUrl == null) {
throw new Error("No URL configured or given");
}
phantom.injectJs("colors.js");
url = testClasses ? "" + runnerUrl + "?testclass=" + testClasses : "" + runnerUrl;
page = new WebPage();
page.onConsoleMessage = function(msg) {
if (CONSOLE) {
return console.log("CONSOLE: " + msg);
}
};
page.onError = function(msg, trace) {
var msgStack;
msgStack = ["ERROR: " + msg];
if (trace && trace.length) {
msgStack.push("TRACE:");
trace.forEach(function(t) {
var functionContent;
functionContent = "";
if (t["function"]) {
functionContent = "(in function '" + t["function"] + "')";
}
return msgStack.push(" -> " + t.file + ": " + t.line + " " + functionContent);
});
}
};
loadedBefore = false;
page.open(url, function(status) {
var processTestResults;
if (status !== "success") {
console.log("Unable to load page");
phantom.exit(1);
}
if (loadedBefore) {
return;
}
loadedBefore = true;
window.setTimeout(function() {
var testSuiteState;
testSuiteState = page.evaluate(function() {
return qx.core.Init.getApplication().runner.getTestSuiteState();
});
switch (testSuiteState) {
case "init":
case "loading":
case "ready":
console.log("Unable to start test suite");
return phantom.exit(1);
}
}, 120000);
page.evaluate(function() {
var runner;
if (typeof qx === "undefined") {
console.log("qooxdoo not found");
return;
}
runner = qx.core.Init.getApplication().runner;
if (runner.getTestSuiteState() !== "ready") {
return runner.addListener("changeTestSuiteState", function(e) {
var state;
state = e.getData();
if (state === "ready") {
return runner.view.run();
}
});
} else {
return runner.view.run();
}
});
processTestResults = function() {
var error, exception, getRunnerStateAndResults, results, skip, state, success, test, testName, _i, _len, _ref, _ref1;
getRunnerStateAndResults = function() {
return page.evaluate(function() {
var error, runner, state;
try {
runner = qx.core.Init.getApplication().runner;
state = runner.getTestSuiteState();
} catch (_error) {
error = _error;
console.log("Error while getting the test runners state and results");
return [null, null];
}
if (state === "finished") {
return [state, runner.view.getTestResults()];
} else {
return [state, null];
}
});
};
_ref = getRunnerStateAndResults(), state = _ref[0], results = _ref[1];
if (!state) {
return;
}
if (state === "error") {
console.log("Error running tests");
phantom.exit(1);
}
if (state === "finished") {
success = [];
skip = [];
error = [];
for (testName in results) {
test = results[testName];
if (test.state === "success") {
success.push(testName);
if (VERBOSE) {
console.log("PASS".green + (" " + testName));
}
}
if (test.state === "skip") {
skip.push(testName);
if (VERBOSE) {
console.log("SKIP".yellow + (" " + testName));
}
}
if (test.state === "error" || test.state === "failure") {
error.push(testName);
console.log("FAIL".red + (" " + testName));
_ref1 = test.messages;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
exception = _ref1[_i];
exception = exception.replace(/\n$/, "");
exception = exception.replace(/\n/g, "\n ");
console.log(">>>> " + exception);
}
}
}
console.log("Finished running test suite.");
console.log(("(" + success.length + " succeeded, ") + ("" + skip.length + " skipped, ") + ("" + error.length + " failed)"));
return phantom.exit(error.length);
}
};
return window.setInterval(processTestResults, 500);
});
}).call(this);