mirror of
https://github.com/harish2704/simple-mocha.git
synced 2026-09-10 06:21:08 +00:00
Cleanup printing messages
This commit is contained in:
+46
-4
@@ -6,7 +6,19 @@ var async = require('async');
|
|||||||
|
|
||||||
|
|
||||||
var pr = console.log;
|
var pr = console.log;
|
||||||
|
|
||||||
var INDENT = ' ';
|
var INDENT = ' ';
|
||||||
|
var STATUS_FLAG = {
|
||||||
|
true : 'Okey',
|
||||||
|
false : 'Fail'
|
||||||
|
};
|
||||||
|
|
||||||
|
function print( level, item ){
|
||||||
|
var indent = getIndent( level );
|
||||||
|
var status = STATUS_FLAG[ item.isSuccess ];
|
||||||
|
var timeTaken = '(' + ( item.endTime - item.startTime ) + 'ms)';
|
||||||
|
pr( [ indent, status, item.description, timeTaken ].join(' ') );
|
||||||
|
};
|
||||||
|
|
||||||
function safeFn( fn ){
|
function safeFn( fn ){
|
||||||
return function( done ){
|
return function( done ){
|
||||||
@@ -39,12 +51,26 @@ function mkAsyncFn( fn ){
|
|||||||
function ItBlock( description, fn ){
|
function ItBlock( description, fn ){
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.fn = mkAsyncFn( fn );
|
this.fn = mkAsyncFn( fn );
|
||||||
|
this.isSuccess = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItBlock.prototype.run = function( done ){
|
ItBlock.prototype.run = function( done ){
|
||||||
pr( getIndent( this.parent.level+1 ) + this.description );
|
var self = this;
|
||||||
this.fn( done );
|
this.startTime = Date.now();
|
||||||
|
this.fn( function( err ){
|
||||||
|
self.endTime = Date.now();
|
||||||
|
if( !err ){
|
||||||
|
self.isSuccess = true;
|
||||||
}
|
}
|
||||||
|
self.print();
|
||||||
|
done( err );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ItBlock.prototype.print = function(){
|
||||||
|
print( this.parent.level+1, this );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -63,6 +89,8 @@ function DescribeBlock( description, parentBlock ){
|
|||||||
this.its = [];
|
this.its = [];
|
||||||
this.beforeEach = null;
|
this.beforeEach = null;
|
||||||
this.afterEach = null;
|
this.afterEach = null;
|
||||||
|
|
||||||
|
this.isSuccess = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +109,7 @@ DescribeBlock.prototype.addItBlock = function( description, fn ){
|
|||||||
|
|
||||||
DescribeBlock.prototype.run = function( cb ){
|
DescribeBlock.prototype.run = function( cb ){
|
||||||
var tasks = [];
|
var tasks = [];
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if( this.beforeFn ){ tasks.push( this.beforeFn ); }
|
if( this.beforeFn ){ tasks.push( this.beforeFn ); }
|
||||||
|
|
||||||
@@ -96,9 +125,22 @@ DescribeBlock.prototype.run = function( cb ){
|
|||||||
|
|
||||||
if( this.afterFn ){ tasks.push( this.afterFn ); }
|
if( this.afterFn ){ tasks.push( this.afterFn ); }
|
||||||
|
|
||||||
|
pr( getIndent( this.level) + '---' + this.description + '---' );
|
||||||
|
this.startTime = Date.now();
|
||||||
|
return async.waterfall( tasks, function( err ){
|
||||||
|
|
||||||
pr( getIndent( this.level) + this.description );
|
self.endTime = Date.now();
|
||||||
return async.waterfall( tasks, cb );
|
if( !err ){
|
||||||
|
self.isSuccess = true;
|
||||||
|
}
|
||||||
|
self.print();
|
||||||
|
cb && cb( err );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DescribeBlock.prototype.print = function(){
|
||||||
|
print( this.level, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -8,7 +8,9 @@ var SimpleMocha = require( './index-v1' );
|
|||||||
var sm = new SimpleMocha();
|
var sm = new SimpleMocha();
|
||||||
|
|
||||||
sm.onLoad = function(){
|
sm.onLoad = function(){
|
||||||
sm.rootDescribeBlock.run();
|
sm.rootDescribeBlock.run( function( err ){
|
||||||
|
console.log( err ? 'Finished with error' : 'Finished Successfully', err );
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user