Skip to content
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

test: remove common module from test it thwarts #13748

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions test/parallel/test-global-console-exists.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
/* 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 common = require('../common');
// Ordinarily test files must require('common') but that action causes
// the global console to be compiled, defeating the purpose of this test.

const assert = require('assert');
const EventEmitter = require('events');
const leakWarning = /EventEmitter memory leak detected\. 2 hello listeners/;

common.hijackStderr(common.mustCall(function(data) {
if (process.stderr.writeTimes === 0) {
assert.ok(data.match(leakWarning));
} else {
assert.fail('stderr.write should be called only once');
}
}));

process.on('warning', function(warning) {
let writeTimes = 0;
let warningTimes = 0;
process.on('warning', () => {
// This will be called after the default internal
// process warning handler is called. The default
// process warning writes to the console, which will
// invoke the monkeypatched process.stderr.write
// below.
assert.strictEqual(process.stderr.writeTimes, 1);
assert.strictEqual(writeTimes, 1);
EventEmitter.defaultMaxListeners = oldDefault;
// when we get here, we should be done
warningTimes++;
});

process.on('exit', () => {
assert.strictEqual(warningTimes, 1);
});

process.stderr.write = (data) => {
if (writeTimes === 0)
assert.ok(data.match(leakWarning));
else
assert.fail('stderr.write should be called only once');

writeTimes++;
};

const oldDefault = EventEmitter.defaultMaxListeners;
EventEmitter.defaultMaxListeners = 1;

const e = new EventEmitter();
e.on('hello', common.noop);
e.on('hello', common.noop);
e.on('hello', () => {});
e.on('hello', () => {});

// TODO: Figure out how to validate console. Currently,
// there is no obvious way of validating that console
Expand Down