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 ba4a3ed

Browse filesBrowse files
Italo A. CasasMyles Borins
authored andcommitted
test: writable stream ending state
Add a test for _writableState.ending, when ending becomes true, but the stream is not finished/ended yet. PR-URL: #8707 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Related: #8686
1 parent 80a26c7 commit ba4a3ed
Copy full SHA for ba4a3ed

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+35
-0
lines changed
Open diff view settings
Collapse file

‎lib/_stream_writable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_writable.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function WritableState(options, stream) {
4343
// cast to ints.
4444
this.highWaterMark = ~~this.highWaterMark;
4545

46+
// drain event flag.
4647
this.needDrain = false;
4748
// at the start of calling end()
4849
this.ending = false;
Collapse file
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const stream = require('stream');
7+
8+
const writable = new stream.Writable();
9+
10+
function testStates(ending, finished, ended) {
11+
assert.strictEqual(writable._writableState.ending, ending);
12+
assert.strictEqual(writable._writableState.finished, finished);
13+
assert.strictEqual(writable._writableState.ended, ended);
14+
}
15+
16+
writable._write = (chunk, encoding, cb) => {
17+
// ending, finished, ended start in false.
18+
testStates(false, false, false);
19+
cb();
20+
};
21+
22+
writable.on('finish', () => {
23+
// ending, finished, ended = true.
24+
testStates(true, true, true);
25+
});
26+
27+
writable.end('testing function end()', () => {
28+
// ending, finished, ended = true.
29+
testStates(true, true, true);
30+
});
31+
32+
// ending, ended = true.
33+
// finished = false.
34+
testStates(true, false, true);

0 commit comments

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