-
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 all commits
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,33 @@ | ||
/* eslint-disable required-modules */ | ||
// ordinarily test files must require('common') but that action causes | ||
// the global console to be compiled, defeating the purpose of this test | ||
|
||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const EventEmitter = require('events'); | ||
const leak_warning = /EventEmitter memory leak detected\. 2 hello listeners/; | ||
|
||
var write_calls = 0; | ||
process.stderr.write = function(data) { | ||
if (write_calls === 0) | ||
assert.ok(data.match(leak_warning)); | ||
else if (write_calls === 1) | ||
assert.ok(data.match(/Trace/)); | ||
else | ||
assert.ok(false, 'stderr.write should be called only twice'); | ||
|
||
write_calls++; | ||
}; | ||
|
||
const old_default = EventEmitter.defaultMaxListeners; | ||
EventEmitter.defaultMaxListeners = 1; | ||
|
||
const e = new EventEmitter(); | ||
e.on('hello', function() {}); | ||
e.on('hello', function() {}); | ||
|
||
// TODO validate console | ||
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. Why add the comment vs. adding the validation? 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. As per earlier discussion (#4479 (diff)) I don't think it's actually possible to validate the console here in any significant way, but @thefourtheye requested a comment about validating 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. oh :-) lol completely missed that one |
||
assert.equal(write_calls, 2); | ||
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. Shouldn't we also assert if 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. I don't think there's any way we can do that without incidentally initializing it. Our prior logging would have failed if 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. How about checking if 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. Such a reference to 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. I suppose we could inspect 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. Scratch that -- 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. Hmmm, my office time has started. I'll think about this when I find time today. Let's not block this PR because of this. Perhaps you might want to leave a TODO or something in the test for the timebeing. |
||
|
||
EventEmitter.defaultMaxListeners = old_default; |
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.
This is why we have
assert.equal(write_calls, 2);
at the end, right?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.
Sure! I felt like I should have some sort of catch-all
else
statement here though.