mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-05-15 18:13:09 +00:00
refactor of test suite runner, added passed/failed counts to suite results
This commit is contained in:
parent
5917b379e1
commit
fb0f6baf24
1 changed files with 50 additions and 44 deletions
|
|
@ -1,58 +1,64 @@
|
|||
(function(){
|
||||
var test = function(data){
|
||||
var $frameElem = $("#testFrame"),
|
||||
template = $frameElem.attr("data-src"),
|
||||
updateFrame = function(dir){
|
||||
return $frameElem.attr("src", template.replace("{{testdir}}", dir));
|
||||
};
|
||||
$(function() {
|
||||
var Runner = function( ) {
|
||||
var self = this;
|
||||
|
||||
$.each(data.directories, function(i, dir){
|
||||
asyncTest( dir, function(){
|
||||
var testTimeout = 3 * 60 * 1000, checkInterval = 2000;
|
||||
$.extend( self, {
|
||||
frame: window.frames[ "testFrame" ],
|
||||
|
||||
// establish a timeout for a given suite in case of async tests hanging
|
||||
var testTimer = setTimeout( function(){
|
||||
// prevent any schedule checks for completion
|
||||
clearTimeouts();
|
||||
start();
|
||||
}, testTimeout ),
|
||||
testTimeout: 3 * 60 * 1000,
|
||||
|
||||
checkTimer = setInterval( check, checkInterval ),
|
||||
$frameElem: $( "#testFrame" ),
|
||||
|
||||
clearTimeouts = function(){
|
||||
// prevent the next interval of the check function and the test timeout
|
||||
clearTimeout( checkTimer );
|
||||
clearTimeout( testTimer );
|
||||
};
|
||||
onTimeout: QUnit.start,
|
||||
|
||||
// check the iframe for success or failure and respond accordingly
|
||||
function check(){
|
||||
// check for the frames jquery object each time
|
||||
var framejQuery = window.frames["testFrame"].jQuery;
|
||||
onFrameDone: function( failed, passed, total, runtime ){
|
||||
// record success
|
||||
self.recordResult( false , failed );
|
||||
self.recordResult( true , passed );
|
||||
|
||||
// if the iframe hasn't loaded (ie loaded jQuery) check back again shortly
|
||||
if( !framejQuery ) return;
|
||||
// make sure we don't time out the tests
|
||||
clearTimeout( self.testTimer );
|
||||
|
||||
// grab the result of the iframe test suite
|
||||
// TODO strip extra white space
|
||||
var result = framejQuery( "#qunit-banner" ).attr( "class" );
|
||||
// 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;
|
||||
|
||||
// if we have a result check it, otherwise check back shortly
|
||||
if( result ){
|
||||
ok( result === "qunit-pass" );
|
||||
clearTimeouts();
|
||||
start();
|
||||
}
|
||||
};
|
||||
// continue on to the next suite
|
||||
QUnit.start();
|
||||
},
|
||||
|
||||
expect( 1 );
|
||||
recordResult: function( result, count ) {
|
||||
for( var i = 0; i < count; i++ ) {
|
||||
ok( result );
|
||||
}
|
||||
},
|
||||
|
||||
// set the test suite page on the iframe
|
||||
updateFrame( dir );
|
||||
});
|
||||
createTest: function( dir ) {
|
||||
// check for the frames jquery object each time
|
||||
$( "iframe#testFrame" ).one( "load", function() {
|
||||
|
||||
// establish a timeout for a given suite in case of async tests hanging
|
||||
self.testTimer = setTimeout( self.onTimeout, self.testTimeout );
|
||||
|
||||
// when the QUnit object reports done in the iframe
|
||||
// run the onFrameDone method
|
||||
self.frame.QUnit.done = self.onFrameDone;
|
||||
});
|
||||
},
|
||||
|
||||
exec: function( data ) {
|
||||
var template = self.$frameElem.attr( "data-src" );
|
||||
|
||||
$.each( data.directories, function(i, dir) {
|
||||
asyncTest( dir, function() {
|
||||
self.createTest( dir );
|
||||
self.$frameElem.attr( "src", template.replace("{{testdir}}", dir) );
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// get the test directories
|
||||
$.get("ls.php", test);
|
||||
})();
|
||||
$.get( "ls.php", (new Runner()).exec );
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue