Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add timing info to test verbose results

  • Loading branch information...
commit 5a9b99fd7f3c181abb8bea09e0bff1c1b27a4d26 1 parent ffd8d3f
@rick-kilgore rick-kilgore authored
Showing with 55 additions and 10 deletions.
  1. +38 −4 lib/jasmine-node/reporter.js
  2. +17 −6 spec/reporter_spec.js
View
42 lib/jasmine-node/reporter.js
@@ -91,7 +91,7 @@
return summary;
},
- // This is heavily influenced by Jasmine's Html/Trivial Reporter
+ // This is heavily influenced by Jasmine''s Html/Trivial Reporter
reportRunnerResults: function(runner) {
this.reportFailures_();
@@ -205,27 +205,56 @@
};
// ***************************************************************
- // TerminalVerboseReporter uses the TerminalReporter's constructor
+ // TerminalVerboseReporter uses the TerminalReporter''s constructor
// ***************************************************************
jasmineNode.TerminalVerboseReporter = function(config) {
jasmineNode.TerminalReporter.call(this, config);
// The extra field in this object
this.indent_ = 0;
+ this.specTimes_ = { };
+ this.suiteTimes_ = { };
+ this.suiteResults_ = {};
}
jasmineNode.TerminalVerboseReporter.prototype = {
+
+ reportSpecStarting: function(spec) {
+ this.specTimes_[spec.id] = new Date().getTime();
+ var suite = spec.suite;
+ while (suite) {
+ if (!this.suiteTimes_[suite.id]) {
+ this.suiteTimes_[suite.id] = new Date().getTime();
+ }
+ suite = suite.parentSuite;
+ }
+ },
+
reportSpecResults: function(spec) {
+ var elapsed = new Date().getTime() - this.specTimes_[spec.id];
+ // jasmine.getGlobal().console.log "spec runtime: #{spec.description} - #{elapsed} ms"
+
if (spec.results().failedCount > 0) {
this.addFailureToFailures_(spec);
}
this.specResults_[spec.id] = {
messages: spec.results().getItems(),
- result: spec.results().failedCount > 0 ? 'failed' : 'passed'
+ result: spec.results().failedCount > 0 ? 'failed' : 'passed',
+ runtime: elapsed
};
},
+ reportSuiteResults: function(suite) {
+ var startTime = this.suiteTimes_[suite.id];
+ if (startTime) {
+ var elapsed = new Date().getTime() - startTime;
+ this.suiteResults_[suite.id] = {
+ runtime: elapsed
+ };
+ }
+ },
+
reportRunnerResults: function(runner) {
var messages = new Array();
this.buildMessagesFromResults_(messages, this.suites_);
@@ -237,7 +266,7 @@
this.print_(messages[messages_length-1]);
- // Call the parent object's method
+ // Call the parent object''s method
jasmineNode.TerminalReporter.prototype.reportRunnerResults.call(this, runner);
},
@@ -251,6 +280,7 @@
if (element.type === 'spec') {
specResult = this.specResults_[element.id.toString()];
+ element.name = element.name + " - " + specResult.runtime + " ms"
if (specResult.result === 'passed') {
msg = this.stringWithColor_(this.indentMessage_(element.name, depth), this.color_.pass());
@@ -260,6 +290,10 @@
messages.push(msg);
} else {
+ if (element.id) {
+ suiteResult = this.suiteResults_[element.id.toString()];
+ element.name = element.name + " - " + suiteResult.runtime + " ms";
+ }
messages.push('');
messages.push(this.indentMessage_(element.name, depth));
}
View
23 spec/reporter_spec.js
@@ -383,6 +383,7 @@ describe('TerminalVerboseReporter', function() {
describe('#buildMessagesFromResults_', function() {
beforeEach(function() {
this.suite = {
+ id: 17,
type: 'suite',
name: 'a describe block',
suiteNestingLevel: 0,
@@ -398,7 +399,12 @@ describe('TerminalVerboseReporter', function() {
};
this.verboseReporter.specResults_['23'] = {
- result: 'passed'
+ result: 'passed',
+ runtime: 200
+ };
+
+ this.verboseReporter.suiteResults_['17'] = {
+ runtime: 500
};
});
@@ -422,7 +428,7 @@ describe('TerminalVerboseReporter', function() {
expect(messages.length).toEqual(2);
expect(messages[0]).toEqual('');
- expect(messages[1]).toEqual('a describe block');
+ expect(messages[1]).toEqual('a describe block - 500 ms');
});
it('adds a single spec with success to the messages', function() {
@@ -437,7 +443,7 @@ describe('TerminalVerboseReporter', function() {
expect(this.passSpy).toHaveBeenCalled();
expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual('a spec block');
+ expect(messages[0]).toEqual('a spec block - 200 ms');
});
it('adds a single spec with failure to the messages', function() {
@@ -462,6 +468,7 @@ describe('TerminalVerboseReporter', function() {
messages = [];
var subSuite = new Object();
+ subSuite.id = '29';
subSuite.type = 'suite';
subSuite.name = 'a sub describe block';
subSuite.suiteNestingLevel = 1;
@@ -471,14 +478,18 @@ describe('TerminalVerboseReporter', function() {
this.suite.children.push(subSuite);
results.push(this.suite);
+ this.verboseReporter.suiteResults_['29'] = {
+ runtime: 350
+ };
+
this.verboseReporter.buildMessagesFromResults_(messages, results);
expect(messages.length).toEqual(5);
expect(messages[0]).toEqual('');
- expect(messages[1]).toEqual('a describe block');
+ expect(messages[1]).toEqual('a describe block - 500 ms');
expect(messages[2]).toEqual('');
- expect(messages[3]).toEqual(' a sub describe block');
- expect(messages[4]).toEqual(' a spec block');
+ expect(messages[3]).toEqual(' a sub describe block - 350 ms');
+ expect(messages[4]).toEqual(' a spec block - 200 ms');
});
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.