Skip to content

Commit

Permalink
Added suite merging. Closes #28
Browse files Browse the repository at this point in the history
the merge.js example there with --reporter spec
will result in:

  merge
    stuff
      one
        ✓ should do something
      two
        ✓ should do stuff
      three
        ✓ should do something
      four
        ✓ should do something
  • Loading branch information
tj committed Nov 16, 2011
1 parent 804d517 commit e474461
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/interfaces/bdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ module.exports = function(suite){
*/

context.describe = function(title, fn){
var suite = new Suite(title);
suites[0].addSuite(suite);
var suite = Suite.create(suites[0], title);
suites.unshift(suite);
fn();
suites.shift();
Expand Down
36 changes: 35 additions & 1 deletion lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,35 @@ var EventEmitter = require('events').EventEmitter;
* Expose `Suite`.
*/

module.exports = Suite;
exports = module.exports = Suite;

/**
* Suite map.
*/

var map = {};

/**
* Create a new `Suite` with the given `title`
* and parent `Suite`. When a suite with the
* same title is already present, that suite
* is returned to provide nicer reporter
* and more flexible meta-testing.
*
* @param {Suite} parent
* @param {String} title
* @return {Suite}
* @api public
*/

exports.create = function(parent, title){
var suite = new Suite(title);
suite.parent = parent;
title = suite.fullTitle();
if (map[title]) return map[title];
parent.addSuite(suite);
return map[title] = suite;
};

/**
* Initialize a new `Suite` with the given `title`.
Expand Down Expand Up @@ -57,6 +85,7 @@ Suite.prototype.timeout = function(ms){

Suite.prototype.beforeAll = function(fn){
this.beforeAllCallbacks.push(fn);
this.emit('beforeAll', fn);
return this;
};

Expand All @@ -70,6 +99,7 @@ Suite.prototype.beforeAll = function(fn){

Suite.prototype.afterAll = function(fn){
this.afterAllCallbacks.push(fn);
this.emit('afterAll', fn);
return this;
};

Expand All @@ -83,6 +113,7 @@ Suite.prototype.afterAll = function(fn){

Suite.prototype.beforeEach = function(fn){
this.beforeEachCallbacks.push(fn);
this.emit('beforeEach', fn);
return this;
};

Expand All @@ -96,6 +127,7 @@ Suite.prototype.beforeEach = function(fn){

Suite.prototype.afterEach = function(fn){
this.afterEachCallbacks.push(fn);
this.emit('afterEach', fn);
return this;
};

Expand All @@ -111,6 +143,7 @@ Suite.prototype.addSuite = function(suite){
suite.parent = this;
if (this._timeout) suite.timeout(this._timeout);
this.suites.push(suite);
this.emit('suite', suite);
return this;
};

Expand All @@ -126,6 +159,7 @@ Suite.prototype.addTest = function(test){
test.parent = this;
if (this._timeout) test.timeout(this._timeout);
this.tests.push(test);
this.emit('test', test);
return this;
};

Expand Down
34 changes: 34 additions & 0 deletions test/merge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

describe('merge', function(){
describe('stuff', function(){
describe('one', function(){
it('should do something', function(){

})
})

describe('two', function(){
it('should do stuff', function(){

})
})
})
})

describe('merge', function(){
describe('stuff', function(){
describe('three', function(){
it('should do something', function(){

})
})
})
})

describe('merge stuff', function(){
describe('four', function(){
it('should do something', function(){

})
})
})

0 comments on commit e474461

Please sign in to comment.