Changeset 7847
- Timestamp:
- 03/29/07 23:13:52 (22 months ago)
- Location:
- dojo/trunk/tests
- Files:
-
- 3 modified
-
runner.html (modified) (2 diffs)
-
runner.js (modified) (11 diffs)
-
_browserRunner.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dojo/trunk/tests/runner.html
r7647 r7847 6 6 <head> 7 7 <title>The Dojo Unit Test Harness, $Rev$</title> 8 <script type="text/javascript" src="../dojo.js" 9 djConfig="isDebug: true"></script> 10 <script type="text/javascript"> 11 try{ 12 dojo.require("tests.runner"); 13 }catch(e){ 14 document.write("<scr"+"ipt type='text/javascript' src='runner.js'></scr"+"ipt>"); 15 document.write("<scr"+"ipt type='text/javascript' src='_browserRunner.js'></scr"+"ipt>"); 16 } 17 </script> 8 18 <style type="text/css"> 9 19 body { … … 148 158 } 149 159 </style> 150 <script type="text/javascript" src="../dojo.js"></script>151 <script type="text/javascript" src="runner.js"></script>152 <script type="text/javascript">153 if(!this["dojo"]){154 document.write("<scr"+"ipt type='text/javascript' src='_browserRunner.js'></scr"+"ipt>");155 document.write("<scr"+"ipt type='text/javascript' src='_base.js'></scr"+"ipt>");156 }157 </script>158 160 </head> 159 161 <body> -
dojo/trunk/tests/runner.js
r7704 r7847 3 3 4 4 // package system gunk. 5 if(this["dojo"]){ 6 // Ensure we can run w/o Dojo in a Rhino or SM environment 5 try{ 7 6 dojo.provide("tests.runner"); 8 }else if(!this["tests"]){ 9 tests = {}; 7 }catch(e){ 8 if(!this["tests"]){ 9 tests = {}; 10 } 10 11 } 11 12 … … 206 207 if(this.fired != -1){ 207 208 if(!this.silentlyCancelled){ 208 t ests.raise("already called!");209 throw new Error("already called!"); 209 210 } 210 211 this.silentlyCancelled = false; … … 268 269 var pair = chain.shift(); 269 270 var f = pair[fired]; 270 if (f == null){271 if(f == null){ 271 272 continue; 272 273 } … … 274 275 res = f(res); 275 276 fired = ((res instanceof Error) ? 1 : 0); 276 if(res instanceof tests.Deferred) {277 if(res instanceof tests.Deferred){ 277 278 cb = function(res){ 278 279 self._continue(res); … … 355 356 } 356 357 357 tests.registerTest = function(/*String*/ group, /*Function or Object*/ test){ 358 tests.registerGroup = function( /*String*/ group, 359 /*Array||Function||Object*/ tests, 360 /*Function*/ setUp, 361 /*Function*/ tearDown){ 362 // summary: 363 // registers an entire group of tests at once and provides a setUp and 364 // tearDown facility for groups. If you call this method with only 365 // setUp and tearDown parameters, they will replace previously 366 // installed setUp or tearDown functions for the group with the new 367 // methods. 368 // group: 369 // string name of the group 370 // tests: 371 // either a function or an object or an array of functions/objects. If 372 // an object, it must contain at *least* a "runTest" method, and may 373 // also contain "setUp" and "tearDown" methods. These will be invoked 374 // on either side of the "runTest" method (respectively) when the test 375 // is run. If an array, it must contain objects matching the above 376 // description or test functions. 377 // setUp: a function for initializing the test group 378 // tearDown: a function for initializing the test group 379 if(tests){ 380 this.register(group, tests); 381 } 382 if(setUp){ 383 this._groups[group].setUp = setUp; 384 } 385 if(tearDown){ 386 this._groups[group].tearDown = tearDown; 387 } 388 } 389 390 tests._getTestObj = function(group, test){ 391 var tObj = test; 392 if(typeof test == "string"){ 393 if(test.substr(0, 4)=="url:"){ 394 return this.registerUrl(group, test); 395 }else{ 396 tObj = { 397 name: test.replace("/\s/g", "_") 398 }; 399 tObj.runTest = new Function(test); 400 } 401 }else if(typeof test == "function"){ 402 // if we didn't get a fixture, wrap the function 403 tObj = { "runTest": test }; 404 if(test["name"]){ 405 tObj.name = test.name; 406 }else{ 407 try{ 408 var fStr = "function "; 409 var ts = tObj.runTest+""; 410 if(0 <= ts.indexOf(fStr)){ 411 tObj.name = ts.split(fStr)[1].split("(", 1)[0]; 412 } 413 // tests.debug(tObj.runTest.toSource()); 414 }catch(e){ 415 } 416 } 417 // FIXME: try harder to get the test name here 418 } 419 return tObj; 420 } 421 422 tests.registerTest = function(/*String*/ group, /*Function||Object*/ test){ 358 423 // summary: 359 424 // add the provided test function or fixture object to the specified … … 371 436 this._groups[group].inFlight = 0; 372 437 } 373 var tObj = test; 374 if(typeof test == "function"){ 375 // if we didn't get a fixture, wrap the function 376 tObj = { "runTest": test }; 377 if(test["name"]){ 378 tObj.name = test.name; 379 }else{ 380 try{ 381 var fStr = "function "; 382 var ts = tObj.runTest+""; 383 if(0 <= ts.indexOf(fStr)){ 384 tObj.name = ts.split(fStr)[1].split("(", 1)[0]; 385 } 386 // tests.debug(tObj.runTest.toSource()); 387 }catch(e){ 388 } 389 } 390 // FIXME: try harder to get the test name here 391 } 438 var tObj = this._getTestObj(group, test); 439 if(!tObj){ return; } 392 440 this._groups[group].push(tObj); 393 441 this._testCount++; 394 442 this._testRegistered(group, tObj); 443 return tObj; 395 444 } 396 445 … … 405 454 } 406 455 407 tests.registerTestUrl = function(/*String*/ group, /*String*/ url){ 456 // FIXME: move implementation to _browserRunner? 457 tests.registerUrl = function( /*String*/ group, 458 /*String*/ url, 459 /*Integer*/ timeout){ 408 460 this.debug("ERROR:"); 409 this.debug("\tNO register TestUrl() METHOD AVAILABLE.");461 this.debug("\tNO registerUrl() METHOD AVAILABLE."); 410 462 // this._urls.push(url); 463 } 464 465 tests.registerString = function(group, str){ 411 466 } 412 467 … … 419 474 if( (arguments.length == 1)&& 420 475 (typeof groupOrNs == "string") ){ 421 this.registerTestUrl(groupOrNs); 476 if(groupOrNs.substr(0, 4)=="url:"){ 477 this.registerUrl(groupOrNs); 478 }else{ 479 this.registerTest("ungrouped", groupOrNs); 480 } 422 481 } 423 482 if(arguments.length == 1){ … … 426 485 } 427 486 if(typeof testOrNull == "string"){ 428 this.registerTestNs(groupOrNs, testOrNull); 487 if(testOrNull.substr(0, 4)=="url:"){ 488 this.registerUrl(testOrNull); 489 }else{ 490 this.registerTest(groupOrNs, testOrNull); 491 } 492 // this.registerTestNs(groupOrNs, testOrNull); 429 493 return; 430 494 } … … 673 737 } 674 738 675 if(this["dojo"]){739 try{ 676 740 dojo.platformRequire({ 677 741 browser: ["tests._browserRunner"], … … 679 743 spidermonkey: ["tests._rhinoRunner"] 680 744 }); 681 dojo.require("tests._base"); 682 dojo.addOnLoad(function(){ 683 setTimeout(function(){ 684 tests.run(); 685 }, 100); 686 }); 745 var _shouldRequire = (dojo.isBrowser) ? (window == window.parent) : true; 746 if(_shouldRequire){ 747 dojo.require("tests._base"); 748 dojo.addOnLoad(function(){ 749 setTimeout(function(){ 750 tests.run(); 751 }, 100); 752 }); 753 } 687 754 // set us up for a run 688 }else if(this["load"]){ 689 load("_rhinoRunner.js"); 690 load("_base.js"); 691 692 print("\n"+tests._line); 693 print("The Dojo Unit Test Harness, $Rev$"); 694 print("Copyright (c) 2007, The Dojo Foundation, All Rights Reserved"); 695 print(tests._line, "\n"); 696 697 tests.run(); 698 } 755 }catch(e){ 756 if(this["load"]){ 757 load("_rhinoRunner.js"); 758 load("_base.js"); 759 760 print("\n"+tests._line); 761 print("The Dojo Unit Test Harness, $Rev$"); 762 print("Copyright (c) 2007, The Dojo Foundation, All Rights Reserved"); 763 print(tests._line, "\n"); 764 765 tests.run(); 766 } 767 } -
dojo/trunk/tests/_browserRunner.js
r7704 r7847 187 187 188 188 tests._groupStarted = function(group){ 189 // console.debug("_groupStarted", group); 189 190 getGroupNode(group).className = "inProgress"; 190 191 } 191 192 192 193 tests._groupFinished = function(group, success){ 194 // console.debug("_groupFinished", group); 193 195 getGroupNode(group).className = (success) ? "success" : "failure"; 194 196 } 195 197 196 198 tests._testStarted = function(group, fixture){ 199 // console.debug("_testStarted", group, fixture.name); 197 200 getFixtureNode(group, fixture).className = "inProgress"; 198 201 fixture.startTime = new Date(); … … 200 203 201 204 tests._testFinished = function(group, fixture, success){ 205 var fn = getFixtureNode(group, fixture); 206 fn.getElementsByTagName("td")[2].innerHTML = ((new Date())-fixture.startTime)+"ms"; 207 fn.className = (success) ? "success" : "failure"; 202 208 this.debug(((success) ? "PASSED" : "FAILED"), "test:", fixture.name); 203 var fn = getFixtureNode(group, fixture); 204 fn.className = (success) ? "success" : "failure"; 205 fn.getElementsByTagName("td")[2].innerHTML = ((new Date())-fixture.startTime)+"ms"; 209 } 210 211 // FIXME: move implementation to _browserRunner? 212 tests.registerUrl = function( /*String*/ group, 213 /*String*/ url, 214 /*Integer*/ timeout){ 215 var tg = new String(group); 216 this.register(group, { 217 name: url, 218 setUp: function(){ 219 tests.currentGroupName = tg; 220 tests.currentGroup = this; 221 tests.currentUrl = url; 222 this.d = new tests.Deferred(); 223 tests.currentTestDeferred = this.d; 224 showTestPage(); 225 byId("testBody").src = url; 226 }, 227 timeout: timeout||10000, // 10s 228 // timeout: timeout||1000, // 10s 229 runTest: function(){ 230 // FIXME: implement calling into the url's groups here!! 231 return this.d; 232 }, 233 tearDown: function(){ 234 tests.currentGroupName = null; 235 tests.currentGroup = null; 236 tests.currentTestDeferred = null; 237 tests.currentUrl = null; 238 // this.d.errback(false); 239 // byId("testBody").src = "about:blank"; 240 showLogPage(); 241 } 242 }); 206 243 } 207 244 … … 258 295 _addOnEvt("load", setListHeight); 259 296 _addOnEvt("load", function(){ 297 if(loaded){ return; } 260 298 loaded = true; 261 299 groupTemplate = byId("groupTemplate"); … … 274 312 _addOnEvt("load", 275 313 function(){ 314 if(loaded){ return; } 276 315 if(!byId("play")){ 277 316 // make sure we've got an ammenable DOM structure … … 307 346 }else{ 308 347 // we're in an iframe environment. Time to mix it up a bit. 309 tests = window.parent.tests; 348 349 _tests = window.parent.tests; 350 var _thisGroup = _tests.currentGroupName; 351 var _thisUrl = _tests.currentUrl; 352 if(_thisGroup){ 353 tests._testRegistered = function(group, tObj){ 354 _tests._updateTestList(_thisGroup, tObj); 355 } 356 tests._onEnd = function(){ 357 _tests.currentTestDeferred.callback(true); 358 } 359 var otr = tests._getTestObj; 360 tests._getTestObj = function(){ 361 var tObj = otr.apply(tests, arguments); 362 tObj.name = _thisUrl+"::"+arguments[0]+"::"+tObj.name; 363 return tObj; 364 } 365 tests.debug = tests.hitch(_tests, "debug"); 366 tests.registerUrl = tests.hitch(_tests, "registerUrl"); 367 tests._testStarted = function(group, fixture){ 368 _tests._testStarted(_thisGroup, fixture); 369 } 370 tests._testFinished = function(g, f, s){ 371 _tests._testFinished(_thisGroup, f, s); 372 } 373 } 310 374 } 311 375