Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Aug 1, 2011
1 parent e0d70cb commit 3561c44
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions lib/reporter/bash_reporter.js
Expand Up @@ -8,33 +8,41 @@ function BashReporter() {
}

BashReporter.prototype.watch = function(testCase) {
var self = this;
testCase
.on('test.end', function(test) {
var error = test.error;
if (!error) {
return;
}

var file = error.file;
if (file.indexOf(process.cwd()) === 0) {
file = file.substr(process.cwd().length + 1);
}

console.log('! ' + test.name + ' (line ' + error.line + ' in ' + file + ')\n');

var stack = test.error.stack;
stack = stack.replace(/(.+)/gm, ' $1');
self.stdout.write(stack + '\n\n');
})
.on('end', function() {
var stats = testCase.stats();
console.log('%d fail | %d pass (%d ms)', stats.fail, stats.pass, stats.duration);

var exitCode = (stats.fail)
? 1
: 0;

process.exit(exitCode);
});
.on('test.end', this.testEnd(testCase))
.on('end', this.testCaseEnd(testCase));
};

BashReporter.prototype.testEnd = function(testCase) {
var self = this;
return function(test) {
var error = test.error;
if (!error) {
return;
}

var file = error.file;
if (file.indexOf(process.cwd()) === 0) {
file = file.substr(process.cwd().length + 1);
}

console.log('! ' + test.name + ' (line ' + error.line + ' in ' + file + ')\n');

var stack = test.error.stack;
stack = stack.replace(/(.+)/gm, ' $1');
self.stdout.write(stack + '\n\n');
};
};

BashReporter.prototype.testCaseEnd = function(testCase) {
return function() {
var stats = testCase.stats();
console.log('%d fail | %d pass (%d ms)', stats.fail, stats.pass, stats.duration);

var exitCode = (stats.fail)
? 1
: 0;

process.exit(exitCode);
}
};

0 comments on commit 3561c44

Please sign in to comment.