github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jeresig / testswarm

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 258
    • 30
  • Source
  • Commits
  • Network (30)
  • Issues (19)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: 5d87e2b

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Distributed continuous integration testing for JavaScript. — Read more

  cancel

http://testswarm.com/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added additional information to the window.onerror messages. 
jeresig (author)
Wed Aug 26 10:30:34 -0700 2009
commit  5d87e2b543f7c90f25f3a616fdfa7bf6dea3a364
tree    f6e481580fff16e538db1b84b794015006e6874e
parent  8878ae1321aee68aeb3b9aa114c8b74169268aec
testswarm / js / inject.js js/inject.js
100644 300 lines (244 sloc) 7.118 kb
edit raw blame history
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
(function(){
 
var DEBUG = false;
 
var doPost = false;
 
try {
doPost = !!window.top.postMessage;
} catch(e){}
 
var url = window.location.search;
url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) );
 
if ( !DEBUG && (!url || url.indexOf("http") !== 0) ) {
return;
}
 
var submitTimeout = 5;
 
var curHeartbeat;
var beatRate = 20;
 
// Expose the TestSwarm API
window.TestSwarm = {
submit: submit,
heartbeat: function(){
if ( curHeartbeat ) {
clearTimeout( curHeartbeat );
}
 
curHeartbeat = setTimeout(function(){
submit({ fail: -1, total: -1 });
}, beatRate * 1000);
},
serialize: function(){
return trimSerialize();
}
};
 
// Prevent careless things from executing
window.print = window.confirm = window.alert = window.open = function(){};
 
window.onerror = function(e){
document.body.appendChild( document.createTextNode( "ERROR: " + e ));
submit({ fail: 0, error: 1, total: 1 });
return false;
};
 
// QUnit (jQuery)
// http://docs.jquery.com/QUnit
if ( typeof QUnit !== "undefined" ) {
QUnit.done = function(fail, total){
submit({
fail: fail,
error: 0,
total: total
});
};
 
QUnit.log = window.TestSwarm.heartbeat;
window.TestSwarm.heartbeat();
 
window.TestSwarm.serialize = function(){
// Clean up the HTML (remove any un-needed test markup)
remove("nothiddendiv");
remove("loadediframe");
remove("dl");
remove("main");
 
// Show any collapsed results
var ol = document.getElementsByTagName("ol");
for ( var i = 0; i < ol.length; i++ ) {
ol[i].style.display = "block";
}
 
return trimSerialize();
};
 
// UnitTestJS (Prototype, Scriptaculous)
// http://github.com/tobie/unittest_js/tree/master
} else if ( typeof Test !== "undefined" && Test && Test.Unit && Test.Unit.runners ) {
var total_runners = Test.Unit.runners.length, cur_runners = 0;
var total = 0, fail = 0, error = 0;
 
for (var i = 0; i < Test.Unit.runners.length; i++) (function(i){
var finish = Test.Unit.runners[i].finish;
Test.Unit.runners[i].finish = function(){
finish.call( this );
 
var results = this.getResult();
total += results.assertions;
fail += results.failures;
error += results.errors;
 
if ( ++cur_runners === total_runners ) {
submit({
fail: fail,
error: error,
total: total
});
}
};
})(i);
 
// JSSpec (MooTools)
// http://jania.pe.kr/aw/moin.cgi/JSSpec
} else if ( typeof JSSpec !== "undefined" && JSSpec && JSSpec.Logger ) {
var onRunnerEnd = JSSpec.Logger.prototype.onRunnerEnd;
JSSpec.Logger.prototype.onRunnerEnd = function(){
onRunnerEnd.call(this);
 
// Show any collapsed results
var ul = document.getElementsByTagName("ul");
for ( var i = 0; i < ul.length; i++ ) {
ul[i].style.display = "block";
}
 
submit({
fail: JSSpec.runner.getTotalFailures(),
error: JSSpec.runner.getTotalErrors(),
total: JSSpec.runner.totalExamples
});
};
 
window.TestSwarm.serialize = function(){
// Show any collapsed results
var ul = document.getElementsByTagName("ul");
for ( var i = 0; i < ul.length; i++ ) {
ul[i].style.display = "block";
}
 
return trimSerialize();
};
 
// JSUnit
// http://www.jsunit.net/
// Note: Injection file must be included before the frames
// are document.write()d into the page.
} else if ( typeof JsUnitTestManager !== "undefined" ) {
var _done = JsUnitTestManager.prototype._done;
JsUnitTestManager.prototype._done = function(){
_done.call(this);
 
submit({
fail: this.failureCount,
error: this.errorCount,
total: this.totalCount
});
};
 
window.TestSwarm.serialize = function(){
return "<pre>" + this.log.join("\n") + "</pre>";
};
 
// Selenium Core
// http://seleniumhq.org/projects/core/
} else if ( typeof SeleniumTestResult !== "undefined" && typeof LOG !== "undefined" ) {
// Completely overwrite the postback
SeleniumTestResult.prototype.post = function(){
submit({
fail: this.metrics.numCommandFailures,
error: this.metrics.numCommandErrors,
total: this.metrics.numCommandPasses + this.metrics.numCommandFailures + this.metrics.numCommandErrors
});
};
 
window.TestSwarm.serialize = function(){
var results = [];
while ( LOG.pendingMessages.length ) {
var msg = LOG.pendingMessages.shift();
results.push( msg.type + ": " + msg.msg );
}
 
return "<pre>" + results.join("\n") + "</pre>";
};
 
// Dojo Objective Harness
// http://docs.dojocampus.org/quickstart/doh
} else if ( typeof doh !== "undefined" && doh._report ) {
var _report = doh._report;
doh._report = function(){
_report.apply(this, arguments);
 
submit({
fail: doh._failureCount,
error: doh._errorCount,
total: doh._testCount
});
};
 
window.TestSwarm.serialize = function(){
return "<pre>" + document.getElementById("logBody").innerHTML + "</pre>";
};
}
 
function trimSerialize(doc) {
doc = doc || document;
 
var scripts = doc.getElementsByTagName("script");
while ( scripts.length ) {
remove( scripts[0] );
}
 
var root = window.location.href.replace(/(https?:\/\/.*?)\/.*/, "$1");
var cur = window.location.href.replace(/[^\/]*$/, "");
 
var links = doc.getElementsByTagName("link");
for ( var i = 0; i < links.length; i++ ) {
var href = links[i].href;
if ( href.indexOf("/") === 0 ) {
href = root + href;
} else if ( !/^https?:\/\//.test( href ) ) {
href = cur + href;
}
links[i].href = href;
}
 
return ("<html>" + doc.documentElement.innerHTML + "</html>")
.replace(/\s+/g, " ");
}
 
function remove(elem){
if ( typeof elem === "string" ) {
elem = document.getElementById( elem );
}
 
if ( elem ) {
elem.parentNode.removeChild( elem );
}
}
 
function submit(params){
if ( curHeartbeat ) {
clearTimeout( curHeartbeat );
}
 
var paramItems = (url.split("?")[1] || "").split("&");
 
for ( var i = 0; i < paramItems.length; i++ ) {
if ( paramItems[i] ) {
var parts = paramItems[i].split("=");
if ( !params[ parts[0] ] ) {
params[ parts[0] ] = parts[1];
}
}
}
 
if ( !params.state ) {
params.state = "saverun";
}
 
if ( !params.results ) {
params.results = window.TestSwarm.serialize();
}
 
if ( doPost ) {
// Build Query String
var query = "";
 
for ( var i in params ) {
query += ( query ? "&" : "" ) + i + "=" +
encodeURIComponent(params[i]);
}
 
if ( DEBUG ) {
alert( query );
} else {
window.top.postMessage( query, "*" );
}
 
} else {
var form = document.createElement("form");
form.action = url;
form.method = "POST";
 
for ( var i in params ) {
var input = document.createElement("input");
input.type = "hidden";
input.name = i;
input.value = params[i];
form.appendChild( input );
}
 
if ( DEBUG ) {
alert( form.innerHTML );
} else {
 
// Watch for the result submission timing out
setTimeout(function(){
submit( params );
}, submitTimeout * 1000);
 
document.body.appendChild( form );
form.submit();
}
}
}
 
})();
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server