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") {
59 Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
62 var good = 0, bad = 0;
63 var ol = document.createElement("ol");
65 var li = "", state = "pass";
66 for ( var i = 0; i < Test.length; i++ ) {
67 var li = document.createElement("li");
68 li.className = Test[i][0] ? "pass" : "fail";
69 li.innerHTML = Test[i][1];
78 var li = document.createElement("li");
81 var b = document.createElement("b");
82 b.innerHTML = files[num] + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
83 b.onclick = function(){
84 var n = this.nextSibling;
85 if ( jQuery.css( n, "display" ) == "none" )
86 n.style.display = "block";
88 n.style.display = "none";
94 document.getElementById("tests").appendChild( li );
100 Test.push( [ !!a, msg ] );
103 function cmpOK( a, c, b, msg ) {
105 eval( "res = (a " + c + " b)" );
106 Test.push( [ res, msg ] );
109 function isSet(a, b, msg) {
112 if ( a && b && a.length == b.length ) {
119 if ( !ret && console )
120 console.log( msg, a, b );
122 Test.push( [ ret, msg ] );
128 for ( var i = 0; i < arguments.length; i++ )
129 r.push( document.getElementById( arguments[i] ) );
135 var f = jQuery.find(b);
138 for ( var i = 0; i < f.length; i++ )
139 s += (s && ",") + '"' + f[i].id + '"';
141 isSet(f, q.apply(q,c), a + " (" + b + ")");