5 synchronize(function() {
7 $.get('index.html', function(content) {
8 var div = $(document.createElement('div')).html(content)
10 .find('[@id=main]').html();
18 function synchronize(callback) {
19 queue[queue.length] = callback;
26 while(queue.length && !blocking) {
28 queue = queue.slice(1);
33 function runTests(files) {
34 var startTime = new Date();
35 for( var i=0; i < files.length; i++) {
39 synchronize(function() {
40 var runTime = new Date() - startTime;
41 $('body').append('<br/>Tests completed in ' + runTime + ' milliseconds.');
45 function runTest( files, num ) {
46 synchronize(function() {
48 $.get(files[num],function(js){
49 js = js.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
54 Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
57 var good = 0, bad = 0;
58 var ol = document.createElement("ol");
60 var li = "", state = "pass";
61 for ( var i = 0; i < Test.length; i++ ) {
62 var li = document.createElement("li");
63 li.className = Test[i][0] ? "pass" : "fail";
64 li.innerHTML = Test[i][1];
73 var li = document.createElement("li");
76 var b = document.createElement("b");
77 b.innerHTML = files[num] + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
78 b.onclick = function(){
79 var n = this.nextSibling;
80 if ( jQuery.css( n, "display" ) == "none" )
81 n.style.display = "block";
83 n.style.display = "none";
89 document.getElementById("tests").appendChild( li );
100 function ok(a, msg) {
101 Test.push( [ !!a, msg ] );
104 function cmpOK( a, c, b, msg ) {
106 eval( "res = (a " + c + " b)" );
107 Test.push( [ res, msg ] );
110 function isSet(a, b, msg) {
113 if ( a && b && a.length == b.length ) {
120 if ( !ret && console )
121 console.log( msg, a, b );
123 Test.push( [ ret, msg ] );
129 for ( var i = 0; i < arguments.length; i++ )
130 r.push( document.getElementById( arguments[i] ) );
136 var f = jQuery.find(b);
139 for ( var i = 0; i < f.length; i++ )
140 s += (s && ",") + '"' + f[i].id + '"';
142 isSet(f, q.apply(q,c), a + " (" + b + ")");
146 var li = document.createElement("li");
148 if ( a.indexOf("#") == 0 )
149 li.className = "comment";
150 else if ( a.indexOf("TODO") >= 0 )
151 li.className = "todo";
152 else if ( a.indexOf("not ok") == 0 )
153 li.classname = "fail";
155 li.className = "pass";
156 document.getElementById("test").appendChild(li);
159 //plan({noPlan: true});