mirror of
https://github.com/harish2704/simple-mocha.git
synced 2026-09-10 06:21:08 +00:00
Feat: parse it blocks
Tests passed
This commit is contained in:
+41
-3
@@ -1,10 +1,35 @@
|
|||||||
|
|
||||||
|
|
||||||
// var _d = console.log.bind( console, 'dbg: ' );
|
// var _d = console.log.bind( console, 'dbg: ' );
|
||||||
var _d = function(){};
|
var _d = function(){};
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
function DescribeBlock( parentBlock ){
|
|
||||||
|
|
||||||
|
function mkAsyncFn( fn ){
|
||||||
|
return function( done ){
|
||||||
|
setTimeout( function(){
|
||||||
|
fn();
|
||||||
|
done();
|
||||||
|
}, 1 );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function ItBlock( description, fn ){
|
||||||
|
var isAsync = ( fn.length > 0 );
|
||||||
|
|
||||||
|
this.description = description;
|
||||||
|
this.fn = isAsync ? fn : mkAsyncFn( fn );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function DescribeBlock( description, parentBlock ){
|
||||||
_d( 'DescribeBlock:init', parentBlock );
|
_d( 'DescribeBlock:init', parentBlock );
|
||||||
|
|
||||||
|
this.description = description || '';
|
||||||
this.parent = parentBlock;
|
this.parent = parentBlock;
|
||||||
if( parentBlock ){
|
if( parentBlock ){
|
||||||
parentBlock.addChild( this );
|
parentBlock.addChild( this );
|
||||||
@@ -16,11 +41,17 @@ function DescribeBlock( parentBlock ){
|
|||||||
this.afterEach = null;
|
this.afterEach = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DescribeBlock.prototype.addChild = function( child ){
|
DescribeBlock.prototype.addChild = function( child ){
|
||||||
this.children.push( child );
|
this.children.push( child );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
DescribeBlock.prototype.addItBlock = function( description, fn ){
|
||||||
|
this.its.push( new ItBlock( description, fn ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function SimpleMocha(){
|
function SimpleMocha(){
|
||||||
@@ -36,20 +67,27 @@ function SimpleMocha(){
|
|||||||
this.currentDescribeBlock = this.rootDescribeBlock;
|
this.currentDescribeBlock = this.rootDescribeBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SimpleMocha.prototype.describe = function( description, fn ){
|
SimpleMocha.prototype.describe = function( description, fn ){
|
||||||
var parentDescribeBlock = this.currentDescribeBlock;
|
var parentDescribeBlock = this.currentDescribeBlock;
|
||||||
var thisDescribeBlock = new DescribeBlock( parentDescribeBlock );
|
var thisDescribeBlock = new DescribeBlock( description, parentDescribeBlock );
|
||||||
|
|
||||||
this.currentDescribeBlock = thisDescribeBlock;
|
this.currentDescribeBlock = thisDescribeBlock;
|
||||||
fn();
|
fn();
|
||||||
this.currentDescribeBlock = parentDescribeBlock;
|
this.currentDescribeBlock = parentDescribeBlock;
|
||||||
};
|
};
|
||||||
|
|
||||||
SimpleMocha.prototype.it = function(){};
|
|
||||||
|
SimpleMocha.prototype.it = function( description, fn ){
|
||||||
|
this.currentDescribeBlock.addItBlock( description, fn );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
SimpleMocha.prototype.before = function( fn ){
|
SimpleMocha.prototype.before = function( fn ){
|
||||||
this.currentDescribeBlock.beforeFn = fn;
|
this.currentDescribeBlock.beforeFn = fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SimpleMocha.prototype.after = function(){};
|
SimpleMocha.prototype.after = function(){};
|
||||||
SimpleMocha.prototype.beforeEach = function(){};
|
SimpleMocha.prototype.beforeEach = function(){};
|
||||||
SimpleMocha.prototype.afterEach = function(){};
|
SimpleMocha.prototype.afterEach = function(){};
|
||||||
|
|||||||
Reference in New Issue
Block a user