2011-08-12 05:32:59 +00:00
|
|
|
$(function() {
|
|
|
|
|
var Runner = function( ) {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
$.extend( self, {
|
|
|
|
|
frame: window.frames[ "testFrame" ],
|
|
|
|
|
|
|
|
|
|
testTimeout: 3 * 60 * 1000,
|
|
|
|
|
|
|
|
|
|
$frameElem: $( "#testFrame" ),
|
|
|
|
|
|
2011-08-13 07:50:16 +00:00
|
|
|
assertionResultPrefix: "assertion result for test:",
|
|
|
|
|
|
2011-08-12 05:32:59 +00:00
|
|
|
onTimeout: QUnit.start,
|
|
|
|
|
|
2011-08-12 05:55:27 +00:00
|
|
|
onFrameLoad: function() {
|
|
|
|
|
// establish a timeout for a given suite in case of async tests hanging
|
|
|
|
|
self.testTimer = setTimeout( self.onTimeout, self.testTimeout );
|
|
|
|
|
|
2011-08-19 21:02:35 +00:00
|
|
|
// it might be a redirect with query params for push state
|
|
|
|
|
// tests skip this call and expect another
|
|
|
|
|
if( !self.frame.QUnit ) {
|
|
|
|
|
self.$frameElem.one( "load", self.onFrameLoad );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-12 05:55:27 +00:00
|
|
|
// when the QUnit object reports done in the iframe
|
|
|
|
|
// run the onFrameDone method
|
|
|
|
|
self.frame.QUnit.done = self.onFrameDone;
|
2011-08-13 07:50:16 +00:00
|
|
|
self.frame.QUnit.testDone = self.onTestDone;
|
2011-08-12 05:55:27 +00:00
|
|
|
},
|
|
|
|
|
|
2011-10-11 15:42:26 +00:00
|
|
|
onTestDone: function( result ) {
|
|
|
|
|
QUnit.ok( !(result.failed > 0), result.name );
|
|
|
|
|
self.recordAssertions( result.total - result.failed, result.name );
|
2011-08-13 07:50:16 +00:00
|
|
|
},
|
2011-08-12 05:32:59 +00:00
|
|
|
|
2011-08-13 07:50:16 +00:00
|
|
|
onFrameDone: function( failed, passed, total, runtime ){
|
2011-08-12 05:32:59 +00:00
|
|
|
// make sure we don't time out the tests
|
|
|
|
|
clearTimeout( self.testTimer );
|
|
|
|
|
|
|
|
|
|
// TODO decipher actual cause of multiple test results firing twice
|
|
|
|
|
// clear the done call to prevent early completion of other test cases
|
|
|
|
|
self.frame.QUnit.done = $.noop;
|
2011-08-13 07:50:16 +00:00
|
|
|
self.frame.QUnit.testDone = $.noop;
|
|
|
|
|
|
|
|
|
|
// hide the extra assertions made to propogate the count
|
|
|
|
|
// to the suite level test
|
|
|
|
|
self.hideAssertionResults();
|
2011-08-12 05:32:59 +00:00
|
|
|
|
|
|
|
|
// continue on to the next suite
|
|
|
|
|
QUnit.start();
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-13 07:50:16 +00:00
|
|
|
recordAssertions: function( count, parentTest ) {
|
2011-08-12 05:32:59 +00:00
|
|
|
for( var i = 0; i < count; i++ ) {
|
2011-08-13 07:50:16 +00:00
|
|
|
ok( true, self.assertionResultPrefix + parentTest );
|
2011-08-12 05:32:59 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-13 07:50:16 +00:00
|
|
|
hideAssertionResults: function() {
|
|
|
|
|
$( "li:not([id]):contains('" + self.assertionResultPrefix + "')" ).hide();
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-12 05:32:59 +00:00
|
|
|
exec: function( data ) {
|
|
|
|
|
var template = self.$frameElem.attr( "data-src" );
|
|
|
|
|
|
2011-08-15 19:09:56 +00:00
|
|
|
$.each( data.testPages, function(i, dir) {
|
2011-08-12 05:55:27 +00:00
|
|
|
QUnit.asyncTest( dir, function() {
|
|
|
|
|
self.dir = dir;
|
2011-08-12 16:51:34 +00:00
|
|
|
self.$frameElem.one( "load", self.onFrameLoad );
|
2011-08-12 05:32:59 +00:00
|
|
|
self.$frameElem.attr( "src", template.replace("{{testdir}}", dir) );
|
|
|
|
|
});
|
|
|
|
|
});
|
2011-08-12 21:41:45 +00:00
|
|
|
|
|
|
|
|
// having defined all suite level tests let QUnit run
|
|
|
|
|
QUnit.start();
|
2011-08-12 05:32:59 +00:00
|
|
|
}
|
2011-06-26 19:09:56 +00:00
|
|
|
});
|
2011-06-27 04:17:32 +00:00
|
|
|
};
|
|
|
|
|
|
2011-08-12 21:41:45 +00:00
|
|
|
// prevent qunit from starting the test suite until all tests are defined
|
|
|
|
|
QUnit.begin = function( ) {
|
|
|
|
|
this.config.autostart = false;
|
|
|
|
|
};
|
|
|
|
|
|
2011-06-27 04:17:32 +00:00
|
|
|
// get the test directories
|
2011-08-12 05:32:59 +00:00
|
|
|
$.get( "ls.php", (new Runner()).exec );
|
|
|
|
|
});
|