0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-stream-event-names.js
IlyasShabi a51efa2bcf
stream: fix eventNames() to not return not defined events
PR-URL: https://github.com/nodejs/node/pull/51331
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-02-27 23:56:43 +00:00

43 lines
982 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { Readable, Writable, Duplex } = require('stream');
{
const stream = new Readable();
assert.strictEqual(stream.eventNames().length, 0);
}
{
const stream = new Readable();
stream.on('foo', () => {});
stream.on('data', () => {});
stream.on('error', () => {});
assert.deepStrictEqual(stream.eventNames(), ['error', 'data', 'foo']);
}
{
const stream = new Writable();
assert.strictEqual(stream.eventNames().length, 0);
}
{
const stream = new Writable();
stream.on('foo', () => {});
stream.on('drain', () => {});
stream.on('prefinish', () => {});
assert.deepStrictEqual(stream.eventNames(), ['prefinish', 'drain', 'foo']);
}
{
const stream = new Duplex();
assert.strictEqual(stream.eventNames().length, 0);
}
{
const stream = new Duplex();
stream.on('foo', () => {});
stream.on('finish', () => {});
assert.deepStrictEqual(stream.eventNames(), ['finish', 'foo']);
}