Permalink
Browse files

The 'suite' and 'suite end' events are now emitted lazily. #350

  • Loading branch information...
1 parent 6dfd490 commit 6b5b687a2c486ef77025e8aecdf8df5f1b2db989 Stepan Riha committed Apr 1, 2012
Showing with 17 additions and 4 deletions.
  1. +9 −2 lib/runner.js
  2. +8 −2 lib/suite.js
View
@@ -350,7 +350,14 @@ Runner.prototype.runSuite = function(suite, fn){
, i = 0;
debug('run suite %s', suite.fullTitle());
- this.emit('suite', this.suite = suite);
+
+ suite.beforeAll(function() {
+ self.emit('suite', suite);
+ }, true);
+
+ suite.afterAll(function() {
+ self.emit('suite end', suite);
+ })
function next() {
var curr = suite.suites[i++];
@@ -361,11 +368,11 @@ Runner.prototype.runSuite = function(suite, fn){
function done() {
self.suite = suite;
self.hook('afterAll', function(){
- self.emit('suite end', suite);
fn();
});
}
+ self.suite = suite;
self.runTests(suite, next);
};
View
@@ -113,20 +113,26 @@ Suite.prototype.bail = function(bail){
/**
* Run `fn(test[, done])` before running a test, but not more than once.
+ * If `first=true`, then the fn is put at the beginning of the callback queue.
*
* @param {Function} fn
+ * @param {Boolean} first
* @return {Suite} for chaining
* @api private
*/
-Suite.prototype.beforeAll = function(fn){
+Suite.prototype.beforeAll = function(fn, first){
// Execute `fn` callback at most once
var hook = new Hook('"before all" hook', runOnce(fn));
hook.parent = this;
hook.timeout(this.timeout());
hook.ctx = this.ctx;
- this._beforeAll.push(hook);
+ if(first) {
+ this._beforeAll.unshift(hook);
+ } else {
+ this._beforeAll.push(hook);
+ }
this.emit('beforeAll', hook);
return this;
};

0 comments on commit 6b5b687

Please sign in to comment.