Skip to content
Myr

readable.js

This file

Path

test/convert/readable.js

463 lines · 16.5 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 08eb743 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 2why, one step back
2import {once} from 'node:events';

TweaksSindre Sorhusbefore adoption698a1b8

lines 3–6why, one step back
3import {pipeline} from 'node:stream/promises';
4import {text} from 'node:stream/consumers';5import {setTimeout} from 'node:timers/promises';6import test from 'node:test';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 7–12why, one step back
7import {
8 compose,9 Readable,10 Writable,11 PassThrough,12} from 'node:stream';

TweaksSindre Sorhusbefore adoption698a1b8

line 13why, one step back
13import {assertRejects, assertLike} from '../helpers/assert.js';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 14–32why, one step back
14import {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 back
33import {majorNodeVersion} from '../helpers/node-version.js';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 34–39why, one step back
34import {prematureClose, fullStdio} from '../helpers/stdio.js';
35import {outputObjectGenerator, getOutputsAsyncGenerator} from '../helpers/generator.js';36import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js';3738setFixtureDirectory();39

TweaksSindre Sorhusbefore adoption698a1b8

line 40why, one step back
40test('.readable() success', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 41–43why, one step back
41 const subprocess = getReadableSubprocess();
42 const stream = subprocess.readable();43

TweaksSindre Sorhusbefore adoption698a1b8

lines 44–47why, one step back
44 assert.ok(!(stream instanceof Writable));
45 assert.equal(stream.writable, undefined);46 assert.ok(stream instanceof Readable);47 assert.equal(stream.readable, true);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 48why, one step back
48

TweaksSindre Sorhusbefore adoption698a1b8

lines 49–50why, one step back
49 await assertStreamOutput(stream);
50 await assertSubprocessOutput(subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 51–52why, one step back
51});
52

TweaksSindre Sorhusbefore adoption698a1b8

line 53why, one step back
53const testReadableDefault = async (fdNumber, from, options, hasResult) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 54–56why, one step back
54 const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], options);
55 const stream = subprocess.readable({from});56

TweaksSindre Sorhusbefore adoption698a1b8

lines 57–58why, one step back
57 await assertStreamOutput(stream, hasResult ? foobarString : '');
58 await assertSubprocessOutput(subprocess, foobarString, fdNumber);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 59–60why, one step back
59};
60

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–70why, one step back
61test('.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));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 71why, one step back
71

TweaksSindre Sorhusbefore adoption698a1b8

line 72why, one step back
72const testBuffering = async methodName => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 73–79why, one step back
73 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();79

TweaksSindre Sorhusbefore adoption698a1b8

line 80why, one step back
80 await assertStreamOutput(stream);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 81–82why, one step back
81};
82

TweaksSindre Sorhusbefore adoption698a1b8

lines 83–84why, one step back
83test('.readable() buffers until read', () => testBuffering('readable'));
84test('.duplex() buffers until read', () => testBuffering('duplex'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 85why, one step back
85

TweaksSindre Sorhusbefore adoption698a1b8

line 86why, one step back
86test('.readable() abort -> subprocess fail', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 87–91why, one step back
87 const subprocess = execa('noop-repeat.js');
88 const stream = subprocess.readable();8990 stream.destroy();91

TweaksSindre Sorhusbefore adoption698a1b8

lines 92–98why, one step back
92 const error = await assertRejects(text(stream));
93 assertProcessNormalExit(error, 1);94 assert.ok(error.message.includes('EPIPE'));95 assertWritableAborted(subprocess.stdin);96 assertReadableAborted(subprocess.stdout);97 assert.equal(subprocess.stderr.readableEnded, true);98 await assertSubprocessError(subprocess, error);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 99–100why, one step back
99});
100

TweaksSindre Sorhusbefore adoption698a1b8

line 101why, one step back
101test('.readable() error -> subprocess fail', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 102–107why, one step back
102 const subprocess = execa('noop-repeat.js');
103 const stream = subprocess.readable();104105 const cause = new Error(foobarString);106 stream.destroy(cause);107

TweaksSindre Sorhusbefore adoption698a1b8

lines 108–114why, one step back
108 const error = await assertStreamReadError(stream, {cause});
109 assertProcessNormalExit(error, 1);110 assert.ok(error.message.includes('EPIPE'));111 assertWritableAborted(subprocess.stdin);112 assert.equal(subprocess.stdout.errored, cause);113 assert.equal(subprocess.stderr.readableEnded, true);114 await assertSubprocessError(subprocess, error);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 115–116why, one step back
115});
116

TweaksSindre Sorhusbefore adoption698a1b8

line 117why, one step back
117const testStdoutAbort = async methodName => {

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 118why, one step back
118 const subprocess = execa('ipc-echo.js', {ipc: true});

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 119–122why, one step back
119 const stream = subprocess[methodName]();
120121 subprocess.stdout.destroy();122

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 123why, one step back
123 await subprocess.sendMessage(foobarString);

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 124why, one step back
124 const [error, message] = await Promise.all([

TweaksSindre Sorhusbefore adoption698a1b8

line 125why, one step back
125 assertRejects(finishedStream(stream)),

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 126why, one step back
126 subprocess.getOneMessage(),

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 127why, one step back
127 ]);

TweaksSindre Sorhusbefore adoption698a1b8

lines 128–133why, one step back
128 assertLike(error, prematureClose);
129 assert.equal(message, foobarString);130 assertWritableAborted(subprocess.stdin);131 assertReadableAborted(subprocess.stdout);132 assert.equal(subprocess.stderr.readableEnded, true);133 await assertSubprocessOutput(subprocess, '');

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 134–135why, one step back
134};
135

TweaksSindre Sorhusbefore adoption698a1b8

lines 136–137why, one step back
136test('subprocess.stdout abort + no more writes -> .readable() error + subprocess success', () => testStdoutAbort('readable'));
137test('subprocess.stdout abort + no more writes -> .duplex() error + subprocess success', () => testStdoutAbort('duplex'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 138why, one step back
138

TweaksSindre Sorhusbefore adoption698a1b8

line 139why, one step back
139const testStdoutError = async methodName => {

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 140why, one step back
140 const subprocess = execa('ipc-echo.js', {ipc: true});

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 141–145why, one step back
141 const stream = subprocess[methodName]();
142143 const cause = new Error(foobarString);144 subprocess.stdout.destroy(cause);145

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 146why, one step back
146 await subprocess.sendMessage(foobarString);

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 147why, one step back
147 const [error, message] = await Promise.all([

TweaksSindre Sorhusbefore adoption698a1b8

line 148why, one step back
148 assertRejects(finishedStream(stream)),

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 149why, one step back
149 subprocess.getOneMessage(),

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 150why, one step back
150 ]);

TweaksSindre Sorhusbefore adoption698a1b8

lines 151–156why, one step back
151 assert.equal(message, foobarString);
152 assert.equal(error.cause, cause);153 assertProcessNormalExit(error);154 assert.equal(subprocess.stdout.errored, cause);155 assert.equal(subprocess.stderr.readableEnded, true);156 assertWritableAborted(subprocess.stdin);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 157why, one step back
157

TweaksSindre Sorhusbefore adoption698a1b8

line 158why, one step back
158 await assertSubprocessError(subprocess, error);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 159–160why, one step back
159};
160

TweaksSindre Sorhusbefore adoption698a1b8

lines 161–162why, one step back
161test('subprocess.stdout error + no more writes -> .readable() error + subprocess fail', () => testStdoutError('readable'));
162test('subprocess.stdout error + no more writes -> .duplex() error + subprocess fail', () => testStdoutError('duplex'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 163why, one step back
163

TweaksSindre Sorhusbefore adoption698a1b8

line 164why, one step back
164const testStdinAbortWrites = async methodName => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 165–170why, one step back
165 const subprocess = getReadWriteSubprocess();
166 const stream = subprocess[methodName]();167168 subprocess.stdout.destroy();169 subprocess.stdin.end(foobarString);170

TweaksSindre Sorhusbefore adoption698a1b8

lines 171–176why, one step back
171 const error = await assertRejects(finishedStream(stream));
172 assertProcessNormalExit(error, 1);173 assert.equal(subprocess.stdin.writableEnded, true);174 assertReadableAborted(subprocess.stdout);175 assert.equal(subprocess.stderr.readableEnded, true);176 await assertSubprocessError(subprocess, error);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 177–178why, one step back
177};
178

TweaksSindre Sorhusbefore adoption698a1b8

lines 179–180why, one step back
179test('subprocess.stdout abort + more writes -> .readable() error + subprocess fail', () => testStdinAbortWrites('readable'));
180test('subprocess.stdout abort + more writes -> .duplex() error + subprocess fail', () => testStdinAbortWrites('duplex'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 181why, one step back
181

TweaksSindre Sorhusbefore adoption698a1b8

line 182why, one step back
182const testStdinErrorWrites = async methodName => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 183–189why, one step back
183 const subprocess = getReadWriteSubprocess();
184 const stream = subprocess[methodName]();185186 const cause = new Error(foobarString);187 subprocess.stdout.destroy(cause);188 subprocess.stdin.end(foobarString);189

TweaksSindre Sorhusbefore adoption698a1b8

lines 190–195why, one step back
190 const error = await assertStreamError(stream, {cause});
191 assertProcessNormalExit(error, 1);192 assert.equal(subprocess.stdin.writableEnded, true);193 assert.equal(subprocess.stdout.errored, cause);194 assert.equal(subprocess.stderr.readableEnded, true);195 await assertSubprocessError(subprocess, error);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 196–197why, one step back
196};
197

TweaksSindre Sorhusbefore adoption698a1b8

lines 198–199why, one step back
198test('subprocess.stdout error + more writes -> .readable() error + subprocess fail', () => testStdinErrorWrites('readable'));
199test('subprocess.stdout error + more writes -> .duplex() error + subprocess fail', () => testStdinErrorWrites('duplex'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 200why, one step back
200

TweaksSindre Sorhusbefore adoption698a1b8

line 201why, one step back
201test('.readable() can be used with Stream.pipeline()', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 202–208why, one step back
202 const subprocess = getReadableSubprocess();
203 const stream = subprocess.readable();204 const outputStream = new PassThrough();205206 await pipeline(stream, outputStream);207208 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

lines 209–210why, one step back
209 await assertStreamOutput(outputStream);
210 await assertSubprocessOutput(subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 211–212why, one step back
211});
212

TweaksSindre Sorhusbefore adoption698a1b8

line 213why, one step back
213test('.readable() can error with Stream.pipeline()', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 214–217why, one step back
214 const subprocess = execa('noop-fail.js', ['1', foobarString]);
215 const stream = subprocess.readable();216 const outputStream = new PassThrough();217

TweaksSindre Sorhusbefore adoption698a1b8

lines 218–220why, one step back
218 const error = await assertRejects(pipeline(stream, outputStream));
219 assertProcessNormalExit(error, 2);220 assertLike(error, {stdout: foobarString});

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 221why, one step back
221

TweaksSindre Sorhusbefore adoption698a1b8

lines 222–224why, one step back
222 await assertStreamError(stream, error);
223 await assertStreamReadError(outputStream, error);224 await assertSubprocessError(subprocess, error);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 225–226why, one step back
225});
226

TweaksSindre Sorhusbefore adoption698a1b8

line 227why, one step back
227test('.readable() can pipe to errored stream with Stream.pipeline()', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 228–234why, one step back
228 const subprocess = getReadableSubprocess();
229 const stream = subprocess.readable();230 const outputStream = new PassThrough();231232 const cause = new Error('test');233 outputStream.destroy(cause);234

Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8

lines 235–237why, one step back
235 // Node 23 does not allow calling `stream.pipeline()` with an already errored stream
236 if (majorNodeVersion >= 23) {237 outputStream.on('error', () => {});

TweaksSindre Sorhusbefore adoption698a1b8

line 238why, one step back
238 await assertRejects(pipeline(stream, outputStream), {code: 'ERR_STREAM_UNABLE_TO_PIPE'});

Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8

line 239why, one step back
239 } else {

TweaksSindre Sorhusbefore adoption698a1b8

lines 240–241why, one step back
240 await assertPromiseError(pipeline(stream, outputStream), cause);
241 await assertRejects(finishedStream(stream));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 242why, one step back
242

TweaksSindre Sorhusbefore adoption698a1b8

lines 243–245why, one step back
243 const error = await assertStreamError(stream, cause);
244 await assertStreamReadError(outputStream, cause);245 await assertSubprocessError(subprocess, {cause: error});

Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8

line 246why, one step back
246 }

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 247–248why, one step back
247});
248

TweaksSindre Sorhusbefore adoption698a1b8

line 249why, one step back
249test('.readable() can be used with Stream.compose()', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 250–253why, one step back
250 const subprocess = getReadableSubprocess();
251 const stream = subprocess.readable();252 const outputStream = new PassThrough();253

TweaksSindre Sorhusbefore adoption698a1b8

lines 254–255why, one step back
254 await assertStreamOutput(compose(stream, outputStream));
255 await assertSubprocessOutput(subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 256–257why, one step back
256});
257

TweaksSindre Sorhusbefore adoption698a1b8

line 258why, one step back
258test('.readable() works with objectMode', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 259–260why, one step back
259 const subprocess = execa('noop.js', {stdout: outputObjectGenerator()});
260 const stream = subprocess.readable();

TweaksSindre Sorhusbefore adoption698a1b8

lines 261–262why, one step back
261 assert.equal(stream.readableObjectMode, true);
262 assert.equal(stream.readableHighWaterMark, defaultObjectHighWaterMark);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 263why, one step back
263

TweaksSindre Sorhusbefore adoption698a1b8

lines 264–265why, one step back
264 await assertStreamChunks(stream, [foobarObject]);
265 await assertSubprocessOutput(subprocess, [foobarObject]);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 266–267why, one step back
266});
267

TweaksSindre Sorhusbefore adoption698a1b8

line 268why, one step back
268test('.duplex() works with objectMode and reads', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 269–270why, one step back
269 const subprocess = getReadWriteSubprocess({stdout: outputObjectGenerator()});
270 const stream = subprocess.duplex();

TweaksSindre Sorhusbefore adoption698a1b8

lines 271–274why, one step back
271 assert.equal(stream.readableObjectMode, true);
272 assert.equal(stream.readableHighWaterMark, defaultObjectHighWaterMark);273 assert.equal(stream.writableObjectMode, false);274 assert.equal(stream.writableHighWaterMark, defaultHighWaterMark);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 275–276why, one step back
275 stream.end(foobarString);
276

TweaksSindre Sorhusbefore adoption698a1b8

lines 277–278why, one step back
277 await assertStreamChunks(stream, [foobarObject]);
278 await assertSubprocessOutput(subprocess, [foobarObject]);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 279–280why, one step back
279});
280

TweaksSindre Sorhusbefore adoption698a1b8

line 281why, one step back
281test('.readable() works with default encoding', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 282–283why, one step back
282 const subprocess = getReadableSubprocess();
283 const stream = subprocess.readable();

TweaksSindre Sorhusbefore adoption698a1b8

line 284why, one step back
284 assert.equal(stream.readableEncoding, null);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 285why, one step back
285

TweaksSindre Sorhusbefore adoption698a1b8

lines 286–287why, one step back
286 await assertStreamChunks(stream, [foobarBuffer]);
287 await assertSubprocessOutput(subprocess, foobarString);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 288–289why, one step back
288});
289

TweaksSindre Sorhusbefore adoption698a1b8

line 290why, one step back
290test('.duplex() works with default encoding', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 291–292why, one step back
291 const subprocess = getReadWriteSubprocess();
292 const stream = subprocess.duplex();

TweaksSindre Sorhusbefore adoption698a1b8

line 293why, one step back
293 assert.equal(stream.readableEncoding, null);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 294–295why, one step back
294 stream.end(foobarString);
295

TweaksSindre Sorhusbefore adoption698a1b8

lines 296–297why, one step back
296 await assertStreamChunks(stream, [foobarBuffer]);
297 await assertSubprocessOutput(subprocess, foobarString);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 298–299why, one step back
298});
299

TweaksSindre Sorhusbefore adoption698a1b8

line 300why, one step back
300test('.readable() works with encoding "utf8"', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 301–303why, one step back
301 const subprocess = getReadableSubprocess();
302 subprocess.stdout.setEncoding('utf8');303 const stream = subprocess.readable();

TweaksSindre Sorhusbefore adoption698a1b8

line 304why, one step back
304 assert.equal(stream.readableEncoding, 'utf8');

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 305why, one step back
305

TweaksSindre Sorhusbefore adoption698a1b8

lines 306–307why, one step back
306 await assertStreamChunks(stream, [foobarString]);
307 await assertSubprocessOutput(subprocess, foobarString);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 308–309why, one step back
308});
309

TweaksSindre Sorhusbefore adoption698a1b8

line 310why, one step back
310test('.duplex() works with encoding "utf8"', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 311–313why, one step back
311 const subprocess = getReadWriteSubprocess();
312 subprocess.stdout.setEncoding('utf8');313 const stream = subprocess.duplex();

TweaksSindre Sorhusbefore adoption698a1b8

line 314why, one step back
314 assert.equal(stream.readableEncoding, 'utf8');

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 315–316why, one step back
315 stream.end(foobarBuffer);
316

TweaksSindre Sorhusbefore adoption698a1b8

lines 317–318why, one step back
317 await assertStreamChunks(stream, [foobarString]);
318 await assertSubprocessOutput(subprocess, foobarString);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 319–320why, one step back
319});
320

TweaksSindre Sorhusbefore adoption698a1b8

line 321why, one step back
321test('.readable() has the right highWaterMark', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 322–323why, one step back
322 const subprocess = execa('noop.js');
323 const stream = subprocess.readable();

TweaksSindre Sorhusbefore adoption698a1b8

line 324why, one step back
324 assert.equal(stream.readableHighWaterMark, defaultHighWaterMark);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 325–327why, one step back
325 await text(stream);
326});327

TweaksSindre Sorhusbefore adoption698a1b8

line 328why, one step back
328test('.readable() can iterate over lines', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 329why, one step back
329 const subprocess = execa('noop-fd.js', ['1', simpleFull]);

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 330why, one step back
330 const lines = await Array.fromAsync(subprocess.readable({binary: false, preserveNewlines: false}));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 331–332why, one step back
331
332 const expectedLines = ['aaa', 'bbb', 'ccc'];

TweaksSindre Sorhusbefore adoption698a1b8

lines 333–334why, one step back
333 assert.deepEqual(lines, expectedLines);
334 await assertSubprocessOutput(subprocess, simpleFull);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 335–336why, one step back
335});
336

TweaksSindre Sorhusbefore adoption698a1b8

line 337why, one step back
337test('.readable() can wait for data', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 338–340why, one step back
338 const subprocess = execa('noop.js', {stdout: getOutputsAsyncGenerator([foobarString, foobarString])(false, true)});
339 const stream = subprocess.readable();340

TweaksSindre Sorhusbefore adoption698a1b8

line 341why, one step back
341 assert.equal(stream.read(), null);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 342why, one step back
342 await once(stream, 'readable');

TweaksSindre Sorhusbefore adoption698a1b8

lines 343–344why, one step back
343 assert.equal(stream.read().toString(), foobarString);
344 assert.equal(stream.read(), null);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 345why, one step back
345 await once(stream, 'readable');

TweaksSindre Sorhusbefore adoption698a1b8

lines 346–347why, one step back
346 assert.equal(stream.read().toString(), foobarString);
347 assert.equal(stream.read(), null);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 348why, one step back
348 await once(stream, 'readable');

TweaksSindre Sorhusbefore adoption698a1b8

line 349why, one step back
349 assert.equal(stream.read(), null);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 350–351why, one step back
350
351 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

line 352why, one step back
352 await assertSubprocessOutput(subprocess, `${foobarString}${foobarString}`);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 353–354why, one step back
353});
354

TweaksSindre Sorhusbefore adoption698a1b8

line 355why, one step back
355const testBufferData = async methodName => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 356–360why, one step back
356 const chunk = '.'.repeat(defaultHighWaterMark).repeat(2);
357 const subprocess = getReadWriteSubprocess();358 const stream = subprocess[methodName]();359 subprocess.stdin.end(chunk);360

TweaksSindre Sorhusbefore adoption698a1b8

lines 361–362why, one step back
361 await assertStreamOutput(stream, chunk);
362 await assertSubprocessOutput(subprocess, chunk);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 363–364why, one step back
363};
364

TweaksSindre Sorhusbefore adoption698a1b8

lines 365–366why, one step back
365test('.readable() can buffer data', () => testBufferData('readable'));
366test('.duplex() can buffer data', () => testBufferData('duplex'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 367why, one step back
367

TweaksSindre Sorhusbefore adoption698a1b8

line 368why, one step back
368const assertDataEvents = async (stream, subprocess) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 369why, one step back
369 const [output] = await once(stream, 'data');

TweaksSindre Sorhusbefore adoption698a1b8

line 370why, one step back
370 assert.equal(output.toString(), foobarString);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 371–372why, one step back
371
372 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

line 373why, one step back
373 await assertSubprocessOutput(subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 374–375why, one step back
374};
375

TweaksSindre Sorhusbefore adoption698a1b8

line 376why, one step back
376test('.readable() can be read with "data" events', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 377–379why, one step back
377 const subprocess = getReadableSubprocess();
378 const stream = subprocess.readable();379

TweaksSindre Sorhusbefore adoption698a1b8

line 380why, one step back
380 await assertDataEvents(stream, subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 381–382why, one step back
381});
382

TweaksSindre Sorhusbefore adoption698a1b8

line 383why, one step back
383test('.duplex() can be read with "data" events', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 384–387why, one step back
384 const subprocess = getReadWriteSubprocess();
385 const stream = subprocess.duplex();386 stream.end(foobarString);387

TweaksSindre Sorhusbefore adoption698a1b8

line 388why, one step back
388 await assertDataEvents(stream, subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 389–390why, one step back
389});
390

TweaksSindre Sorhusbefore adoption698a1b8

line 391why, one step back
391const assertPause = async (stream, subprocess) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 392–394why, one step back
392 const onceData = once(stream, 'data');
393 stream.pause();394

TweaksSindre Sorhusbefore adoption698a1b8

line 395why, one step back
395 assert.equal(stream.readableLength, 0);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 396–400why, one step back
396 do {
397 // eslint-disable-next-line no-await-in-loop398 await setTimeout(10);399 } while (stream.readableLength === 0);400

TweaksSindre Sorhusbefore adoption698a1b8

line 401why, one step back
401 assert.ok(!await Promise.race([onceData, false]));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 402–404why, one step back
402
403 stream.resume();404 const [output] = await onceData;

TweaksSindre Sorhusbefore adoption698a1b8

line 405why, one step back
405 assert.equal(output.toString(), foobarString);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 406–407why, one step back
406
407 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

line 408why, one step back
408 await assertSubprocessOutput(subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 409–410why, one step back
409};
410

TweaksSindre Sorhusbefore adoption698a1b8

line 411why, one step back
411test('.readable() can be paused', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 412–414why, one step back
412 const subprocess = getReadableSubprocess();
413 const stream = subprocess.readable();414

TweaksSindre Sorhusbefore adoption698a1b8

line 415why, one step back
415 await assertPause(stream, subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 416–417why, one step back
416});
417

TweaksSindre Sorhusbefore adoption698a1b8

line 418why, one step back
418test('.duplex() can be paused', async () => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 419–422why, one step back
419 const subprocess = getReadWriteSubprocess();
420 const stream = subprocess.duplex();421 stream.end(foobarString);422

TweaksSindre Sorhusbefore adoption698a1b8

line 423why, one step back
423 await assertPause(stream, subprocess);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 424–427why, one step back
424});
425426// This feature does not work on Node 18.427// @todo: remove after dropping support for Node 18.

Runs CI tests on Node 23 (#1169)ehmickybefore adoptione330bd8

line 428why, one step back
428if (majorNodeVersion >= 20) {

TweaksSindre Sorhusbefore adoption698a1b8

line 429why, one step back
429 const testHighWaterMark = async methodName => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 430–442why, one step back
430 const subprocess = execa('stdin.js');
431 const stream = subprocess[methodName]();432433 let count = 0;434 const onPause = once(subprocess.stdout, 'pause');435 for (; !subprocess.stdout.isPaused(); count += 1) {436 subprocess.stdin.write('.');437 // eslint-disable-next-line no-await-in-loop438 await Promise.race([onPause, once(subprocess.stdout, 'data')]);439 }440441 const expectedCount = defaultObjectHighWaterMark + 1;442 const expectedOutput = '.'.repeat(expectedCount);

TweaksSindre Sorhusbefore adoption698a1b8

line 443why, one step back
443 assert.equal(count, expectedCount);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 444why, one step back
444 subprocess.stdin.end();

TweaksSindre Sorhusbefore adoption698a1b8

lines 445–446why, one step back
445 await assertStreamOutput(stream, expectedOutput);
446 await assertSubprocessOutput(subprocess, expectedOutput);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 447–448why, one step back
447 };
448

TweaksSindre Sorhusbefore adoption698a1b8

lines 449–450why, one step back
449 test('.readable() pauses its buffering when too high', () => testHighWaterMark('readable'));
450 test('.duplex() pauses its buffering when too high', () => testHighWaterMark('duplex'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 451–452why, one step back
451}
452

TweaksSindre Sorhusbefore adoption698a1b8

line 453why, one step back
453const testBigOutput = async methodName => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 454–457why, one step back
454 const bigChunk = '.'.repeat(1e6);
455 const subprocess = execa('stdin.js', {input: bigChunk});456 const stream = subprocess[methodName]();457

TweaksSindre Sorhusbefore adoption698a1b8

lines 458–459why, one step back
458 await assertStreamOutput(stream, bigChunk);
459 await assertSubprocessOutput(subprocess, bigChunk);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 460–461why, one step back
460};
461

TweaksSindre Sorhusbefore adoption698a1b8

lines 462–463why, one step back
462test('.readable() with big output', () => testBigOutput('readable'));
463test('.duplex() with big output', () => testBigOutput('duplex'));