readable.js
This file
Path
test/convert/readable.js
503 lines · 18.5 KiB · JavaScript
Last changed by
Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import {once} from 'node:events';TweaksSindre Sorhusbefore adoption698a1b8
lines 3–6why, one step back3import {pipeline} from 'node:stream/promises';4import {text} from 'node:stream/consumers';5import {setTimeout} from 'node:timers/promises';6import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 7–12why, one step back7import {8 compose,9 Readable,10 Writable,11 PassThrough,12} from 'node:stream';TweaksSindre Sorhusbefore adoption698a1b8
line 13why, one step back13import {assertRejects, assertLike} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 14–32why, one step back14import {execa} from '../../index.js';15import {setFixtureDirectory} from '../helpers/fixtures-directory.js';16import {17 finishedStream,18 assertReadableAborted,19 assertWritableAborted,20 assertProcessNormalExit,21 assertStreamOutput,22 assertStreamChunks,23 assertStreamError,24 assertStreamReadError,25 assertSubprocessOutput,26 assertSubprocessError,27 assertPromiseError,28 getReadableSubprocess,29 getReadWriteSubprocess,30} from '../helpers/convert.js';31import {foobarString, foobarBuffer, foobarObject} from '../helpers/input.js';32import {simpleFull} from '../helpers/lines.js';Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8
line 33why, one step back33import {majorNodeVersion} from '../helpers/node-version.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 34–39why, one step back34import {prematureClose, fullStdio} from '../helpers/stdio.js';35import {outputObjectGenerator, getOutputsAsyncGenerator} from '../helpers/generator.js';36import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js';3738setFixtureDirectory();39TweaksSindre Sorhusbefore adoption698a1b8
line 40why, one step back40test('.readable() success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 41–43why, one step back41 const subprocess = getReadableSubprocess();42 const stream = subprocess.readable();43TweaksSindre Sorhusbefore adoption698a1b8
lines 44–47why, one step back44 assert.ok(!(stream instanceof Writable));45 assert.equal(stream.writable, undefined);46 assert.ok(stream instanceof Readable);47 assert.equal(stream.readable, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 48why, one step back48TweaksSindre Sorhusbefore adoption698a1b8
lines 49–50why, one step back49 await assertStreamOutput(stream);50 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 51–52why, one step back51});52TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53const testReadableDefault = async (fdNumber, from, options, hasResult) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 54–56why, one step back54 const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], options);55 const stream = subprocess.readable({from});56TweaksSindre Sorhusbefore adoption698a1b8
lines 57–58why, one step back57 await assertStreamOutput(stream, hasResult ? foobarString : '');58 await assertSubprocessOutput(subprocess, foobarString, fdNumber);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 59–60why, one step back59};60TweaksSindre Sorhusbefore adoption698a1b8
lines 61–70why, one step back61test('.readable() can use stdout', () => testReadableDefault(1, 'stdout', {}, true));62test('.readable() can use stderr', () => testReadableDefault(2, 'stderr', {}, true));63test('.readable() can use stdio[*]', () => testReadableDefault(3, 'fd3', fullStdio, true));64test('.readable() uses stdout by default', () => testReadableDefault(1, undefined, {}, true));65test('.readable() does not use stderr by default', () => testReadableDefault(2, undefined, {}, false));66test('.readable() does not use stdio[*] by default', () => testReadableDefault(3, undefined, fullStdio, false));67test('.readable() uses stdout even if stderr is "ignore"', () => testReadableDefault(1, 'stdout', {stderr: 'ignore'}, true));68test('.readable() uses stderr even if stdout is "ignore"', () => testReadableDefault(2, 'stderr', {stdout: 'ignore'}, true));69test('.readable() uses stdout if "all" is used', () => testReadableDefault(1, 'all', {all: true}, true));70test('.readable() uses stderr if "all" is used', () => testReadableDefault(2, 'all', {all: true}, true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 71why, one step back71TweaksSindre Sorhusbefore adoption698a1b8
line 72why, one step back72const testBuffering = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 73–79why, one step back73 const subprocess = execa('noop-stdin-fd.js', ['1'], {buffer: false});74 const stream = subprocess[methodName]();7576 subprocess.stdin.write(foobarString);77 await once(subprocess.stdout, 'readable');78 subprocess.stdin.end();79TweaksSindre Sorhusbefore adoption698a1b8
line 80why, one step back80 await assertStreamOutput(stream);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 81–82why, one step back81};82TweaksSindre Sorhusbefore adoption698a1b8
lines 83–84why, one step back83test('.readable() buffers until read', () => testBuffering('readable'));84test('.duplex() buffers until read', () => testBuffering('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 85why, one step back85Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
lines 86–117why, one step back86// Breaking out of `for await` or cancelling a web stream destroys the stream with an `AbortError`, which aborts it like `stream.destroy()`87const testStopIteration = async stopIteration => {88 const subprocess = execa('noop-delay.js', ['1', foobarString]);89 await stopIteration(subprocess);90 const {exitCode} = await subprocess;91 assert.equal(exitCode, 0);92};9394const stopIterator = async asyncIterable => {95 const iterator = asyncIterable[Symbol.asyncIterator]();96 await iterator.next();97 await iterator.return();98};99100const cancelReader = async readableStream => {101 const reader = readableStream.getReader();102 await reader.read();103 await reader.cancel();104};105106test('.readable() iteration can be stopped', () => testStopIteration(subprocess => stopIterator(subprocess.readable())));107// This destroys `subprocess.stdout` with an `AbortError`, which cannot be told apart from an `AbortError` thrown by a transform. So this is not supported, and `subprocess.readable()` or `subprocess.iterable()` must be used instead.108test('subprocess.stdout iteration cannot be stopped', async () => {109 const subprocess = execa('noop-delay.js', ['1', foobarString]);110 await stopIterator(subprocess.stdout);111 const {code} = await assertRejects(subprocess);112 assert.equal(code, 'ABORT_ERR');113});114test('.readableStream() can be cancelled', () => testStopIteration(subprocess => cancelReader(subprocess.readableStream())));115test('.readableStream() iteration can be stopped', () => testStopIteration(subprocess => stopIterator(subprocess.readableStream())));116test('.iterable() iteration can be stopped', () => testStopIteration(subprocess => stopIterator(subprocess.iterable())));117TweaksSindre Sorhusbefore adoption698a1b8
line 118why, one step back118test('.readable() abort -> subprocess fail', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 119–123why, one step back119 const subprocess = execa('noop-repeat.js');120 const stream = subprocess.readable();121122 stream.destroy();123TweaksSindre Sorhusbefore adoption698a1b8
lines 124–130why, one step back124 const error = await assertRejects(text(stream));125 assertProcessNormalExit(error, 1);126 assert.ok(error.message.includes('EPIPE'));127 assertWritableAborted(subprocess.stdin);128 assertReadableAborted(subprocess.stdout);129 assert.equal(subprocess.stderr.readableEnded, true);130 await assertSubprocessError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 131–132why, one step back131});132TweaksSindre Sorhusbefore adoption698a1b8
line 133why, one step back133test('.readable() error -> subprocess fail', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 134–139why, one step back134 const subprocess = execa('noop-repeat.js');135 const stream = subprocess.readable();136137 const cause = new Error(foobarString);138 stream.destroy(cause);139TweaksSindre Sorhusbefore adoption698a1b8
lines 140–146why, one step back140 const error = await assertStreamReadError(stream, {cause});141 assertProcessNormalExit(error, 1);142 assert.ok(error.message.includes('EPIPE'));143 assertWritableAborted(subprocess.stdin);144 assert.equal(subprocess.stdout.errored, cause);145 assert.equal(subprocess.stderr.readableEnded, true);146 await assertSubprocessError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 147–148why, one step back147});148TweaksSindre Sorhusbefore adoption698a1b8
line 149why, one step back149const testStdoutAbort = async methodName => {Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 150why, one step back150 const subprocess = execa('ipc-echo.js', {ipc: true});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 151–154why, one step back151 const stream = subprocess[methodName]();152153 subprocess.stdout.destroy();154Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 155why, one step back155 await subprocess.sendMessage(foobarString);Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 156why, one step back156 const [error, message] = await Promise.all([TweaksSindre Sorhusbefore adoption698a1b8
line 157why, one step back157 assertRejects(finishedStream(stream)),Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 158why, one step back158 subprocess.getOneMessage(),100% test coverage (#1018)ehmickybefore adoption9f65b86
line 159why, one step back159 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 160–165why, one step back160 assertLike(error, prematureClose);161 assert.equal(message, foobarString);162 assertWritableAborted(subprocess.stdin);163 assertReadableAborted(subprocess.stdout);164 assert.equal(subprocess.stderr.readableEnded, true);165 await assertSubprocessOutput(subprocess, '');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 166–167why, one step back166};167TweaksSindre Sorhusbefore adoption698a1b8
lines 168–169why, one step back168test('subprocess.stdout abort + no more writes -> .readable() error + subprocess success', () => testStdoutAbort('readable'));169test('subprocess.stdout abort + no more writes -> .duplex() error + subprocess success', () => testStdoutAbort('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 170why, one step back170TweaksSindre Sorhusbefore adoption698a1b8
line 171why, one step back171const testStdoutError = async methodName => {Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 172why, one step back172 const subprocess = execa('ipc-echo.js', {ipc: true});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 173–177why, one step back173 const stream = subprocess[methodName]();174175 const cause = new Error(foobarString);176 subprocess.stdout.destroy(cause);177Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 178why, one step back178 await subprocess.sendMessage(foobarString);Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 179why, one step back179 const [error, message] = await Promise.all([TweaksSindre Sorhusbefore adoption698a1b8
line 180why, one step back180 assertRejects(finishedStream(stream)),Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 181why, one step back181 subprocess.getOneMessage(),100% test coverage (#1018)ehmickybefore adoption9f65b86
line 182why, one step back182 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 183–188why, one step back183 assert.equal(message, foobarString);184 assert.equal(error.cause, cause);185 assertProcessNormalExit(error);186 assert.equal(subprocess.stdout.errored, cause);187 assert.equal(subprocess.stderr.readableEnded, true);188 assertWritableAborted(subprocess.stdin);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 189why, one step back189TweaksSindre Sorhusbefore adoption698a1b8
line 190why, one step back190 await assertSubprocessError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 191–192why, one step back191};192TweaksSindre Sorhusbefore adoption698a1b8
lines 193–194why, one step back193test('subprocess.stdout error + no more writes -> .readable() error + subprocess fail', () => testStdoutError('readable'));194test('subprocess.stdout error + no more writes -> .duplex() error + subprocess fail', () => testStdoutError('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 195why, one step back195TweaksSindre Sorhusbefore adoption698a1b8
line 196why, one step back196const testStdinAbortWrites = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 197–202why, one step back197 const subprocess = getReadWriteSubprocess();198 const stream = subprocess[methodName]();199200 subprocess.stdout.destroy();201 subprocess.stdin.end(foobarString);202TweaksSindre Sorhusbefore adoption698a1b8
lines 203–208why, one step back203 const error = await assertRejects(finishedStream(stream));204 assertProcessNormalExit(error, 1);205 assert.equal(subprocess.stdin.writableEnded, true);206 assertReadableAborted(subprocess.stdout);207 assert.equal(subprocess.stderr.readableEnded, true);208 await assertSubprocessError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 209–210why, one step back209};210TweaksSindre Sorhusbefore adoption698a1b8
lines 211–212why, one step back211test('subprocess.stdout abort + more writes -> .readable() error + subprocess fail', () => testStdinAbortWrites('readable'));212test('subprocess.stdout abort + more writes -> .duplex() error + subprocess fail', () => testStdinAbortWrites('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 213why, one step back213TweaksSindre Sorhusbefore adoption698a1b8
line 214why, one step back214const testStdinErrorWrites = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 215–221why, one step back215 const subprocess = getReadWriteSubprocess();216 const stream = subprocess[methodName]();217218 const cause = new Error(foobarString);219 subprocess.stdout.destroy(cause);220 subprocess.stdin.end(foobarString);221TweaksSindre Sorhusbefore adoption698a1b8
lines 222–227why, one step back222 const error = await assertStreamError(stream, {cause});223 assertProcessNormalExit(error, 1);224 assert.equal(subprocess.stdin.writableEnded, true);225 assert.equal(subprocess.stdout.errored, cause);226 assert.equal(subprocess.stderr.readableEnded, true);227 await assertSubprocessError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 228–229why, one step back228};229TweaksSindre Sorhusbefore adoption698a1b8
lines 230–231why, one step back230test('subprocess.stdout error + more writes -> .readable() error + subprocess fail', () => testStdinErrorWrites('readable'));231test('subprocess.stdout error + more writes -> .duplex() error + subprocess fail', () => testStdinErrorWrites('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 232why, one step back232TweaksSindre Sorhusbefore adoption698a1b8
line 233why, one step back233test('.readable() can be used with Stream.pipeline()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 234–240why, one step back234 const subprocess = getReadableSubprocess();235 const stream = subprocess.readable();236 const outputStream = new PassThrough();237238 await pipeline(stream, outputStream);239240 await finishedStream(stream);TweaksSindre Sorhusbefore adoption698a1b8
lines 241–242why, one step back241 await assertStreamOutput(outputStream);242 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 243–244why, one step back243});244TweaksSindre Sorhusbefore adoption698a1b8
line 245why, one step back245test('.readable() can error with Stream.pipeline()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 246–249why, one step back246 const subprocess = execa('noop-fail.js', ['1', foobarString]);247 const stream = subprocess.readable();248 const outputStream = new PassThrough();249TweaksSindre Sorhusbefore adoption698a1b8
lines 250–252why, one step back250 const error = await assertRejects(pipeline(stream, outputStream));251 assertProcessNormalExit(error, 2);252 assertLike(error, {stdout: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 253why, one step back253TweaksSindre Sorhusbefore adoption698a1b8
lines 254–256why, one step back254 await assertStreamError(stream, error);255 await assertStreamReadError(outputStream, error);256 await assertSubprocessError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 257–258why, one step back257});258TweaksSindre Sorhusbefore adoption698a1b8
line 259why, one step back259test('.readable() can pipe to errored stream with Stream.pipeline()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 260–266why, one step back260 const subprocess = getReadableSubprocess();261 const stream = subprocess.readable();262 const outputStream = new PassThrough();263264 const cause = new Error('test');265 outputStream.destroy(cause);266Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8
lines 267–269why, one step back267 // Node 23 does not allow calling `stream.pipeline()` with an already errored stream268 if (majorNodeVersion >= 23) {269 outputStream.on('error', () => {});TweaksSindre Sorhusbefore adoption698a1b8
line 270why, one step back270 await assertRejects(pipeline(stream, outputStream), {code: 'ERR_STREAM_UNABLE_TO_PIPE'});Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8
line 271why, one step back271 } else {TweaksSindre Sorhusbefore adoption698a1b8
lines 272–273why, one step back272 await assertPromiseError(pipeline(stream, outputStream), cause);273 await assertRejects(finishedStream(stream));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 274why, one step back274TweaksSindre Sorhusbefore adoption698a1b8
lines 275–277why, one step back275 const error = await assertStreamError(stream, cause);276 await assertStreamReadError(outputStream, cause);277 await assertSubprocessError(subprocess, {cause: error});Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8
line 278why, one step back278 }100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 279–280why, one step back279});280TweaksSindre Sorhusbefore adoption698a1b8
line 281why, one step back281test('.readable() can be used with Stream.compose()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 282–285why, one step back282 const subprocess = getReadableSubprocess();283 const stream = subprocess.readable();284 const outputStream = new PassThrough();285TweaksSindre Sorhusbefore adoption698a1b8
lines 286–287why, one step back286 await assertStreamOutput(compose(stream, outputStream));287 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 288–289why, one step back288});289TweaksSindre Sorhusbefore adoption698a1b8
line 290why, one step back290test('.readable() works with objectMode', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 291–292why, one step back291 const subprocess = execa('noop.js', {stdout: outputObjectGenerator()});292 const stream = subprocess.readable();TweaksSindre Sorhusbefore adoption698a1b8
lines 293–294why, one step back293 assert.equal(stream.readableObjectMode, true);294 assert.equal(stream.readableHighWaterMark, defaultObjectHighWaterMark);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 295why, one step back295TweaksSindre Sorhusbefore adoption698a1b8
lines 296–297why, one step back296 await assertStreamChunks(stream, [foobarObject]);297 await assertSubprocessOutput(subprocess, [foobarObject]);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 298–299why, one step back298});299TweaksSindre Sorhusbefore adoption698a1b8
line 300why, one step back300test('.duplex() works with objectMode and reads', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 301–302why, one step back301 const subprocess = getReadWriteSubprocess({stdout: outputObjectGenerator()});302 const stream = subprocess.duplex();TweaksSindre Sorhusbefore adoption698a1b8
lines 303–306why, one step back303 assert.equal(stream.readableObjectMode, true);304 assert.equal(stream.readableHighWaterMark, defaultObjectHighWaterMark);305 assert.equal(stream.writableObjectMode, false);306 assert.equal(stream.writableHighWaterMark, defaultHighWaterMark);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 307–308why, one step back307 stream.end(foobarString);308TweaksSindre Sorhusbefore adoption698a1b8
lines 309–310why, one step back309 await assertStreamChunks(stream, [foobarObject]);310 await assertSubprocessOutput(subprocess, [foobarObject]);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 311–312why, one step back311});312TweaksSindre Sorhusbefore adoption698a1b8
line 313why, one step back313test('.readable() works with default encoding', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 314–315why, one step back314 const subprocess = getReadableSubprocess();315 const stream = subprocess.readable();TweaksSindre Sorhusbefore adoption698a1b8
line 316why, one step back316 assert.equal(stream.readableEncoding, null);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 317why, one step back317TweaksSindre Sorhusbefore adoption698a1b8
lines 318–319why, one step back318 await assertStreamChunks(stream, [foobarBuffer]);319 await assertSubprocessOutput(subprocess, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 320–321why, one step back320});321TweaksSindre Sorhusbefore adoption698a1b8
line 322why, one step back322test('.duplex() works with default encoding', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 323–324why, one step back323 const subprocess = getReadWriteSubprocess();324 const stream = subprocess.duplex();TweaksSindre Sorhusbefore adoption698a1b8
line 325why, one step back325 assert.equal(stream.readableEncoding, null);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 326–327why, one step back326 stream.end(foobarString);327TweaksSindre Sorhusbefore adoption698a1b8
lines 328–329why, one step back328 await assertStreamChunks(stream, [foobarBuffer]);329 await assertSubprocessOutput(subprocess, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 330–331why, one step back330});331TweaksSindre Sorhusbefore adoption698a1b8
line 332why, one step back332test('.readable() works with encoding "utf8"', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 333–335why, one step back333 const subprocess = getReadableSubprocess();334 subprocess.stdout.setEncoding('utf8');335 const stream = subprocess.readable();TweaksSindre Sorhusbefore adoption698a1b8
line 336why, one step back336 assert.equal(stream.readableEncoding, 'utf8');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 337why, one step back337TweaksSindre Sorhusbefore adoption698a1b8
lines 338–339why, one step back338 await assertStreamChunks(stream, [foobarString]);339 await assertSubprocessOutput(subprocess, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 340–341why, one step back340});341TweaksSindre Sorhusbefore adoption698a1b8
line 342why, one step back342test('.duplex() works with encoding "utf8"', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 343–345why, one step back343 const subprocess = getReadWriteSubprocess();344 subprocess.stdout.setEncoding('utf8');345 const stream = subprocess.duplex();TweaksSindre Sorhusbefore adoption698a1b8
line 346why, one step back346 assert.equal(stream.readableEncoding, 'utf8');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 347–348why, one step back347 stream.end(foobarBuffer);348TweaksSindre Sorhusbefore adoption698a1b8
lines 349–350why, one step back349 await assertStreamChunks(stream, [foobarString]);350 await assertSubprocessOutput(subprocess, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 351–352why, one step back351});352TweaksSindre Sorhusbefore adoption698a1b8
line 353why, one step back353test('.readable() has the right highWaterMark', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 354–355why, one step back354 const subprocess = execa('noop.js');355 const stream = subprocess.readable();TweaksSindre Sorhusbefore adoption698a1b8
line 356why, one step back356 assert.equal(stream.readableHighWaterMark, defaultHighWaterMark);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 357–359why, one step back357 await text(stream);358});359TweaksSindre Sorhusbefore adoption698a1b8
line 360why, one step back360test('.readable() can iterate over lines', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 361why, one step back361 const subprocess = execa('noop-fd.js', ['1', simpleFull]);Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 362why, one step back362 const lines = await Array.fromAsync(subprocess.readable({binary: false, preserveNewlines: false}));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 363–364why, one step back363364 const expectedLines = ['aaa', 'bbb', 'ccc'];TweaksSindre Sorhusbefore adoption698a1b8
lines 365–366why, one step back365 assert.deepEqual(lines, expectedLines);366 await assertSubprocessOutput(subprocess, simpleFull);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 367–368why, one step back367});368TweaksSindre Sorhusbefore adoption698a1b8
line 369why, one step back369test('.readable() can wait for data', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 370–372why, one step back370 const subprocess = execa('noop.js', {stdout: getOutputsAsyncGenerator([foobarString, foobarString])(false, true)});371 const stream = subprocess.readable();372TweaksSindre Sorhusbefore adoption698a1b8
line 373why, one step back373 assert.equal(stream.read(), null);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 374why, one step back374 await once(stream, 'readable');TweaksSindre Sorhusbefore adoption698a1b8
lines 375–376why, one step back375 assert.equal(stream.read().toString(), foobarString);376 assert.equal(stream.read(), null);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 377why, one step back377 await once(stream, 'readable');TweaksSindre Sorhusbefore adoption698a1b8
lines 378–379why, one step back378 assert.equal(stream.read().toString(), foobarString);379 assert.equal(stream.read(), null);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 380why, one step back380 await once(stream, 'readable');TweaksSindre Sorhusbefore adoption698a1b8
line 381why, one step back381 assert.equal(stream.read(), null);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 382–383why, one step back382383 await finishedStream(stream);TweaksSindre Sorhusbefore adoption698a1b8
line 384why, one step back384 await assertSubprocessOutput(subprocess, `${foobarString}${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 385–386why, one step back385});386TweaksSindre Sorhusbefore adoption698a1b8
line 387why, one step back387const testBufferData = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 388–392why, one step back388 const chunk = '.'.repeat(defaultHighWaterMark).repeat(2);389 const subprocess = getReadWriteSubprocess();390 const stream = subprocess[methodName]();391 subprocess.stdin.end(chunk);392TweaksSindre Sorhusbefore adoption698a1b8
lines 393–394why, one step back393 await assertStreamOutput(stream, chunk);394 await assertSubprocessOutput(subprocess, chunk);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 395–396why, one step back395};396TweaksSindre Sorhusbefore adoption698a1b8
lines 397–398why, one step back397test('.readable() can buffer data', () => testBufferData('readable'));398test('.duplex() can buffer data', () => testBufferData('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 399why, one step back399TweaksSindre Sorhusbefore adoption698a1b8
line 400why, one step back400const assertDataEvents = async (stream, subprocess) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 401why, one step back401 const [output] = await once(stream, 'data');TweaksSindre Sorhusbefore adoption698a1b8
line 402why, one step back402 assert.equal(output.toString(), foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 403–404why, one step back403404 await finishedStream(stream);TweaksSindre Sorhusbefore adoption698a1b8
line 405why, one step back405 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 406–407why, one step back406};407TweaksSindre Sorhusbefore adoption698a1b8
line 408why, one step back408test('.readable() can be read with "data" events', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 409–411why, one step back409 const subprocess = getReadableSubprocess();410 const stream = subprocess.readable();411TweaksSindre Sorhusbefore adoption698a1b8
line 412why, one step back412 await assertDataEvents(stream, subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 413–414why, one step back413});414TweaksSindre Sorhusbefore adoption698a1b8
line 415why, one step back415test('.duplex() can be read with "data" events', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 416–419why, one step back416 const subprocess = getReadWriteSubprocess();417 const stream = subprocess.duplex();418 stream.end(foobarString);419TweaksSindre Sorhusbefore adoption698a1b8
line 420why, one step back420 await assertDataEvents(stream, subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 421–422why, one step back421});422TweaksSindre Sorhusbefore adoption698a1b8
line 423why, one step back423const assertPause = async (stream, subprocess) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 424–426why, one step back424 const onceData = once(stream, 'data');425 stream.pause();426TweaksSindre Sorhusbefore adoption698a1b8
line 427why, one step back427 assert.equal(stream.readableLength, 0);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 428–432why, one step back428 do {429 // eslint-disable-next-line no-await-in-loop430 await setTimeout(10);431 } while (stream.readableLength === 0);432TweaksSindre Sorhusbefore adoption698a1b8
line 433why, one step back433 assert.ok(!await Promise.race([onceData, false]));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 434–436why, one step back434435 stream.resume();436 const [output] = await onceData;TweaksSindre Sorhusbefore adoption698a1b8
line 437why, one step back437 assert.equal(output.toString(), foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 438–439why, one step back438439 await finishedStream(stream);TweaksSindre Sorhusbefore adoption698a1b8
line 440why, one step back440 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 441–442why, one step back441};442TweaksSindre Sorhusbefore adoption698a1b8
line 443why, one step back443test('.readable() can be paused', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 444–446why, one step back444 const subprocess = getReadableSubprocess();445 const stream = subprocess.readable();446TweaksSindre Sorhusbefore adoption698a1b8
line 447why, one step back447 await assertPause(stream, subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 448–449why, one step back448});449TweaksSindre Sorhusbefore adoption698a1b8
line 450why, one step back450test('.duplex() can be paused', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 451–454why, one step back451 const subprocess = getReadWriteSubprocess();452 const stream = subprocess.duplex();453 stream.end(foobarString);454TweaksSindre Sorhusbefore adoption698a1b8
line 455why, one step back455 await assertPause(stream, subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 456–459why, one step back456});457458// This feature does not work on Node 18.459// @todo: remove after dropping support for Node 18.Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8
line 460why, one step back460if (majorNodeVersion >= 20) {TweaksSindre Sorhusbefore adoption698a1b8
line 461why, one step back461 const testHighWaterMark = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 462–474why, one step back462 const subprocess = execa('stdin.js');463 const stream = subprocess[methodName]();464465 let count = 0;466 const onPause = once(subprocess.stdout, 'pause');467 for (; !subprocess.stdout.isPaused(); count += 1) {468 subprocess.stdin.write('.');469 // eslint-disable-next-line no-await-in-loop470 await Promise.race([onPause, once(subprocess.stdout, 'data')]);471 }472473 const expectedCount = defaultObjectHighWaterMark + 1;474 const expectedOutput = '.'.repeat(expectedCount);TweaksSindre Sorhusbefore adoption698a1b8
line 475why, one step back475 assert.equal(count, expectedCount);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 476why, one step back476 subprocess.stdin.end();TweaksSindre Sorhusbefore adoption698a1b8
lines 477–478why, one step back477 await assertStreamOutput(stream, expectedOutput);478 await assertSubprocessOutput(subprocess, expectedOutput);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 479–480why, one step back479 };480TweaksSindre Sorhusbefore adoption698a1b8
lines 481–482why, one step back481 test('.readable() pauses its buffering when too high', () => testHighWaterMark('readable'));482 test('.duplex() pauses its buffering when too high', () => testHighWaterMark('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 483–484why, one step back483}484TweaksSindre Sorhusbefore adoption698a1b8
line 485why, one step back485const testBigOutput = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 486–489why, one step back486 const bigChunk = '.'.repeat(1e6);487 const subprocess = execa('stdin.js', {input: bigChunk});488 const stream = subprocess[methodName]();489TweaksSindre Sorhusbefore adoption698a1b8
lines 490–491why, one step back490 await assertStreamOutput(stream, bigChunk);491 await assertSubprocessOutput(subprocess, bigChunk);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 492–493why, one step back492};493TweaksSindre Sorhusbefore adoption698a1b8
lines 494–495why, one step back494test('.readable() with big output', () => testBigOutput('readable'));495test('.duplex() with big output', () => testBigOutput('duplex'));Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
lines 496–503why, one step back496497test('The "binary" readable option must use a boolean', () => {498 assert.throws(() => execa('noop.js').readable({binary: 'true'}), {message: /`binary` option must use a boolean/});499});500501test('The "preserveNewlines" readable option must use a boolean', () => {502 assert.throws(() => execa('noop.js').readable({preserveNewlines: 'true'}), {message: /`preserveNewlines` option must use a boolean/});503});