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 if(typeof console != "undefined")
56 Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
59 var good = 0, bad = 0;
60 var ol = document.createElement("ol");
62 var li = "", state = "pass";
63 for ( var i = 0; i < Test.length; i++ ) {
64 var li = document.createElement("li");
65 li.className = Test[i][0] ? "pass" : "fail";
66 li.innerHTML = Test[i][1];
75 var li = document.createElement("li");
78 var b = document.createElement("b");
79 b.innerHTML = files[num] + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
80 b.onclick = function(){
81 var n = this.nextSibling;
82 if ( jQuery.css( n, "display" ) == "none" )
83 n.style.display = "block";
85 n.style.display = "none";
91 document.getElementById("tests").appendChild( li );
102 function ok(a, msg) {
103 Test.push( [ !!a, msg ] );
106 function cmpOK( a, c, b, msg ) {
108 eval( "res = (a " + c + " b)" );
109 Test.push( [ res, msg ] );
112 function isSet(a, b, msg) {
115 if ( a && b && a.length == b.length ) {
122 if ( !ret && console )
123 console.log( msg, a, b );
125 Test.push( [ ret, msg ] );
131 for ( var i = 0; i < arguments.length; i++ )
132 r.push( document.getElementById( arguments[i] ) );
138 var f = jQuery.find(b);
141 for ( var i = 0; i < f.length; i++ )
142 s += (s && ",") + '"' + f[i].id + '"';
144 isSet(f, q.apply(q,c), a + " (" + b + ")");
148 var li = document.createElement("li");
150 if ( a.indexOf("#") == 0 )
151 li.className = "comment";
152 else if ( a.indexOf("TODO") >= 0 )
153 li.className = "todo";
154 else if ( a.indexOf("not ok") == 0 )
155 li.classname = "fail";
157 li.className = "pass";
158 document.getElementById("test").appendChild(li);
161 //plan({noPlan: true});