-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events: make sure console functions exist
If there's no global console cached, initialize it. Fixes: #4467 PR-URL: #4479 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* 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: figure out how to validate console. Currently, | ||
// there is no obvious way of validating that console | ||
// exists here exactly when it should. | ||
|
||
assert.equal(write_calls, 2); | ||
|
||
EventEmitter.defaultMaxListeners = old_default; |