diff --git a/spec/suites/TrivialNodeReporterSpec.js b/spec/suites/TrivialNodeReporterSpec.js index 4815a7b..fe82d03 100644 --- a/spec/suites/TrivialNodeReporterSpec.js +++ b/spec/suites/TrivialNodeReporterSpec.js @@ -34,7 +34,8 @@ describe("TrivialNodeReporter", function() { return { puts:function(str) {output += str + "\n";}, print:function(str) {output += str;}, - getOutput:function(){return output;} + getOutput:function(){return output;}, + clear: function(){output = "";} }; })(); @@ -122,6 +123,48 @@ describe("TrivialNodeReporter", function() { newline + prefixRed("Finished") ); }); + + it("prints the elapsed time in the summary message", function(){ + this.reporter.now = function(){return 1000} + this.reporter.reportRunnerStarting(); + this.reporter.now = function(){return 1777} + this.reporter.reportRunnerResults(passingRun); + expect(this.fakeSys.getOutput()).toContain("0.777 seconds"); + }); + + it("prints round time numbers correctly", function(){ + var self = this; + function run(startTime, endTime) { + self.fakeSys.clear(); + self.reporter.runnerStartTime = startTime; + self.reporter.now = function(){return endTime} + self.reporter.reportRunnerResults(passingRun); + } + + run(1000, 11000); + expect(this.fakeSys.getOutput()).toContain("10 seconds"); + + run(1000, 2000); + expect(this.fakeSys.getOutput()).toContain("1 seconds"); + + run(1000, 1100); + expect(this.fakeSys.getOutput()).toContain("0.1 seconds"); + + run(1000, 1010); + expect(this.fakeSys.getOutput()).toContain("0.01 seconds"); + + run(1000, 1001); + expect(this.fakeSys.getOutput()).toContain("0.001 seconds"); + }); + + it("altogether now", function(){ + this.reporter.now = function(){return 1000} + this.reporter.reportRunnerStarting(); + this.reporter.now = function(){return 1777} + this.reporter.reportRunnerResults(failingRun); + expect(this.fakeSys.getOutput()).toContain(red("Finished in 0.777 seconds")); + }); + }); }); diff --git a/src/node/TrivialNodeReporter.js b/src/node/TrivialNodeReporter.js index 14164d1..9b4234f 100644 --- a/src/node/TrivialNodeReporter.js +++ b/src/node/TrivialNodeReporter.js @@ -22,9 +22,9 @@ jasmine.TrivialNodeReporter = function(sys) { function redF() { sys.print(redStr("F")); } function yellowStar() { sys.print(yellowStr("*")); } - function finished(colorF) { newline(); sys.print(colorF("Finished")); } - function greenFinished() { finished(greenStr); } - function redFinished() { finished(redStr); } + function finished(colorF, elapsed) { newline(); sys.print(colorF("Finished in " + elapsed/1000 + " seconds")); } + function greenFinished(elapsed) { finished(greenStr, elapsed); } + function redFinished(elapsed) { finished(redStr, elapsed); } @@ -42,7 +42,10 @@ jasmine.TrivialNodeReporter = function(sys) { var startNewLineIfNecessary = lineEnder(defaultColumnsPerLine); + this.now = function() { return new Date().getTime(); } + this.reportRunnerStarting = function() { + this.runnerStartTime = this.now(); started(); }; @@ -59,10 +62,12 @@ jasmine.TrivialNodeReporter = function(sys) { }; this.reportRunnerResults = function(runner) { + var elapsed = this.now() - this.runnerStartTime; + if (runner.results().failedCount === 0) { - greenFinished(); + greenFinished(elapsed); } else { - redFinished(); + redFinished(elapsed); } }; }; \ No newline at end of file