Skip to content
Browse files

Merge branch 'master' of git://github.com/HBOCodeLabs/jasmine-node in…

…to HBOCodeLabs-master
  • Loading branch information...
2 parents d70424d + 4146f3e commit 94641f1aaf363beb2267f4d91b290d66574fd06b Chris Moultrie committed Jan 18, 2014
Showing with 61 additions and 8 deletions.
  1. +44 −2 lib/jasmine-node/reporter.js
  2. +17 −6 spec/reporter_spec.js
View
46 lib/jasmine-node/reporter.js
@@ -47,13 +47,17 @@
ANSIColors: {
pass: function() { return '\033[32m'; }, // Green
fail: function() { return '\033[31m'; }, // Red
+ specTiming: function() { return '\033[34m'; }, // Blue
+ suiteTiming: function() { return '\033[33m'; }, // Yelow
ignore: function() { return '\033[37m'; }, // Light Gray
neutral: function() { return '\033[0m'; } // Normal
},
NoColors: {
pass: function() { return ''; },
fail: function() { return ''; },
+ specTiming: function() { return ''; },
+ suiteTiming: function() { return ''; },
ignore: function() { return ''; },
neutral: function() { return ''; }
},
@@ -211,21 +215,50 @@
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) {
+ now = new Date().getTime();
+ this.specTimes_[spec.id] = now;
+ var suite = spec.suite;
+ while (suite) {
+ if (!this.suiteTimes_[suite.id]) {
+ this.suiteTimes_[suite.id] = now;
+ }
+ suite = suite.parentSuite;
+ }
+ },
+
reportSpecResults: function(spec) {
+ var elapsed = new Date().getTime() - this.specTimes_[spec.id];
+
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_);
@@ -257,11 +290,20 @@
} else {
msg = this.stringWithColor_(this.indentMessage_(element.name, depth), this.color_.fail());
}
+ msg += this.stringWithColor_(" - " + specResult.runtime + " ms",
+ this.color_.specTiming());
messages.push(msg);
} else {
messages.push('');
- messages.push(this.indentMessage_(element.name, depth));
+ msg = this.indentMessage_(element.name, depth)
+ if (element.id != null) {
+ suiteResult = this.suiteResults_[element.id.toString()];
+ if (suiteResult) {
+ msg += this.stringWithColor_(" - " + suiteResult.runtime + " ms", this.color_.suiteTiming());
+ }
+ }
+ messages.push(msg);
}
this.buildMessagesFromResults_(messages, element.children, depth + 2);
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');
});
});
});

0 comments on commit 94641f1

Please sign in to comment.
Something went wrong with that request. Please try again.