Skip to content
Closed
31 changes: 31 additions & 0 deletions test/parallel/test-stream-readable-readingMore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';
const Readable = require('stream').Readable,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please require ../common.js, as done in other test files.

assert = require('assert');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a new const statement on each line (drop the comma separated declarations).


const readable = new Readable({
read(size) {}
});

// false initially
assert.strictEqual(readable._readableState.readingMore, false);

readable.on('data', data => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are assertions inside of this callback, can you wrap it in common.mustCall().

// still in a flowing state, try to read more
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize and punctuate comments.

assert.strictEqual(readable._readableState.readingMore, true);
});

readable.on('end', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about common.mustCall() here.

// end of stream
// reading is false, and so should be readingMore
assert.strictEqual(readable._readableState.readingMore, false);
});


readable.push("abc");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use single quotes for strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjihrig Thank you for the guidance 👍

readable.push(null);

process.nextTick(() => {
// finished reading
// reading is false, and so should be readingMore
assert.strictEqual(readable._readableState.readingMore, false);
});