Skip to content

Commit

Permalink
make console reporter a little more powerful
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed May 17, 2010
1 parent 1606341 commit 98c70ad
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/vows/reporters/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ var sys = require('sys');
//
// Console reporter
//
this.report = function (data) {
var stream, buffer;

this.report = function (data, s) {
var event = data[1];

stream = typeof(s) === 'object' ? s : process.stdout;
buffer = [];

switch (data[0]) {
case 'subject':
puts('\n' + stylize(event, 'underline') + '\n');
Expand Down Expand Up @@ -37,22 +42,25 @@ this.report = function (data) {
style = event.honored === event.total ? ('green')
: (event.errored === 0 ? 'yellow' : 'red');

puts("\nVerified " + event.total + " vows in " +
(event.time + " seconds."));
puts("\n" + stylize(result, style));
if (event.time) {
puts("\nVerified " + event.total + " vows in " +
(event.time + " seconds.\n"));
}
puts(stylize(result, style));
break;
case 'error':
puts('\n * ' + stylize(event.error, 'red'));
break;
}
return buffer.join('');
};

function puts(args) {
args = Array.prototype.slice.call(arguments).map(function (a) {
return a.replace(/`([^`]+)`/g, function (_, capture) { return stylize(capture, 'italic') })
.replace(/\*([^*]+)\*/g, function (_, capture) { return stylize(capture, 'bold') });
});
sys.puts.apply(null, args);
return stream ? stream.write(args.join('\n') + '\n') : buffer.push(args);
}

// Stylize a string
Expand Down

0 comments on commit 98c70ad

Please sign in to comment.