@@ -26,6 +26,7 @@ function Test(title, fn) {
2626this . assertCount = 0 ;
2727this . planCount = null ;
2828this . duration = null ;
29+ this . assertError = undefined ;
2930
3031// test type, can be: test, hook, eachHook
3132this . type = 'test' ;
@@ -67,20 +68,32 @@ Object.keys(assert).forEach(function (el) {
6768if ( isPromise ( fn ) ) {
6869return Promise . resolve ( fn )
6970. catch ( function ( err ) {
70- self . assertError = err ;
71+ self . _setAssertError ( err ) ;
7172} )
7273. finally ( function ( ) {
7374self . _assert ( ) ;
7475} ) ;
7576}
7677} catch ( err ) {
77- this . assertError = err ;
78+ this . _setAssertError ( err ) ;
7879}
7980
8081this . _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 () {
118131try {
119132ret = this . fn ( this ) ;
120133} catch ( err ) {
121- this . assertError = err ;
134+ this . _setAssertError ( err ) ;
122135this . 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 ( {
136149actual : err ,
137150message : 'Promise rejected → ' + err ,
138151operator : 'promise'
139- } ) ;
152+ } ) ) ;
140153
141154self . exit ( ) ;
142155} ) ;
@@ -147,11 +160,11 @@ Test.prototype.run = function () {
147160
148161Test . prototype . end = function ( err ) {
149162if ( err ) {
150- this . assertError = new assert . AssertionError ( {
163+ this . _setAssertError ( new assert . AssertionError ( {
151164actual : err ,
152165message : 'Callback called with an error → ' + err ,
153166operator : 'callback'
154- } ) ;
167+ } ) ) ;
155168
156169this . exit ( ) ;
157170return ;
@@ -174,13 +187,13 @@ Test.prototype.exit = function () {
174187// stop infinite timer
175188clearTimeout ( 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 ( {
179192actual : this . assertCount ,
180193expected : this . planCount ,
181194message : 'Assertion count does not match planned' ,
182195operator : 'plan'
183- } ) ;
196+ } ) ) ;
184197
185198this . assertError . stack = this . planStack ;
186199}
@@ -189,7 +202,7 @@ Test.prototype.exit = function () {
189202this . ended = true ;
190203
191204setImmediate ( function ( ) {
192- if ( self . assertError ) {
205+ if ( self . assertError !== undefined ) {
193206self . promise . reject ( self . assertError ) ;
194207return ;
195208}
0 commit comments