Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 271f578

Browse filesBrowse files
joyeecheungMylesBorins
authored andcommitted
stream, test: test _readableState.emittedReadable
Part of #8683, increase coverage of the internal state machine of streams. PR-URL: #10249 See: #8683 See: #10230 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 3f29cbb commit 271f578
Copy full SHA for 271f578

File tree

Expand file treeCollapse file tree

1 file changed

+70
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+70
-0
lines changed
Open diff view settings
Collapse file
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const Readable = require('stream').Readable;
5+
6+
const readable = new Readable({
7+
read: () => {}
8+
});
9+
10+
// Initialized to false.
11+
assert.strictEqual(readable._readableState.emittedReadable, false);
12+
13+
readable.on('readable', common.mustCall(() => {
14+
// emittedReadable should be true when the readable event is emitted
15+
assert.strictEqual(readable._readableState.emittedReadable, true);
16+
readable.read();
17+
// emittedReadable is reset to false during read()
18+
assert.strictEqual(readable._readableState.emittedReadable, false);
19+
}, 4));
20+
21+
// When the first readable listener is just attached,
22+
// emittedReadable should be false
23+
assert.strictEqual(readable._readableState.emittedReadable, false);
24+
25+
// Each one of these should trigger a readable event.
26+
process.nextTick(common.mustCall(() => {
27+
readable.push('foo');
28+
}));
29+
process.nextTick(common.mustCall(() => {
30+
readable.push('bar');
31+
}));
32+
process.nextTick(common.mustCall(() => {
33+
readable.push('quo');
34+
}));
35+
process.nextTick(common.mustCall(() => {
36+
readable.push(null);
37+
}));
38+
39+
const noRead = new Readable({
40+
read: () => {}
41+
});
42+
43+
noRead.on('readable', common.mustCall(() => {
44+
// emittedReadable should be true when the readable event is emitted
45+
assert.strictEqual(noRead._readableState.emittedReadable, true);
46+
noRead.read(0);
47+
// emittedReadable is not reset during read(0)
48+
assert.strictEqual(noRead._readableState.emittedReadable, true);
49+
}));
50+
51+
noRead.push('foo');
52+
noRead.push(null);
53+
54+
const flowing = new Readable({
55+
read: () => {}
56+
});
57+
58+
flowing.on('data', common.mustCall(() => {
59+
// When in flowing mode, emittedReadable is always false.
60+
assert.strictEqual(flowing._readableState.emittedReadable, false);
61+
flowing.read();
62+
assert.strictEqual(flowing._readableState.emittedReadable, false);
63+
}, 3));
64+
65+
flowing.push('foooo');
66+
flowing.push('bar');
67+
flowing.push('quo');
68+
process.nextTick(common.mustCall(() => {
69+
flowing.push(null);
70+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.