From: Robert Konigsberg Date: Thu, 28 Apr 2011 16:17:56 +0000 (-0400) Subject: Added runAllTests. Useful. X-Git-Tag: v1.0.0~486^2~6 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=9d076ffecc3dc9cc3a8ef411fa8ee61d54b2c3bf;p=dygraphs.git Added runAllTests. Useful. --- diff --git a/auto_tests/misc/fake-jstestdriver.js b/auto_tests/misc/fake-jstestdriver.js index 4849f99..9ca10cd 100644 --- a/auto_tests/misc/fake-jstestdriver.js +++ b/auto_tests/misc/fake-jstestdriver.js @@ -43,18 +43,32 @@ function TestCase(name) { return "Fake test case " + name; }; - var emptyFunction = function() { return this; }; - emptyFunction.prototype.setUp = function() { }; - emptyFunction.prototype.tearDown = function() { }; - emptyFunction.prototype.runTest = function(name) { + var testCase = function() { return this; }; + testCase.prototype.setUp = function() { }; + testCase.prototype.tearDown = function() { }; + testCase.prototype.runTest = function(name) { try { this.setUp(); var fn = this[name]; fn.apply(this, []); this.tearDown(); + return true; } catch (e) { console.log(e.stack); + return false; } }; - return emptyFunction; + testCase.prototype.runAllTests = function() { + // what's better than for ... in for non-array objects? + var tests = {}; + for (var name in this) { + if (name.indexOf('test') == 0 && typeof(this[name]) == 'function') { + console.log("Running " + name); + var result = this.runTest(name); + tests[name] = result; + } + } + console.log(prettyPrintEntity_(tests)); + }; + return testCase; };