-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: fix eventNames() to not return not defined events
PR-URL: #51331 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
1 parent
7543e77
commit 5b06af7
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'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']); | ||
} |