@@ -130,8 +130,8 @@ TestSuite.prototype.initAfterEachHook = function() {
130
130
asyncArgsCount = 2 ;
131
131
}
132
132
asyncFn = Utils . makeFnAsync ( asyncArgsCount , hookFn , module ) ;
133
- return self . makePromise ( function ( done ) {
134
- var doneFn = self . adaptDoneCallback ( done , 'afterEach' ) ;
133
+ return self . makePromise ( function ( done , deferred ) {
134
+ var doneFn = self . adaptDoneCallback ( done , 'afterEach' , deferred ) ;
135
135
if ( expectedArgs < 2 ) {
136
136
// user has only supplied the done callback argument (pre v0.6 behaviour), e.g.:
137
137
// afterEach : function(done) { ... }
@@ -298,8 +298,8 @@ TestSuite.prototype.globalAfterEach = function() {
298
298
} ;
299
299
300
300
TestSuite . prototype . adaptGlobalHook = function ( hookName ) {
301
- return this . makePromise ( function ( done ) {
302
- var doneFn = this . adaptDoneCallback ( done , 'global ' + hookName ) ;
301
+ return this . makePromise ( function ( done , deffered ) {
302
+ var doneFn = this . adaptDoneCallback ( done , 'global ' + hookName , deffered ) ;
303
303
var argsCount , expectedCount = 1 ;
304
304
if ( Utils . checkFunction ( hookName , this . options . globals ) ) {
305
305
argsCount = this . options . globals [ hookName ] . length ;
@@ -318,10 +318,14 @@ TestSuite.prototype.adaptGlobalHook = function(hookName) {
318
318
} ) ;
319
319
} ;
320
320
321
- TestSuite . prototype . adaptDoneCallback = function ( done , hookName ) {
321
+ TestSuite . prototype . adaptDoneCallback = function ( done , hookName , deferred ) {
322
322
var timeout = setTimeout ( function ( ) {
323
- throw new Error ( 'done() callback timeout was reached while executing ' + hookName + '.' +
324
- ' Make sure to call the done() callback when the operation finishes.' ) ;
323
+ try {
324
+ throw new Error ( 'done() callback timeout was reached while executing ' + hookName + '.' +
325
+ ' Make sure to call the done() callback when the operation finishes.' ) ;
326
+ } catch ( err ) {
327
+ deferred . reject ( err ) ;
328
+ }
325
329
} , ASYNC_HOOK_TIMEOUT ) ;
326
330
327
331
return function ( ) {
@@ -338,7 +342,7 @@ TestSuite.prototype.makePromise = function (fn) {
338
342
try {
339
343
fn . call ( this , function ( ) {
340
344
deferred . resolve ( ) ;
341
- } ) ;
345
+ } , deferred ) ;
342
346
} catch ( e ) {
343
347
deferred . reject ( e ) ;
344
348
}
0 commit comments