File tree 3 files changed +31
-5
lines changed
3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -233,9 +233,13 @@ Runner.prototype.fail = function (test, err) {
233
233
err = new Error ( 'the ' + type ( err ) + ' ' + stringify ( err ) + ' was thrown, throw an Error :)' ) ;
234
234
}
235
235
236
- err . stack = ( this . fullStackTrace || ! err . stack )
237
- ? err . stack
238
- : stackFilter ( err . stack ) ;
236
+ try {
237
+ err . stack = ( this . fullStackTrace || ! err . stack )
238
+ ? err . stack
239
+ : stackFilter ( err . stack ) ;
240
+ } catch ( ignored ) {
241
+ // some environments do not take kindly to monkeying with the stack
242
+ }
239
243
240
244
this . emit ( 'fail' , test , err ) ;
241
245
} ;
@@ -819,11 +823,13 @@ Runner.prototype.run = function (fn) {
819
823
this . on ( 'end' , function ( ) {
820
824
debug ( 'end' ) ;
821
825
process . removeListener ( 'uncaughtException' , uncaught ) ;
826
+ process . removeListener ( 'unhandledRejection' , uncaught ) ;
822
827
fn ( self . failures ) ;
823
828
} ) ;
824
829
825
830
// uncaught exception
826
831
process . on ( 'uncaughtException' , uncaught ) ;
832
+ // process.on('unhandledRejection', uncaught);
827
833
828
834
if ( this . _delay ) {
829
835
// for reporters, I guess.
Original file line number Diff line number Diff line change @@ -794,3 +794,9 @@ exports.stackTraceFilter = function () {
794
794
exports . isPromise = function isPromise ( value ) {
795
795
return typeof value === 'object' && typeof value . then === 'function' ;
796
796
} ;
797
+
798
+ /**
799
+ * It's a noop.
800
+ * @api
801
+ */
802
+ exports . noop = function ( ) { } ;
Original file line number Diff line number Diff line change @@ -6,8 +6,7 @@ var Runner = mocha.Runner;
6
6
var Test = mocha . Test ;
7
7
var Hook = mocha . Hook ;
8
8
var path = require ( 'path' ) ;
9
-
10
- function noop ( ) { }
9
+ var noop = mocha . utils . noop ;
11
10
12
11
describe ( 'Runner' , function ( ) {
13
12
var suite ;
@@ -291,6 +290,21 @@ describe('Runner', function () {
291
290
} ) ;
292
291
runner . fail ( test , err ) ;
293
292
} ) ;
293
+
294
+ it ( 'should recover if the error stack is not writable' , function ( done ) {
295
+ var err = new Error ( 'not evil' ) ;
296
+ Object . defineProperty ( err , 'stack' , {
297
+ value : err . stack
298
+ } ) ;
299
+ var test = new Test ( 'a test' , noop ) ;
300
+
301
+ runner . on ( 'fail' , function ( test , err ) {
302
+ err . message . should . equal ( 'not evil' ) ;
303
+ done ( ) ;
304
+ } ) ;
305
+
306
+ runner . fail ( test , err ) ;
307
+ } ) ;
294
308
} ) ;
295
309
296
310
describe ( '.failHook(hook, err)' , function ( ) {
You can’t perform that action at this time.
0 commit comments