X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=build%2Ftest%2Fjs%2Ftest.js;h=82469f720f066e0bfb28d93a65175bf96b999ab1;hb=97ea47492fe13ddb1108045c244d5af6570ace92;hp=44a405fdbf4407c2ce900e62638e8f3bdd608b74;hpb=519b7d33e2e40c9d6f5defa67500979af2123d99;p=jquery.git diff --git a/build/test/js/test.js b/build/test/js/test.js index 44a405f..82469f7 100644 --- a/build/test/js/test.js +++ b/build/test/js/test.js @@ -1,53 +1,97 @@ -function runTests(files) { - runTest( files, 0 ); +var queue = []; +var blocking = false; + +function reset() { + synchronize(function() { + blocking = true; + $.get('index.html', function(content) { + var div = $(document.createElement('div')).html(content) + // search for main div + .find('[@id=main]').html(); + $('#main').html(div); + blocking = false; + process(); + }); + }); } -function runTest( files, num ) { - $.get(files[num],function(js){ - js = js.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); +function synchronize(callback) { + queue[queue.length] = callback; + if(!blocking) { + process(); + } +} - try { - eval(js); - } catch(e) { - Test.push( [ false, "Died on test #" + Test.length + ": " + e ] ); - } +function process() { + while(queue.length && !blocking) { + var call = queue[0]; + queue = queue.slice(1); + call(); + } +} - var good = 0, bad = 0; - var ol = document.createElement("ol"); +function runTests(files) { + var startTime = new Date(); + for( var i=0; i < files.length; i++) { + runTest( files, i ); + reset(); + } + synchronize(function() { + var runTime = new Date() - startTime; + $('body').append('
Tests completed in ' + runTime + ' milliseconds.'); + }); +} - var li = "", state = "pass"; - for ( var i = 0; i < Test.length; i++ ) { +function runTest( files, num ) { + synchronize(function() { + blocking = true; + $.get(files[num],function(js){ + js = js.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); + + try { + eval(js); + } catch(e) { + Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] ); + } + + var good = 0, bad = 0; + var ol = document.createElement("ol"); + + var li = "", state = "pass"; + for ( var i = 0; i < Test.length; i++ ) { + var li = document.createElement("li"); + li.className = Test[i][0] ? "pass" : "fail"; + li.innerHTML = Test[i][1]; + ol.appendChild( li ); + + if ( !Test[i][0] ) { + state = "fail"; + bad++; + } else good++; + } + var li = document.createElement("li"); - li.className = Test[i][0] ? "pass" : "fail"; - li.innerHTML = Test[i][1]; - ol.appendChild( li ); - - if ( !Test[i][0] ) { - state = "fail"; - bad++; - } else good++; - } - - var li = document.createElement("li"); - li.className = state; - - var b = document.createElement("b"); - b.innerHTML = files[num] + " (" + bad + ", " + good + ", " + Test.length + ")"; - b.onclick = function(){ - var n = this.nextSibling; - if ( jQuery.css( n, "display" ) == "none" ) - n.style.display = "block"; - else - n.style.display = "none"; - }; - li.appendChild( b ); - - li.appendChild( ol ); - - document.getElementById("tests").appendChild( li ); - - Test = []; - if ( ++num < files.length ) runTest( files, num ); + li.className = state; + + var b = document.createElement("b"); + b.innerHTML = files[num] + " (" + bad + ", " + good + ", " + Test.length + ")"; + b.onclick = function(){ + var n = this.nextSibling; + if ( jQuery.css( n, "display" ) == "none" ) + n.style.display = "block"; + else + n.style.display = "none"; + }; + li.appendChild( b ); + + li.appendChild( ol ); + + document.getElementById("tests").appendChild( li ); + + Test = []; + blocking = false; + process(); + }); }); }