-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
events: make sure console functions exist #4479
Changes from 1 commit
362d832
9f8eddb
04a9276
ff4065e
e1a14e7
7152739
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,21 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const events = require('events'); | ||
|
||
const old_default = events.defaultMaxListeners; | ||
events.defaultMaxListeners = 1; | ||
|
||
const e = new events.EventEmitter(); | ||
e.on('hello', function() {}); | ||
|
||
assert.ok(!e._events['hello'].hasOwnProperty('warned')); | ||
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. Perhaps it would be better to use a public API to check, such as: assert.ok(!e.listeners('hello')[0].hasOwnProperty('warned')); 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. The 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. While I agree that it's the most efficient approach, using an internal API in a test is a bit troublesome. The "correct" way to do this would likely be to direct the stderr/stdout output to a stream and apply a regex to ensure that the result is as the user should expect it to be. It's a bit of a workaround but it ensures that we're testing exactly what the user would see. |
||
|
||
e.on('hello', function() {}); | ||
|
||
assert.ok(e._events['hello'].hasOwnProperty('warned')); | ||
|
||
events.defaultMaxListeners = old_default; | ||
|
||
// this caches console, so place it after the test just to appease the linter | ||
require('../common'); | ||
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. A better solution would be to put a |
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.
Redundant
EventEmitter