4 function reset(fixture) {
5 synchronize(function() {
6 document.getElementById('main').innerHTML = fixture;
10 function synchronize(callback) {
11 queue[queue.length] = callback;
18 while(queue.length && !blocking) {
20 queue = queue.slice(1);
25 function runTests(files) {
26 var fixture = document.getElementById('main').innerHTML;
27 var startTime = new Date();
28 for( var i=0; i < files.length; i++) {
32 synchronize(function() {
33 var runTime = new Date() - startTime;
34 // lets use jQuery for this, its not important anyway
35 $('body').append('<br/>Tests completed in ' + runTime + ' milliseconds.');
39 function runTest( files, num ) {
40 synchronize(function() {
42 $.get(files[num],function(js) {
43 evaluateTest(files, num, js);
48 function evaluateTest(files, num, js) {
50 js = js.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
55 if(typeof console != "undefined")
58 Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
61 var good = 0, bad = 0;
62 var ol = document.createElement("ol");
64 var li = "", state = "pass";
65 for ( var i = 0; i < Test.length; i++ ) {
66 var li = document.createElement("li");
67 li.className = Test[i][0] ? "pass" : "fail";
68 li.innerHTML = Test[i][1];
77 var li = document.createElement("li");
80 var b = document.createElement("b");
81 b.innerHTML = files[num] + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
82 b.onclick = function(){
83 var n = this.nextSibling;
84 if ( jQuery.css( n, "display" ) == "none" )
85 n.style.display = "block";
87 n.style.display = "none";
93 document.getElementById("tests").appendChild( li );
99 Test.push( [ !!a, msg ] );
102 function cmpOK( a, c, b, msg ) {
104 eval( "res = (a " + c + " b)" );
105 Test.push( [ res, msg ] );
108 function isSet(a, b, msg) {
111 if ( a && b && a.length == b.length ) {
118 if ( !ret && console )
119 console.log( msg, a, b );
121 Test.push( [ ret, msg ] );
127 for ( var i = 0; i < arguments.length; i++ )
128 r.push( document.getElementById( arguments[i] ) );
134 var f = jQuery.find(b);
137 for ( var i = 0; i < f.length; i++ )
138 s += (s && ",") + '"' + f[i].id + '"';
140 isSet(f, q.apply(q,c), a + " (" + b + ")");