diff options
author | Dave <dave@jut.io> | 2015-12-30 00:20:33 -0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-01-14 18:20:25 -0800 |
commit | f9a59c1d3bf8f809b2e581b4c8570b2c23a34bf2 (patch) | |
tree | 4789d5e8661fc58f0d3faf9343cb7128cf35b006 /test/parallel/test-global-console-exists.js | |
parent | 4bc1a4776164f813db8d22813fd06c7f5bdc173a (diff) | |
download | android-node-v8-f9a59c1d3bf8f809b2e581b4c8570b2c23a34bf2.tar.gz android-node-v8-f9a59c1d3bf8f809b2e581b4c8570b2c23a34bf2.tar.bz2 android-node-v8-f9a59c1d3bf8f809b2e581b4c8570b2c23a34bf2.zip |
events: make sure console functions exist
If there's no global console cached, initialize it.
Fixes: https://github.com/nodejs/node/issues/4467
PR-URL: https://github.com/nodejs/node/pull/4479
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-global-console-exists.js')
-rw-r--r-- | test/parallel/test-global-console-exists.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/parallel/test-global-console-exists.js b/test/parallel/test-global-console-exists.js new file mode 100644 index 0000000000..1a13ffec29 --- /dev/null +++ b/test/parallel/test-global-console-exists.js @@ -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; |