Skip to content

Commit

Permalink
refactor reporters, share more.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Jun 4, 2010
1 parent 8cd49ba commit bd8a4f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
18 changes: 18 additions & 0 deletions lib/vows/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ this.puts = function (options) {
return options.stream ? options.stream.write(args.join('\n') + '\n') : buffer.push(args);
};
};

this.result = function (event) {
var result = event.honored + " honored, " +
event.broken + " broken, " +
event.errored + " errored",
style = event.honored === event.total ? ('green')
: (event.errored === 0 ? 'yellow' : 'red'),
buffer = [];


if ('time' in event) {
buffer.push("\nVerified " + event.total + " vows in " +
(event.time + " seconds.\n"));
}
buffer.push(this.stylize(result, style));

return buffer;
};
19 changes: 5 additions & 14 deletions lib/vows/reporters/dot-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
var sys = require('sys');

var options = {};
var stylize = require('vows/console').stylize,
puts = require('vows/console').puts(options);
var console = require('vows/console');
var stylize = console.stylize,
puts = console.puts(options);
//
// Console reporter
//
var stream, buffer, messages = [];

this.name = 'dot-matrix';
this.report = function (data, s) {
var event = data[1];

Expand Down Expand Up @@ -46,24 +48,13 @@ this.report = function (data, s) {
sys.print(' ');
break;
case 'finish':
var result = event.honored + " honored, " +
event.broken + " broken, " +
event.errored + " errored",
style = event.honored === event.total ? ('green')
: (event.errored === 0 ? 'yellow' : 'red');

if (messages.length) {
messages.pop(); // drop trailing blank message
puts('\n\n' + messages.join('\n'));
} else {
sys.print('\n');
}

if ('time' in event) {
puts("\nVerified " + event.total + " vows in " +
(event.time + " seconds.\n"));
}
puts(stylize(result, style));
puts(console.result(event).join('\n'));
break;
case 'error':
puts('\n\n * ' + stylize(event.error, 'red'));
Expand Down
18 changes: 5 additions & 13 deletions lib/vows/reporters/spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
var sys = require('sys');

var options = {};
var stylize = require('vows/console').stylize,
puts = require('vows/console').puts(options);
var console = require('vows/console');
var stylize = console.stylize,
puts = console.puts(options);
//
// Console reporter
//

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

Expand Down Expand Up @@ -39,17 +41,7 @@ this.report = function (data, s) {
sys.print('\n');
break;
case 'finish':
var result = event.honored + " honored, " +
event.broken + " broken, " +
event.errored + " errored",
style = event.honored === event.total ? ('green')
: (event.errored === 0 ? 'yellow' : 'red');

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

0 comments on commit bd8a4f8

Please sign in to comment.