mirror of https://github.com/lukechilds/node.git
Browse Source
Log unhandled promise rejections with a guid and emit a process warning. When rejection is eventually handled, emit a secondary warning. PR-URL: https://github.com/nodejs/node/pull/8217 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>v7.x
Benjamin Gruenbaum
9 years ago
committed by
James M Snell
2 changed files with 47 additions and 6 deletions
@ -0,0 +1,26 @@ |
|||||
|
// Flags: --no-warnings
|
||||
|
'use strict'; |
||||
|
|
||||
|
// Test that warnings are emitted when a Promise experiences an uncaught
|
||||
|
// rejection, and then again if the rejection is handled later on.
|
||||
|
|
||||
|
const common = require('../common'); |
||||
|
const assert = require('assert'); |
||||
|
|
||||
|
var b = 0; |
||||
|
|
||||
|
process.on('warning', common.mustCall((warning) => { |
||||
|
switch (b++) { |
||||
|
case 0: |
||||
|
assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning'); |
||||
|
assert(/Unhandled promise rejection/.test(warning.message)); |
||||
|
break; |
||||
|
case 1: |
||||
|
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning'); |
||||
|
assert(/Promise rejection was handled asynchronously/ |
||||
|
.test(warning.message)); |
||||
|
} |
||||
|
}, 2)); |
||||
|
|
||||
|
const p = Promise.reject('This was rejected'); |
||||
|
setImmediate(common.mustCall(() => p.catch(() => {}))); |
Loading…
Reference in new issue