Skip to content

Commit

Permalink
Merge pull request #1 from HBOCodeLabs/rkilgore/timing
Browse files Browse the repository at this point in the history
add timing info to verbose report
  • Loading branch information
Rick Kilgore committed Jan 18, 2014
2 parents ffd8d3f + 9e50254 commit 4146f3e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
46 changes: 44 additions & 2 deletions lib/jasmine-node/reporter.js
Expand Up @@ -47,13 +47,17 @@
ANSIColors: { ANSIColors: {
pass: function() { return '\033[32m'; }, // Green pass: function() { return '\033[32m'; }, // Green
fail: function() { return '\033[31m'; }, // Red 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 ignore: function() { return '\033[37m'; }, // Light Gray
neutral: function() { return '\033[0m'; } // Normal neutral: function() { return '\033[0m'; } // Normal
}, },


NoColors: { NoColors: {
pass: function() { return ''; }, pass: function() { return ''; },
fail: function() { return ''; }, fail: function() { return ''; },
specTiming: function() { return ''; },
suiteTiming: function() { return ''; },
ignore: function() { return ''; }, ignore: function() { return ''; },
neutral: function() { return ''; } neutral: function() { return ''; }
}, },
Expand Down Expand Up @@ -211,21 +215,50 @@
jasmineNode.TerminalReporter.call(this, config); jasmineNode.TerminalReporter.call(this, config);
// The extra field in this object // The extra field in this object
this.indent_ = 0; this.indent_ = 0;
this.specTimes_ = {};
this.suiteTimes_ = {};
this.suiteResults_ = {};
} }




jasmineNode.TerminalVerboseReporter.prototype = { 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) { reportSpecResults: function(spec) {
var elapsed = new Date().getTime() - this.specTimes_[spec.id];

if (spec.results().failedCount > 0) { if (spec.results().failedCount > 0) {
this.addFailureToFailures_(spec); this.addFailureToFailures_(spec);
} }


this.specResults_[spec.id] = { this.specResults_[spec.id] = {
messages: spec.results().getItems(), 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) { reportRunnerResults: function(runner) {
var messages = new Array(); var messages = new Array();
this.buildMessagesFromResults_(messages, this.suites_); this.buildMessagesFromResults_(messages, this.suites_);
Expand Down Expand Up @@ -257,11 +290,20 @@
} else { } else {
msg = this.stringWithColor_(this.indentMessage_(element.name, depth), this.color_.fail()); msg = this.stringWithColor_(this.indentMessage_(element.name, depth), this.color_.fail());
} }
msg += this.stringWithColor_(" - " + specResult.runtime + " ms",
this.color_.specTiming());


messages.push(msg); messages.push(msg);
} else { } else {
messages.push(''); 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); this.buildMessagesFromResults_(messages, element.children, depth + 2);
Expand Down
23 changes: 17 additions & 6 deletions spec/reporter_spec.js
Expand Up @@ -383,6 +383,7 @@ describe('TerminalVerboseReporter', function() {
describe('#buildMessagesFromResults_', function() { describe('#buildMessagesFromResults_', function() {
beforeEach(function() { beforeEach(function() {
this.suite = { this.suite = {
id: 17,
type: 'suite', type: 'suite',
name: 'a describe block', name: 'a describe block',
suiteNestingLevel: 0, suiteNestingLevel: 0,
Expand All @@ -398,7 +399,12 @@ describe('TerminalVerboseReporter', function() {
}; };


this.verboseReporter.specResults_['23'] = { this.verboseReporter.specResults_['23'] = {
result: 'passed' result: 'passed',
runtime: 200
};

this.verboseReporter.suiteResults_['17'] = {
runtime: 500
}; };


}); });
Expand All @@ -422,7 +428,7 @@ describe('TerminalVerboseReporter', function() {


expect(messages.length).toEqual(2); expect(messages.length).toEqual(2);
expect(messages[0]).toEqual(''); 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() { it('adds a single spec with success to the messages', function() {
Expand All @@ -437,7 +443,7 @@ describe('TerminalVerboseReporter', function() {


expect(this.passSpy).toHaveBeenCalled(); expect(this.passSpy).toHaveBeenCalled();
expect(messages.length).toEqual(1); 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() { it('adds a single spec with failure to the messages', function() {
Expand All @@ -462,6 +468,7 @@ describe('TerminalVerboseReporter', function() {
messages = []; messages = [];


var subSuite = new Object(); var subSuite = new Object();
subSuite.id = '29';
subSuite.type = 'suite'; subSuite.type = 'suite';
subSuite.name = 'a sub describe block'; subSuite.name = 'a sub describe block';
subSuite.suiteNestingLevel = 1; subSuite.suiteNestingLevel = 1;
Expand All @@ -471,14 +478,18 @@ describe('TerminalVerboseReporter', function() {
this.suite.children.push(subSuite); this.suite.children.push(subSuite);
results.push(this.suite); results.push(this.suite);


this.verboseReporter.suiteResults_['29'] = {
runtime: 350
};

this.verboseReporter.buildMessagesFromResults_(messages, results); this.verboseReporter.buildMessagesFromResults_(messages, results);


expect(messages.length).toEqual(5); expect(messages.length).toEqual(5);
expect(messages[0]).toEqual(''); 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[2]).toEqual('');
expect(messages[3]).toEqual(' a sub describe block'); expect(messages[3]).toEqual(' a sub describe block - 350 ms');
expect(messages[4]).toEqual(' a spec block'); expect(messages[4]).toEqual(' a spec block - 200 ms');
}); });
}); });
}); });

0 comments on commit 4146f3e

Please sign in to comment.