☕️ Classic, reliable, trusted test framework for Node.js and the browser
plugging in Hook
Tj Holowaychukc0bb91886fd9
diff --git a/lib/suite.js b/lib/suite.jsindex 0530fae5..f0472e9f 100644--- a/lib/suite.js+++ b/lib/suite.js@@ -3,7 +3,8 @@* Module dependencies.*/-var EventEmitter = require('events').EventEmitter;+var EventEmitter = require('events').EventEmitter+ , Hook = require('./hook');/*** Expose `Suite`.@@ -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);}@@ -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;};@@ -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;};@@ -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;};@@ -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;};