mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 12:08:20 +00:00

When a possible listener leak is detected, a warning is emitted. This commit updates an existing test to verify that the warning is only emitted once. PR-URL: https://github.com/nodejs/node/pull/12502 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
24 lines
815 B
JavaScript
24 lines
815 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');
|
|
|
|
const e = new events.EventEmitter();
|
|
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.'));
|
|
}));
|
|
|
|
e.on('event-type', common.noop);
|
|
e.on('event-type', common.noop); // Trigger warning.
|
|
e.on('event-type', common.noop); // Verify that warning is emitted only once.
|