mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

This adds the constructor name of the event target to the emitted warning. Right now it's difficult to identify where the leak is actually coming from and having some further information about the source will likely help to identify the source. PR-URL: https://github.com/nodejs/node/pull/27694 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
32 lines
916 B
JavaScript
32 lines
916 B
JavaScript
// Flags: --no-warnings
|
|
// The flag suppresses stderr output but the warning event will still emit
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const events = require('events');
|
|
const assert = require('assert');
|
|
|
|
class FakeInput extends events.EventEmitter {
|
|
resume() {}
|
|
pause() {}
|
|
write() {}
|
|
end() {}
|
|
}
|
|
|
|
const e = new FakeInput();
|
|
e.setMaxListeners(1);
|
|
|
|
process.on('warning', common.mustCall((warning) => {
|
|
assert.ok(warning instanceof Error);
|
|
assert.strictEqual(warning.name, 'MaxListenersExceededWarning');
|
|
assert.strictEqual(warning.emitter, e);
|
|
assert.strictEqual(warning.count, 2);
|
|
assert.strictEqual(warning.type, 'event-type');
|
|
assert.ok(warning.message.includes(
|
|
'2 event-type listeners added to [FakeInput].'));
|
|
}));
|
|
|
|
e.on('event-type', () => {});
|
|
e.on('event-type', () => {}); // Trigger warning.
|
|
e.on('event-type', () => {}); // Verify that warning is emitted only once.
|