Refactored the testsuite code with the hope in mind to make the test suite run faster

This commit is contained in:
Jörn Zaefferer 2006-09-05 19:50:13 +00:00
parent b5220adbbc
commit ded1402498

View file

@ -1,13 +1,10 @@
var queue = []; var queue = [];
var blocking = false; var blocking = false;
var fixture;
function reset() { function reset(fixture) {
if(fixture) { synchronize(function() {
$("#main").html(fixture); document.getElementById('main').innerHTML = fixture;
} else { });
fixture = $("#main").html();
}
} }
function synchronize(callback) { function synchronize(callback) {
@ -26,14 +23,15 @@ function process() {
} }
function runTests(files) { function runTests(files) {
var fixture = null; var fixture = document.getElementById('main').innerHTML;
reset();
var startTime = new Date(); var startTime = new Date();
for( var i=0; i < files.length; i++) { for( var i=0; i < files.length; i++) {
runTest( files, i ); runTest( files, i );
reset(fixture);
} }
synchronize(function() { synchronize(function() {
var runTime = new Date() - startTime; var runTime = new Date() - startTime;
// lets use jQuery for this, its not important anyway
$('body').append('<br/>Tests completed in ' + runTime + ' milliseconds.'); $('body').append('<br/>Tests completed in ' + runTime + ' milliseconds.');
}); });
} }
@ -42,6 +40,13 @@ function runTest( files, num ) {
synchronize(function() { synchronize(function() {
blocking = true; blocking = true;
$.get(files[num],function(js) { $.get(files[num],function(js) {
evaluateTest(files, num, js);
});
});
}
function evaluateTest(files, num, js) {
var Test = [];
js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&"); js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
try { try {
@ -49,6 +54,7 @@ function runTest( files, num ) {
} catch(e) { } catch(e) {
if(typeof console != "undefined") if(typeof console != "undefined")
console.error(e); console.error(e);
console.debug(js);
Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] ); Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
} }
@ -86,15 +92,8 @@ function runTest( files, num ) {
document.getElementById("tests").appendChild( li ); document.getElementById("tests").appendChild( li );
Test = [];
reset();
blocking = false; blocking = false;
process(); process();
});
});
}
var Test = [];
function ok(a, msg) { function ok(a, msg) {
Test.push( [ !!a, msg ] ); Test.push( [ !!a, msg ] );
@ -140,19 +139,4 @@ function t(a,b,c) {
isSet(f, q.apply(q,c), a + " (" + b + ")"); isSet(f, q.apply(q,c), a + " (" + b + ")");
} }
function o(a) {
var li = document.createElement("li");
li.innerHTML = a;
if ( a.indexOf("#") == 0 )
li.className = "comment";
else if ( a.indexOf("TODO") >= 0 )
li.className = "todo";
else if ( a.indexOf("not ok") == 0 )
li.classname = "fail";
else
li.className = "pass";
document.getElementById("test").appendChild(li);
} }
//plan({noPlan: true});