11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst { Readable } = require('stream'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// basic 81cb0ef41Sopenharmony_ci{ 91cb0ef41Sopenharmony_ci // Find it on Readable.prototype 101cb0ef41Sopenharmony_ci assert(Object.hasOwn(Readable.prototype, 'readableEnded')); 111cb0ef41Sopenharmony_ci} 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// event 141cb0ef41Sopenharmony_ci{ 151cb0ef41Sopenharmony_ci const readable = new Readable(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci readable._read = () => { 181cb0ef41Sopenharmony_ci // The state ended should start in false. 191cb0ef41Sopenharmony_ci assert.strictEqual(readable.readableEnded, false); 201cb0ef41Sopenharmony_ci readable.push('asd'); 211cb0ef41Sopenharmony_ci assert.strictEqual(readable.readableEnded, false); 221cb0ef41Sopenharmony_ci readable.push(null); 231cb0ef41Sopenharmony_ci assert.strictEqual(readable.readableEnded, false); 241cb0ef41Sopenharmony_ci }; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci readable.on('end', common.mustCall(() => { 271cb0ef41Sopenharmony_ci assert.strictEqual(readable.readableEnded, true); 281cb0ef41Sopenharmony_ci })); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci readable.on('data', common.mustCall(() => { 311cb0ef41Sopenharmony_ci assert.strictEqual(readable.readableEnded, false); 321cb0ef41Sopenharmony_ci })); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// Verifies no `error` triggered on multiple .push(null) invocations 361cb0ef41Sopenharmony_ci{ 371cb0ef41Sopenharmony_ci const readable = new Readable(); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci readable.on('readable', () => { readable.read(); }); 401cb0ef41Sopenharmony_ci readable.on('error', common.mustNotCall()); 411cb0ef41Sopenharmony_ci readable.on('end', common.mustCall()); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci readable.push('a'); 441cb0ef41Sopenharmony_ci readable.push(null); 451cb0ef41Sopenharmony_ci readable.push(null); 461cb0ef41Sopenharmony_ci} 47