Skip to content

Commit

Permalink
plugging in Hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 25, 2011
1 parent 27dcead commit c0bb918
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Module dependencies.
*/

var EventEmitter = require('events').EventEmitter;
var EventEmitter = require('events').EventEmitter
, Hook = require('./hook');

/**
* Expose `Suite`.
Expand Down Expand Up @@ -50,10 +51,10 @@ function Suite(title) {
this.title = title;
this.suites = [];
this.tests = [];
this.beforeAllCallbacks = [];
this.beforeEachCallbacks = [];
this.afterAllCallbacks = [];
this.afterEachCallbacks = [];
this._beforeEach = [];
this._beforeAll = [];
this._afterEach = [];
this._afterAll = [];
this.root = !title;
this.timeout(2000);
}
Expand Down Expand Up @@ -87,8 +88,10 @@ Suite.prototype.timeout = function(ms){
*/

Suite.prototype.beforeAll = function(fn){
this.beforeAllCallbacks.push(fn);
this.emit('beforeAll', fn);
var hook = new Hook('before all', fn);
hook.parent = this;
this._beforeAll.push(fn);
this.emit('beforeAll', hook);
return this;
};

Expand All @@ -101,8 +104,10 @@ Suite.prototype.beforeAll = function(fn){
*/

Suite.prototype.afterAll = function(fn){
this.afterAllCallbacks.push(fn);
this.emit('afterAll', fn);
var hook = new Hook('after all', fn);
hook.parent = this;
this._afterAll.push(hook);
this.emit('afterAll', hook);
return this;
};

Expand All @@ -115,8 +120,10 @@ Suite.prototype.afterAll = function(fn){
*/

Suite.prototype.beforeEach = function(fn){
this.beforeEachCallbacks.push(fn);
this.emit('beforeEach', fn);
var hook = new Hook('before each', fn);
hook.parent = this;
this._beforeEach.push(hook);
this.emit('beforeEach', hook);
return this;
};

Expand All @@ -129,8 +136,10 @@ Suite.prototype.beforeEach = function(fn){
*/

Suite.prototype.afterEach = function(fn){
this.afterEachCallbacks.push(fn);
this.emit('afterEach', fn);
var hook = new Hook('after each', fn);
hook.parent = this;
this._afterEach.push(hook);
this.emit('afterEach', hook);
return this;
};

Expand Down

0 comments on commit c0bb918

Please sign in to comment.