clean up reporter a bit

This commit is contained in:
John Bintz 2011-05-12 18:47:56 -04:00
parent e761616830
commit dff767cad1
2 changed files with 14 additions and 13 deletions

View File

@ -5,6 +5,8 @@ class HeadlessReporterResult
constructor: (name) -> constructor: (name) ->
@name = name @name = name
@results = [] @results = []
addResult: (message) ->
@results.push(message)
print: -> print: ->
JHW.printName(@name) JHW.printName(@name)
for result in @results for result in @results
@ -15,17 +17,16 @@ class jasmine.HeadlessReporter
constructor: -> constructor: ->
@results = [] @results = []
@failedCount = 0 @failedCount = 0
@totalDuration = 0.0
@length = 0 @length = 0
reportRunnerResults: (runner) -> reportRunnerResults: (runner) ->
for result in @results for result in @results
do (result) => do (result) =>
result.print() result.print()
JHW.finishSuite(@totalDuration / 1000.0, @length, @failedCount) JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount)
reportRunnerStarting: (runner) -> reportRunnerStarting: (runner) ->
@startTime = new Date()
reportSpecResults: (spec) -> reportSpecResults: (spec) ->
@totalDuration += (new Date() - spec.startTime)
if spec.results().passed() if spec.results().passed()
JHW.specPassed() JHW.specPassed()
else else
@ -35,9 +36,8 @@ class jasmine.HeadlessReporter
do (result) => do (result) =>
if result.type == 'expect' and !result.passed_ if result.type == 'expect' and !result.passed_
@failedCount += 1 @failedCount += 1
failureResult.results.push(result.message) failureResult.addResult(result.message)
@results.push(failureResult) @results.push(failureResult)
reportSpecStarting: (spec) -> reportSpecStarting: (spec) ->
spec.startTime = new Date()
reportSuiteResults: (suite) -> reportSuiteResults: (suite) ->
@length += suite.specs().length @length += suite.specs().length

View File

@ -9,6 +9,9 @@
this.name = name; this.name = name;
this.results = []; this.results = [];
} }
HeadlessReporterResult.prototype.addResult = function(message) {
return this.results.push(message);
};
HeadlessReporterResult.prototype.print = function() { HeadlessReporterResult.prototype.print = function() {
var result, _i, _len, _ref, _results; var result, _i, _len, _ref, _results;
JHW.printName(this.name); JHW.printName(this.name);
@ -28,7 +31,6 @@
function HeadlessReporter() { function HeadlessReporter() {
this.results = []; this.results = [];
this.failedCount = 0; this.failedCount = 0;
this.totalDuration = 0.0;
this.length = 0; this.length = 0;
} }
HeadlessReporter.prototype.reportRunnerResults = function(runner) { HeadlessReporter.prototype.reportRunnerResults = function(runner) {
@ -41,12 +43,13 @@
result = _ref[_i]; result = _ref[_i];
_fn(result); _fn(result);
} }
return JHW.finishSuite(this.totalDuration / 1000.0, this.length, this.failedCount); return JHW.finishSuite((new Date() - this.startTime) / 1000.0, this.length, this.failedCount);
};
HeadlessReporter.prototype.reportRunnerStarting = function(runner) {
return this.startTime = new Date();
}; };
HeadlessReporter.prototype.reportRunnerStarting = function(runner) {};
HeadlessReporter.prototype.reportSpecResults = function(spec) { HeadlessReporter.prototype.reportSpecResults = function(spec) {
var failureResult, result, _fn, _i, _len, _ref; var failureResult, result, _fn, _i, _len, _ref;
this.totalDuration += new Date() - spec.startTime;
if (spec.results().passed()) { if (spec.results().passed()) {
return JHW.specPassed(); return JHW.specPassed();
} else { } else {
@ -56,7 +59,7 @@
_fn = __bind(function(result) { _fn = __bind(function(result) {
if (result.type === 'expect' && !result.passed_) { if (result.type === 'expect' && !result.passed_) {
this.failedCount += 1; this.failedCount += 1;
return failureResult.results.push(result.message); return failureResult.addResult(result.message);
} }
}, this); }, this);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -66,9 +69,7 @@
return this.results.push(failureResult); return this.results.push(failureResult);
} }
}; };
HeadlessReporter.prototype.reportSpecStarting = function(spec) { HeadlessReporter.prototype.reportSpecStarting = function(spec) {};
return spec.startTime = new Date();
};
HeadlessReporter.prototype.reportSuiteResults = function(suite) { HeadlessReporter.prototype.reportSuiteResults = function(suite) {
return this.length += suite.specs().length; return this.length += suite.specs().length;
}; };