1'use strict';
2
3const common = require('../common');
4
5// This test ensures that Readable stream will call _read() for streams
6// with highWaterMark === 0 upon .read(0) instead of just trying to
7// emit 'readable' event.
8
9const assert = require('assert');
10const { Readable } = require('stream');
11
12const r = new Readable({
13  // Must be called only once upon setting 'readable' listener
14  read: common.mustCall(),
15  highWaterMark: 0,
16});
17
18let pushedNull = false;
19// This will trigger read(0) but must only be called after push(null)
20// because the we haven't pushed any data
21r.on('readable', common.mustCall(() => {
22  assert.strictEqual(r.read(), null);
23  assert.strictEqual(pushedNull, true);
24}));
25r.on('end', common.mustCall());
26process.nextTick(() => {
27  assert.strictEqual(r.read(), null);
28  pushedNull = true;
29  r.push(null);
30});
31