Skip to content

Commit

Permalink
Improved bash output
Browse files Browse the repository at this point in the history
As well as a test for the BashReporter
  • Loading branch information
felixge committed Nov 14, 2011
1 parent 84813b8 commit cb48e0f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/reporter/BashReporter.js
Expand Up @@ -3,17 +3,17 @@ function BashReporter(options) {
this._process = options.process || process;
this._collection = options.collection;

this._collection.on('fail', this.handleFail.bind(this));
this._process.on('exit', this.handleExit.bind(this));
this._collection.on('fail', this._handleFail.bind(this));
this._process.on('exit', this._handleExit.bind(this));
}

BashReporter.prototype.handleFail = function(testCase, test, error) {
this._process.stdout.write('Fail: ' + testCase.name + ': ' + test + '\n');
this._process.stdout.write(error.stack + '\n\n');

BashReporter.prototype._handleFail = function(testCase, test, error) {
this._process.stdout.write('Failed: ' + testCase.name + ' ' + test + '\n\n');
var stack = error.stack.replace(/^/gm, ' ');
this._process.stdout.write(stack + '\n\n');
};

BashReporter.prototype.handleExit = function() {
BashReporter.prototype._handleExit = function() {
var stats = this._collection.stats();
this._process.stdout.write(
stats.fail + ' fail | ' +
Expand Down
32 changes: 32 additions & 0 deletions test/unit/test-BashReporter.js
@@ -0,0 +1,32 @@
var assert = require('assert');
var BashReporter = require('../../lib/reporter/BashReporter');
var EventEmitter = require('events').EventEmitter;

(function testOutputOfFailedTests() {
var process = new EventEmitter();
var collection = new EventEmitter();
var reporter = new BashReporter({process: process, collection: collection});

var stdout = '';
process.stdout = {
write: function(chunk) {
stdout += chunk;
},
}

var testCase = {name: 'MyTestCase'};
var test = 'is awesome';
var error = {stack: 'Something went wrong:\nLine2\nLine3'};

collection.emit('fail', testCase, test, error);

assert.equal(
stdout,
'Failed: MyTestCase is awesome\n' +
'\n' +
' Something went wrong:\n' +
' Line2\n' +
' Line3\n' +
'\n'
);
})();

0 comments on commit cb48e0f

Please sign in to comment.