☕️ Classic, reliable, trusted test framework for Node.js and the browser
refactored internals
Tj Holowaychuk916b3649a073
diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.jsindex 11135a0e..d4a29417 100644--- a/lib/interfaces/bdd.js+++ b/lib/interfaces/bdd.js@@ -33,7 +33,7 @@ module.exports = function(suite){*/context.beforeEach = function(fn){- suites[0].addSetup(fn);+ suites[0].beforeEach(fn);};/**@@ -41,7 +41,7 @@ module.exports = function(suite){*/context.afterEach = function(fn){- suites[0].addTearDown(fn);+ suites[0].afterEach(fn);};/**diff --git a/lib/interfaces/tdd.js b/lib/interfaces/tdd.jsindex 73d6da49..99de6f2c 100644--- a/lib/interfaces/tdd.js+++ b/lib/interfaces/tdd.js@@ -33,7 +33,7 @@ module.exports = function(suite){*/context.setup = function(fn){- suites[0].addSetup(fn);+ suites[0].beforeEach(fn);};/**@@ -41,7 +41,7 @@ module.exports = function(suite){*/context.tearDown = function(fn){- suites[0].addTearDown(fn);+ suites[0].afterEach(fn);};/**diff --git a/lib/runner.js b/lib/runner.jsindex 4cdc08aa..684f9f70 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -63,7 +63,7 @@ Runner.prototype.runTests = function(suite, fn){if (!test) return fn();self.emit('test', test);// run any befores first- suite.setup.forEach(function(fn){+ suite.beforeEachCallbacks.forEach(function(fn){fn(test);});// run the test@@ -95,7 +95,7 @@ Runner.prototype.runTests = function(suite, fn){if (test.sync) {self.emit('test end', test);// teardown hook- suite.tearDown.forEach(function(fn){+ suite.afterEachCallbacks.forEach(function(fn){fn(test);});run(tests.shift());diff --git a/lib/suite.js b/lib/suite.jsindex af2e611f..6e29c018 100644--- a/lib/suite.js+++ b/lib/suite.js@@ -22,8 +22,8 @@ function Suite(title) {this.title = title;this.suites = [];this.tests = [];- this.setup = [];- this.tearDown = [];+ this.beforeEachCallbacks = [];+ this.afterEachCallbacks = [];}/**@@ -33,27 +33,27 @@ function Suite(title) {Suite.prototype.__proto__ = EventEmitter.prototype;/**- * Add a test `setup`.+ * Run `fn(test[, done])` before each test case.** @param {Function} fn* @return {Suite} for chaining* @api private*/-Suite.prototype.addSetup = function(setup){- this.setup.push(setup);+Suite.prototype.beforeEach = function(fn){+ this.beforeEachCallbacks.push(fn);return this;}/**- * Add a test `tearDown`.+ * Run `fn(test[, done])` after each test case.** @param {Function} fn* @return {Suite} for chaining* @api private*/-Suite.prototype.addTearDown = function(tearDown){- this.tearDown.push(tearDown);+Suite.prototype.afterEach = function(fn){+ this.afterEachCallbacks.push(fn);return this;}