@@ -26,6 +26,7 @@ function Test(title, fn) {
2626 this . assertCount = 0 ;
2727 this . planCount = null ;
2828 this . duration = null ;
29+ this . assertError = undefined ;
2930
3031 // test type, can be: test, hook, eachHook
3132 this . type = 'test' ;
@@ -67,20 +68,32 @@ Object.keys(assert).forEach(function (el) {
6768 if ( isPromise ( fn ) ) {
6869 return Promise . resolve ( fn )
6970 . catch ( function ( err ) {
70- self . assertError = err ;
71+ self . _setAssertError ( err ) ;
7172 } )
7273 . finally ( function ( ) {
7374 self . _assert ( ) ;
7475 } ) ;
7576 }
7677 } catch ( err ) {
77- this . assertError = err ;
78+ this . _setAssertError ( err ) ;
7879 }
7980
8081 this . _assert ( ) ;
8182 } ;
8283} ) ;
8384
85+ Test . prototype . _setAssertError = function ( err ) {
86+ if ( this . assertError !== undefined ) {
87+ return ;
88+ }
89+
90+ if ( err === undefined ) {
91+ err = 'undefined' ;
92+ }
93+
94+ this . assertError = err ;
95+ } ;
96+
8497// Workaround for power-assert
8598// `t` must be capturable for decorated assert output
8699Test . prototype . _capt = assert . _capt ;
@@ -118,7 +131,7 @@ Test.prototype.run = function () {
118131 try {
119132 ret = this . fn ( this ) ;
120133 } catch ( err ) {
121- this . assertError = err ;
134+ this . _setAssertError ( err ) ;
122135 this . exit ( ) ;
123136 }
124137
@@ -132,11 +145,11 @@ Test.prototype.run = function () {
132145 }
133146 } )
134147 . catch ( function ( err ) {
135- self . assertError = new assert . AssertionError ( {
148+ self . _setAssertError ( new assert . AssertionError ( {
136149 actual : err ,
137150 message : 'Promise rejected → ' + err ,
138151 operator : 'promise'
139- } ) ;
152+ } ) ) ;
140153
141154 self . exit ( ) ;
142155 } ) ;
@@ -147,11 +160,11 @@ Test.prototype.run = function () {
147160
148161Test . prototype . end = function ( err ) {
149162 if ( err ) {
150- this . assertError = new assert . AssertionError ( {
163+ this . _setAssertError ( new assert . AssertionError ( {
151164 actual : err ,
152165 message : 'Callback called with an error → ' + err ,
153166 operator : 'callback'
154- } ) ;
167+ } ) ) ;
155168
156169 this . exit ( ) ;
157170 return ;
@@ -174,13 +187,13 @@ Test.prototype.exit = function () {
174187 // stop infinite timer
175188 clearTimeout ( this . _timeout ) ;
176189
177- if ( ! this . assertError && this . planCount !== null && this . planCount !== this . assertCount ) {
178- this . assertError = new assert . AssertionError ( {
190+ if ( this . assertError === undefined && this . planCount !== null && this . planCount !== this . assertCount ) {
191+ this . _setAssertError ( new assert . AssertionError ( {
179192 actual : this . assertCount ,
180193 expected : this . planCount ,
181194 message : 'Assertion count does not match planned' ,
182195 operator : 'plan'
183- } ) ;
196+ } ) ) ;
184197
185198 this . assertError . stack = this . planStack ;
186199 }
@@ -189,7 +202,7 @@ Test.prototype.exit = function () {
189202 this . ended = true ;
190203
191204 setImmediate ( function ( ) {
192- if ( self . assertError ) {
205+ if ( self . assertError !== undefined ) {
193206 self . promise . reject ( self . assertError ) ;
194207 return ;
195208 }
0 commit comments