Ticket #3215: testrunner.patch
File testrunner.patch, 2.7 KB (added by , 14 years ago) |
---|
-
testrunner.js
15 15 Test: [], 16 16 stats: { 17 17 all: 0, 18 good: 0, 18 19 bad: 0 19 20 }, 20 21 queue: [], … … 22 23 timeout: null, 23 24 expected: null, 24 25 currentModule: null, 26 startTime : new Date().getTime(), 27 beforeEach : null, 28 afterEach : null, 25 29 asyncTimeout: 2 // seconds for async timeout 30 26 31 }; 27 32 28 33 _config.filters = location.search.length > 1 && //restrict modules/tests by get parameters … … 35 40 runTest(); 36 41 }); 37 42 43 function qUnitTesting( testsCallback ){ 44 $(document).ready(function(){ 45 testsCallback(_config); 46 allTestsDone(); 47 }); 48 } 49 38 50 function synchronize(callback) { 39 51 _config.queue[_config.queue.length] = callback; 40 52 if(!_config.blocking) { … … 90 102 } 91 103 92 104 function runTest() { 93 _config.blocking = false; 94 var time = new Date(); 105 _config.blocking = false; 95 106 _config.fixture = document.getElementById('main').innerHTML; 96 107 _config.ajaxSettings = $.ajaxSettings; 108 } 109 110 function allTestsDone(){ 111 synchronize(function(){ 112 updateStats(); 113 $("<div>").attr("id", "TESTRESULTS").html(""+_config.stats.bad).hide().appendTo("body"); 114 }); 115 } 116 117 function updateStats(){ 97 118 synchronize(function() { 98 time = new Date() - time; 99 $("<div>").html(['<p class="result">Tests completed in ', 100 time, ' milliseconds.<br/>', 119 _config.endTime = new Date().getTime(); 120 $("#results").html(['<p class="result">Tests completed in ', 121 (_config.endTime - _config.startTime), ' milliseconds.<br/>', 122 _config.stats.good, ' tests of ', _config.stats.all, ' passed.<br/>', 101 123 _config.stats.bad, ' tests of ', _config.stats.all, ' failed.</p>'] 102 .join('')) 103 .appendTo("body"); 124 .join('')); 104 125 $("#banner").addClass(_config.stats.bad ? "fail" : "pass"); 105 126 }); 106 127 } … … 115 136 synchronize(function() { 116 137 _config.Test = []; 117 138 try { 139 if( _config.beforeEach ){ _config.beforeEach(name); } 118 140 callback(); 141 if( _config.afterEach ){ _config.afterEach(name); } 119 142 } catch(e) { 120 143 if( typeof console != "undefined" && console.error && console.warn ) { 121 144 console.error("Test " + name + " died, exception and test follows"); … … 159 182 state = "fail"; 160 183 bad++; 161 184 _config.stats.bad++; 162 } else good++; 185 } else { 186 good++; 187 _config.stats.good++; 188 } 163 189 } 164 190 165 191 var li = document.createElement("li"); … … 185 211 li.appendChild( ol ); 186 212 187 213 document.getElementById("tests").appendChild( li ); 188 }); 214 }); 189 215 } 190 216 191 217 // call on start of module test to prepend name to all tests