Skip to content

Commit

Permalink
Merge pull request mochajs#167 from TooTallNate/no-carriage-returns
Browse files Browse the repository at this point in the history
No carriage returns in the built-in reporters (for Windows)
  • Loading branch information
tj committed Dec 20, 2011
2 parents 221a3c0 + 255d460 commit ca54edd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
13 changes: 13 additions & 0 deletions lib/reporters/base.js
Expand Up @@ -88,6 +88,19 @@ exports.cursor = {

show: function(){
process.stdout.write('\033[?25h');
},

deleteLine: function(){
process.stdout.write('\033[2K');
},

beginningOfLine: function(){
process.stdout.write('\033[0G');
},

CR: function(){
exports.cursor.deleteLine();
exports.cursor.beginningOfLine();
}
};

Expand Down
9 changes: 6 additions & 3 deletions lib/reporters/list.js
Expand Up @@ -4,6 +4,7 @@
*/

var Base = require('./base')
, cursor = Base.cursor
, color = Base.color;

/**
Expand Down Expand Up @@ -44,11 +45,13 @@ function List(runner) {
var fmt = color('checkmark', ' ✓')
+ color('pass', ' %s: ')
+ color(test.speed, '%dms');
console.log('\r' + fmt, test.fullTitle(), test.duration);
cursor.CR();
console.log(fmt, test.fullTitle(), test.duration);
});

runner.on('fail', function(test, err){
console.log('\r' + color('fail', ' %d) %s'), n++, test.fullTitle());
cursor.CR();
console.log(color('fail', ' %d) %s'), n++, test.fullTitle());
});

runner.on('end', self.epilogue.bind(self));
Expand All @@ -58,4 +61,4 @@ function List(runner) {
* Inherit from `Base.prototype`.
*/

List.prototype.__proto__ = Base.prototype;
List.prototype.__proto__ = Base.prototype;
5 changes: 3 additions & 2 deletions lib/reporters/progress.js
Expand Up @@ -58,7 +58,8 @@ function Progress(runner, options) {
, n = width * percent | 0
, i = width - n;

process.stdout.write('\r\033[J');
cursor.CR();
process.stdout.write('\033[J');
process.stdout.write(color('progress', ' ' + options.open));
process.stdout.write(Array(n).join(options.complete));
process.stdout.write(Array(i).join(options.incomplete));
Expand All @@ -81,4 +82,4 @@ function Progress(runner, options) {
* Inherit from `Base.prototype`.
*/

Progress.prototype.__proto__ = Base.prototype;
Progress.prototype.__proto__ = Base.prototype;
12 changes: 8 additions & 4 deletions lib/reporters/spec.js
Expand Up @@ -4,6 +4,7 @@
*/

var Base = require('./base')
, cursor = Base.cursor
, color = Base.color;

/**
Expand Down Expand Up @@ -59,18 +60,21 @@ function Spec(runner) {
var fmt = indent()
+ color('checkmark', ' ✓')
+ color('pass', ' %s ');
console.log('\r' + fmt, test.title);
cursor.CR();
console.log(fmt, test.title);
} else {
var fmt = indent()
+ color('checkmark', ' ✓')
+ color('pass', ' %s ')
+ color(test.speed, '(%dms)');
console.log('\r' + fmt, test.title, test.duration);
cursor.CR();
console.log(fmt, test.title, test.duration);
}
});

runner.on('fail', function(test, err){
console.log('\r' + indent() + color('fail', ' %d) %s'), n++, test.title);
cursor.CR();
console.log(indent() + color('fail', ' %d) %s'), n++, test.title);
});

runner.on('end', self.epilogue.bind(self));
Expand All @@ -80,4 +84,4 @@ function Spec(runner) {
* Inherit from `Base.prototype`.
*/

Spec.prototype.__proto__ = Base.prototype;
Spec.prototype.__proto__ = Base.prototype;

0 comments on commit ca54edd

Please sign in to comment.