-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
promise: warning on unhandled rejection #8217
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Flags: --no-warnings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be unnecessary since we are handling it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prevents the unnecessary stderr output so the test isn't needlessly noisy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jasnell It should never reach stderr since we are listening to it. is there a bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not how emitWarning works. By default it prints to stderr and emits the |
||
'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, 'DeprecationWarning'); | ||
break; | ||
case 2: | ||
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning'); | ||
assert(/Promise rejection was handled asynchronously/ | ||
.test(warning.message)); | ||
} | ||
}, 3)); | ||
|
||
const p = Promise.reject('This was rejected'); | ||
setImmediate(common.mustCall(() => p.catch(() => {}))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this variable to define at line 36?