X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Fmisc%2Ffake-jstestdriver.js;h=772e10acb6ca5493bfd346081f819a58eeabebf8;hb=c715be428d83d80c0a26fd60dc5bc36fb4c908d9;hp=6f4f464afad1c2ed75f4797bcc9c2ef3e768d7ce;hpb=3bdeeb9b9d123e9e45159a6801b6e7fe74f08690;p=dygraphs.git diff --git a/auto_tests/misc/fake-jstestdriver.js b/auto_tests/misc/fake-jstestdriver.js index 6f4f464..772e10a 100644 --- a/auto_tests/misc/fake-jstestdriver.js +++ b/auto_tests/misc/fake-jstestdriver.js @@ -24,7 +24,19 @@ * @author konigsberg@google.com (Robert Konigsberg) */ var jstestdriver = { - jQuery : jQuery + jQuery : jQuery, + listeners_ : [], + announce_ : function(name, args) { + for (var idx = 0; idx < jstestdriver.listeners_.length; idx++) { + var listener = jstestdriver.listeners_[idx]; + if (listener[name]) { + listener[name].apply(null, args); + } + } + }, + attachListener: function(listener) { + jstestdriver.listeners_.push(listener); + } }; if (!console) { @@ -55,6 +67,7 @@ function TestCase(name) { testCase.prototype.setUp = function() { }; testCase.prototype.tearDown = function() { }; + testCase.prototype.name = name; /** * name can be a string, which is looked up in this object, or it can be a * function, in which case it's run. @@ -68,29 +81,35 @@ function TestCase(name) { * Chrome's console completion. */ testCase.prototype.runTest = function(func) { + var result = false; + var ex = null; + var name = typeof(func) == "string" ? func : "(anonymous function)"; + jstestdriver.announce_("start", [this, name]); try { - this.setUp(); - - var fn = null; - var parameterType = typeof(func); - if (typeof(func) == "function") { - fn = func; - } else if (typeof(func) == "string") { - fn = this[func]; - } else { - fail("can't supply " + typeof(func) + " to runTest"); - } - - fn.apply(this, []); - this.tearDown(); - return true; + result = this.runTest_(func); } catch (e) { - console.log(e); - if (e.stack) { - console.log(e.stack); - } - return false; + ex = e; } + jstestdriver.announce_("finish", [this, name, result, ex]); + return result; // TODO(konigsberg): Remove this, and return value from runAllTests. + } + + testCase.prototype.runTest_ = function(func) { + this.setUp(); + + var fn = null; + var parameterType = typeof(func); + if (typeof(func) == "function") { + fn = func; + } else if (typeof(func) == "string") { + fn = this[func]; + } else { + fail("can't supply " + typeof(func) + " to runTest"); + } + + fn.apply(this, []); + this.tearDown(); + return true; }; testCase.prototype.runAllTests = function() { @@ -152,3 +171,15 @@ function addGlobalTestSymbols() { function getAllTestCases() { return testCaseList; } + +jstestdriver.attachListener({ + finish : function(tc, name, result, e) { + if (e) { + console.log(e); + if (e.stack) { + console.log(e.stack); + } + } + } +}); +