You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/parallel/test-promises-unhandled-rejections.js
+92-36Lines changed: 92 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,3 @@
1
-
/* eslint-disable max-len */
2
1
'use strict';
3
2
varcommon=require('../common');
4
3
varassert=require('assert');
@@ -107,15 +106,17 @@ function onUnhandledFail(done) {
107
106
},10);
108
107
}
109
108
110
-
asyncTest('synchronously rejected promise should trigger unhandledRejection',function(done){
109
+
asyncTest('synchronously rejected promise should trigger'+
110
+
' unhandledRejection',function(done){
111
111
vare=newError();
112
112
onUnhandledSucceed(done,function(reason,promise){
113
113
assert.strictEqual(e,reason);
114
114
});
115
115
Promise.reject(e);
116
116
});
117
117
118
-
asyncTest('synchronously rejected promise should trigger unhandledRejection',function(done){
118
+
asyncTest('synchronously rejected promise should trigger'+
119
+
' unhandledRejection',function(done){
119
120
vare=newError();
120
121
onUnhandledSucceed(done,function(reason,promise){
121
122
assert.strictEqual(e,reason);
@@ -125,7 +126,8 @@ asyncTest('synchronously rejected promise should trigger unhandledRejection', fu
125
126
});
126
127
});
127
128
128
-
asyncTest('Promise rejected after setImmediate should trigger unhandledRejection',function(done){
129
+
asyncTest('Promise rejected after setImmediate should trigger'+
130
+
' unhandledRejection',function(done){
129
131
vare=newError();
130
132
onUnhandledSucceed(done,function(reason,promise){
131
133
assert.strictEqual(e,reason);
@@ -137,7 +139,8 @@ asyncTest('Promise rejected after setImmediate should trigger unhandledRejection
137
139
});
138
140
});
139
141
140
-
asyncTest('Promise rejected after setTimeout(,1) should trigger unhandled rejection',function(done){
142
+
asyncTest('Promise rejected after setTimeout(,1) should trigger'+
143
+
' unhandled rejection',function(done){
141
144
vare=newError();
142
145
onUnhandledSucceed(done,function(reason,promise){
143
146
assert.strictEqual(e,reason);
@@ -149,7 +152,8 @@ asyncTest('Promise rejected after setTimeout(,1) should trigger unhandled reject
149
152
});
150
153
});
151
154
152
-
asyncTest('Catching a promise rejection after setImmediate is not soon enough to stop unhandledRejection',function(done){
155
+
asyncTest('Catching a promise rejection after setImmediate is not'+
156
+
' soon enough to stop unhandledRejection',function(done){
153
157
vare=newError();
154
158
onUnhandledSucceed(done,function(reason,promise){
155
159
assert.strictEqual(e,reason);
@@ -164,7 +168,8 @@ asyncTest('Catching a promise rejection after setImmediate is not soon enough to
164
168
});
165
169
});
166
170
167
-
asyncTest('When re-throwing new errors in a promise catch, only the re-thrown error should hit unhandledRejection',function(done){
171
+
asyncTest('When re-throwing new errors in a promise catch, only the'+
172
+
' re-thrown error should hit unhandledRejection',function(done){
168
173
vare=newError();
169
174
vare2=newError();
170
175
onUnhandledSucceed(done,function(reason,promise){
@@ -177,7 +182,8 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown er
177
182
});
178
183
});
179
184
180
-
asyncTest('Test params of unhandledRejection for a synchronously-rejected promise',function(done){
185
+
asyncTest('Test params of unhandledRejection for a synchronously-rejected'+
186
+
'promise',function(done){
181
187
vare=newError();
182
188
vare2=newError();
183
189
onUnhandledSucceed(done,function(reason,promise){
@@ -187,7 +193,9 @@ asyncTest('Test params of unhandledRejection for a synchronously-rejected promis
187
193
varpromise=Promise.reject(e);
188
194
});
189
195
190
-
asyncTest('When re-throwing new errors in a promise catch, only the re-thrown error should hit unhandledRejection: original promise rejected async with setTimeout(,1)',function(done){
196
+
asyncTest('When re-throwing new errors in a promise catch, only the '+
197
+
're-thrown error should hit unhandledRejection: original promise'+
198
+
' rejected async with setTimeout(,1)',function(done){
191
199
vare=newError();
192
200
vare2=newError();
193
201
onUnhandledSucceed(done,function(reason,promise){
@@ -204,7 +212,9 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown er
204
212
});
205
213
});
206
214
207
-
asyncTest('When re-throwing new errors in a promise catch, only the re-thrown error should hit unhandledRejection: promise catch attached a process.nextTick after rejection',function(done){
215
+
asyncTest('When re-throwing new errors in a promise catch, only the re-thrown'+
216
+
' error should hit unhandledRejection: promise catch attached a'+
217
+
' process.nextTick after rejection',function(done){
208
218
vare=newError();
209
219
vare2=newError();
210
220
onUnhandledSucceed(done,function(reason,promise){
@@ -225,21 +235,26 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown er
225
235
varpromise2;
226
236
});
227
237
228
-
asyncTest('unhandledRejection should not be triggered if a promise catch is attached synchronously upon the promise\'s creation',function(done){
238
+
asyncTest('unhandledRejection should not be triggered if a promise catch is'+
239
+
' attached synchronously upon the promise\'s creation',
240
+
function(done){
229
241
vare=newError();
230
242
onUnhandledFail(done);
231
243
Promise.reject(e).then(assert.fail,function(){});
232
244
});
233
245
234
-
asyncTest('unhandledRejection should not be triggered if a promise catch is attached synchronously upon the promise\'s creation',function(done){
246
+
asyncTest('unhandledRejection should not be triggered if a promise catch is'+
247
+
' attached synchronously upon the promise\'s creation',
248
+
function(done){
235
249
vare=newError();
236
250
onUnhandledFail(done);
237
251
newPromise(function(_,reject){
238
252
reject(e);
239
253
}).then(assert.fail,function(){});
240
254
});
241
255
242
-
asyncTest('Attaching a promise catch in a process.nextTick is soon enough to prevent unhandledRejection',function(done){
256
+
asyncTest('Attaching a promise catch in a process.nextTick is soon enough to'+
257
+
' prevent unhandledRejection',function(done){
243
258
vare=newError();
244
259
onUnhandledFail(done);
245
260
varpromise=Promise.reject(e);
@@ -248,7 +263,8 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to pre
248
263
});
249
264
});
250
265
251
-
asyncTest('Attaching a promise catch in a process.nextTick is soon enough to prevent unhandledRejection',function(done){
266
+
asyncTest('Attaching a promise catch in a process.nextTick is soon enough to'+
267
+
' prevent unhandledRejection',function(done){
252
268
vare=newError();
253
269
onUnhandledFail(done);
254
270
varpromise=newPromise(function(_,reject){
@@ -260,7 +276,9 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to pre
260
276
});
261
277
262
278
// State adapation tests
263
-
asyncTest('catching a promise which is asynchronously rejected (via resolution to an asynchronously-rejected promise) prevents unhandledRejection',function(done){
279
+
asyncTest('catching a promise which is asynchronously rejected (via'+
280
+
'resolution to an asynchronously-rejected promise) prevents'+
281
+
' unhandledRejection',function(done){
264
282
vare=newError();
265
283
onUnhandledFail(done);
266
284
Promise.resolve().then(function(){
@@ -274,7 +292,8 @@ asyncTest('catching a promise which is asynchronously rejected (via resolution t
274
292
});
275
293
});
276
294
277
-
asyncTest('Catching a rejected promise derived from throwing in a fulfillment handler prevents unhandledRejection',function(done){
295
+
asyncTest('Catching a rejected promise derived from throwing in a'+
@@ -284,7 +303,9 @@ asyncTest('Catching a rejected promise derived from throwing in a fulfillment ha
284
303
});
285
304
});
286
305
287
-
asyncTest('Catching a rejected promise derived from returning a synchronously-rejected promise in a fulfillment handler prevents unhandledRejection',function(done){
306
+
asyncTest('Catching a rejected promise derived from returning a'+
307
+
' synchronously-rejected promise in a fulfillment handler'+
308
+
' prevents unhandledRejection',function(done){
288
309
vare=newError();
289
310
onUnhandledFail(done);
290
311
Promise.resolve().then(function(){
@@ -294,7 +315,9 @@ asyncTest('Catching a rejected promise derived from returning a synchronously-re
294
315
});
295
316
});
296
317
297
-
asyncTest('A rejected promise derived from returning an asynchronously-rejected promise in a fulfillment handler does trigger unhandledRejection',function(done){
318
+
asyncTest('A rejected promise derived from returning an'+
319
+
' asynchronously-rejected promise in a fulfillment handler'+
320
+
' does trigger unhandledRejection',function(done){
298
321
vare=newError();
299
322
var_promise;
300
323
onUnhandledSucceed(done,function(reason,promise){
@@ -310,7 +333,8 @@ asyncTest('A rejected promise derived from returning an asynchronously-rejected
310
333
});
311
334
});
312
335
313
-
asyncTest('A rejected promise derived from throwing in a fulfillment handler does trigger unhandledRejection',function(done){
336
+
asyncTest('A rejected promise derived from throwing in a fulfillment handler'+
337
+
' does trigger unhandledRejection',function(done){
314
338
vare=newError();
315
339
var_promise;
316
340
onUnhandledSucceed(done,function(reason,promise){
@@ -322,7 +346,9 @@ asyncTest('A rejected promise derived from throwing in a fulfillment handler doe
322
346
});
323
347
});
324
348
325
-
asyncTest('A rejected promise derived from returning a synchronously-rejected promise in a fulfillment handler does trigger unhandledRejection',function(done){
349
+
asyncTest('A rejected promise derived from returning a synchronously-rejected'+
350
+
' promise in a fulfillment handler does trigger unhandledRejection',
351
+
function(done){
326
352
vare=newError();
327
353
var_promise;
328
354
onUnhandledSucceed(done,function(reason,promise){
@@ -335,13 +361,16 @@ asyncTest('A rejected promise derived from returning a synchronously-rejected pr
335
361
});
336
362
337
363
// Combinations with Promise.all
338
-
asyncTest('Catching the Promise.all() of a collection that includes a rejected promise prevents unhandledRejection',function(done){
364
+
asyncTest('Catching the Promise.all() of a collection that includes a'+
@@ -355,7 +384,9 @@ asyncTest('Catching the Promise.all() of a collection that includes a nextTick-a
355
384
});
356
385
});
357
386
358
-
asyncTest('Failing to catch the Promise.all() of a collection that includes a rejected promise triggers unhandledRejection for the returned promise, not the passed promise',function(done){
387
+
asyncTest('Failing to catch the Promise.all() of a collection that includes'+
388
+
' a rejected promise triggers unhandledRejection for the returned'+
389
+
' promise, not the passed promise',function(done){
359
390
vare=newError();
360
391
onUnhandledSucceed(done,function(reason,promise){
361
392
assert.strictEqual(e,reason);
@@ -364,7 +395,8 @@ asyncTest('Failing to catch the Promise.all() of a collection that includes a re
364
395
varp=Promise.all([Promise.reject(e)]);
365
396
});
366
397
367
-
asyncTest('Waiting setTimeout(, 10) to catch a promise causes an unhandledRejection + rejectionHandled pair',function(done){
398
+
asyncTest('Waiting setTimeout(, 10) to catch a promise causes an'+
@@ -389,7 +421,9 @@ asyncTest('Waiting setTimeout(, 10) to catch a promise causes an unhandledReject
389
421
},10);
390
422
});
391
423
392
-
asyncTest('Waiting for some combination of process.nextTick + promise microtasks to attach a catch handler is still soon enough to prevent unhandledRejection',function(done){
424
+
asyncTest('Waiting for some combination of process.nextTick + promise'+
425
+
' microtasks to attach a catch handler is still soon enough to'+
426
+
' prevent unhandledRejection',function(done){
393
427
vare=newError();
394
428
onUnhandledFail(done);
395
429
@@ -406,7 +440,9 @@ asyncTest('Waiting for some combination of process.nextTick + promise microtasks
406
440
});
407
441
});
408
442
409
-
asyncTest('Waiting for some combination of process.nextTick + promise microtasks to attach a catch handler is still soon enough to prevent unhandledRejection: inside setImmediate',function(done){
443
+
asyncTest('Waiting for some combination of process.nextTick + promise'+
444
+
' microtasks to attach a catch handler is still soon enough to '+
@@ -424,7 +460,9 @@ asyncTest('Waiting for some combination of process.nextTick + promise microtasks
424
460
});
425
461
});
426
462
427
-
asyncTest('Waiting for some combination of process.nextTick + promise microtasks to attach a catch handler is still soon enough to prevent unhandledRejection: inside setTimeout',function(done){
463
+
asyncTest('Waiting for some combination of process.nextTick + promise '+
464
+
'microtasks to attach a catch handler is still soon enough to '+
@@ -442,7 +480,9 @@ asyncTest('Waiting for some combination of process.nextTick + promise microtasks
442
480
},0);
443
481
});
444
482
445
-
asyncTest('Waiting for some combination of promise microtasks + process.nextTick to attach a catch handler is still soon enough to prevent unhandledRejection',function(done){
483
+
asyncTest('Waiting for some combination of promise microtasks + '+
484
+
'process.nextTick to attach a catch handler is still soon enough'+
485
+
' to prevent unhandledRejection',function(done){
446
486
vare=newError();
447
487
onUnhandledFail(done);
448
488
@@ -459,7 +499,10 @@ asyncTest('Waiting for some combination of promise microtasks + process.nextTick
459
499
});
460
500
});
461
501
462
-
asyncTest('Waiting for some combination of promise microtasks + process.nextTick to attach a catch handler is still soon enough to prevent unhandledRejection: inside setImmediate',function(done){
502
+
asyncTest('Waiting for some combination of promise microtasks +'+
503
+
' process.nextTick to attach a catch handler is still soon enough'+
504
+
' to prevent unhandledRejection: inside setImmediate',
505
+
function(done){
463
506
vare=newError();
464
507
onUnhandledFail(done);
465
508
@@ -477,7 +520,9 @@ asyncTest('Waiting for some combination of promise microtasks + process.nextTick
477
520
});
478
521
});
479
522
480
-
asyncTest('Waiting for some combination of promise microtasks + process.nextTick to attach a catch handler is still soon enough to prevent unhandledRejection: inside setTimeout',function(done){
523
+
asyncTest('Waiting for some combination of promise microtasks +'+
524
+
' process.nextTick to attach a catch handler is still soon enough'+
525
+
' to prevent unhandledRejection: inside setTimeout',function(done){
481
526
vare=newError();
482
527
onUnhandledFail(done);
483
528
@@ -495,7 +540,9 @@ asyncTest('Waiting for some combination of promise microtasks + process.nextTick
495
540
},0);
496
541
});
497
542
498
-
asyncTest('setImmediate + promise microtasks is too late to attach a catch handler; unhandledRejection will be triggered in that case. (setImmediate before promise creation/rejection)',function(done){
543
+
asyncTest('setImmediate + promise microtasks is too late to attach a catch'+
544
+
' handler; unhandledRejection will be triggered in that case.'+
545
+
' (setImmediate before promise creation/rejection)',function(done){
499
546
vare=newError();
500
547
onUnhandledSucceed(done,function(reason,promise){
501
548
assert.strictEqual(e,reason);
@@ -509,7 +556,9 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch handl
509
556
});
510
557
});
511
558
512
-
asyncTest('setImmediate + promise microtasks is too late to attach a catch handler; unhandledRejection will be triggered in that case (setImmediate before promise creation/rejection)',function(done){
559
+
asyncTest('setImmediate + promise microtasks is too late to attach a catch'+
560
+
' handler; unhandledRejection will be triggered in that case'+
561
+
' (setImmediate before promise creation/rejection)',function(done){
513
562
onUnhandledSucceed(done,function(reason,promise){
514
563
assert.strictEqual(undefined,reason);
515
564
assert.strictEqual(p,promise);
@@ -528,7 +577,9 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch handl
528
577
varp=Promise.reject();
529
578
});
530
579
531
-
asyncTest('setImmediate + promise microtasks is too late to attach a catch handler; unhandledRejection will be triggered in that case (setImmediate after promise creation/rejection)',function(done){
580
+
asyncTest('setImmediate + promise microtasks is too late to attach a catch'+
581
+
' handler; unhandledRejection will be triggered in that case'+
582
+
' (setImmediate after promise creation/rejection)',function(done){
532
583
onUnhandledSucceed(done,function(reason,promise){
533
584
assert.strictEqual(undefined,reason);
534
585
assert.strictEqual(p,promise);
@@ -547,7 +598,9 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch handl
547
598
});
548
599
});
549
600
550
-
asyncTest('Promise unhandledRejection handler does not interfere with domain error handlers being given exceptions thrown from nextTick.',function(done){
601
+
asyncTest('Promise unhandledRejection handler does not interfere with domain'+
602
+
' error handlers being given exceptions thrown from nextTick.',
603
+
function(done){
551
604
vard=domain.create();
552
605
vardomainReceivedError;
553
606
d.on('error',function(e){
@@ -568,7 +621,8 @@ asyncTest('Promise unhandledRejection handler does not interfere with domain err
568
621
});
569
622
});
570
623
571
-
asyncTest('nextTick is immediately scheduled when called inside an event handler',function(done){
624
+
asyncTest('nextTick is immediately scheduled when called inside an event'+
@@ -585,7 +639,9 @@ asyncTest('nextTick is immediately scheduled when called inside an event handler
585
639
Promise.reject(e);
586
640
});
587
641
588
-
asyncTest('Throwing an error inside a rejectionHandled handler goes to unhandledException, and does not cause .catch() to throw an exception',function(done){
642
+
asyncTest('Throwing an error inside a rejectionHandled handler goes to'+
643
+
' unhandledException, and does not cause .catch() to throw an'+
0 commit comments