Skip to content
Myr

writable.js

This file

Path

test/convert/writable.js

401 lines · 13.8 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 2–7why, one step back
2import {once} from 'node:events';
3import {compose, Readable, Writable} from 'node:stream';4import {pipeline} from 'node:stream/promises';5import {text} from 'node:stream/consumers';6import {setTimeout, scheduler} from 'node:timers/promises';7import {promisify} from 'node:util';

TweaksSindre Sorhusbefore adoption698a1b8

lines 8–9why, one step back
8import test from 'node:test';
9import {assertRejects, assertLike} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 10–30why, one step back
10import {execa} from '../../index.js';
11import {setFixtureDirectory} from '../helpers/fixtures-directory.js';12import {13 finishedStream,14 assertWritableAborted,15 assertProcessNormalExit,16 assertStreamOutput,17 assertStreamError,18 assertSubprocessOutput,19 assertSubprocessError,20 assertPromiseError,21 getWritableSubprocess,22 getReadableSubprocess,23 getReadWriteSubprocess,24} from '../helpers/convert.js';25import {26 foobarString,27 foobarBuffer,28 foobarObject,29 foobarObjectString,30} from '../helpers/input.js';

Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)Sindre Sorhusbefore adoption487a3a4

line 31why, one step back
31import {getStdio, prematureClose, fullReadableStdio} from '../helpers/stdio.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 32–40why, one step back
32import {
33 throwingGenerator,34 serializeGenerator,35 noopAsyncGenerator,36} from '../helpers/generator.js';37import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js';3839setFixtureDirectory();40

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 42–44why, one step back
42 const subprocess = getWritableSubprocess();
43 const stream = subprocess.writable();44

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 49–52why, one step back
49
50 stream.end(foobarString);5152 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

line 53why, one step back
53 await assertSubprocessOutput(subprocess, foobarString, 2);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 54–55why, one step back
54});
55

TweaksSindre Sorhusbefore adoption698a1b8

line 56why, one step back
56const testWritableDefault = async (fdNumber, to, options) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 57–62why, one step back
57 const subprocess = execa('stdin-fd.js', [`${fdNumber}`], options);
58 const stream = subprocess.writable({to});5960 stream.end(foobarString);6162 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 64–65why, one step back
64};
65

TweaksSindre Sorhusbefore adoption698a1b8

lines 66–70why, one step back
66test('.writable() can use stdin', () => testWritableDefault(0, 'stdin', {}));
67test('.writable() can use stdio[*]', () => testWritableDefault(3, 'fd3', fullReadableStdio()));68test('.writable() can use stdio[*] with { value: "pipe", input: true }', () => testWritableDefault(3, 'fd3', getStdio(3, {value: 'pipe', input: true})));69test('.writable() can use stdio[*] with [{ value: "pipe", input: true }, "pipe"]', () => testWritableDefault(3, 'fd3', getStdio(3, [{value: 'pipe', input: true}, 'pipe'])));70test('.writable() uses stdin by default', () => testWritableDefault(0, undefined, {}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 71why, one step back
71

TweaksSindre Sorhusbefore adoption698a1b8

line 72why, one step back
72test('.writable() hangs until ended', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 73–80why, one step back
73 const subprocess = getReadWriteSubprocess();
74 const stream = subprocess.writable();7576 stream.write(foobarString);77 await setTimeout(1e2);78 stream.end();7980 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 82–83why, one step back
82});
83

TweaksSindre Sorhusbefore adoption698a1b8

line 84why, one step back
84test('.duplex() hangs until ended', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 85–91why, one step back
85 const subprocess = getReadWriteSubprocess();
86 const stream = subprocess.duplex();8788 stream.write(foobarString);89 await setTimeout(1e2);90 stream.end();91

TweaksSindre Sorhusbefore adoption698a1b8

lines 92–93why, one step back
92 await assertStreamOutput(stream);
93 await assertSubprocessOutput(subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 94–95why, one step back
94});
95

TweaksSindre Sorhusbefore adoption698a1b8

line 96why, one step back
96const testEarlySuccess = async (methodName, hasWrites) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 97–99why, one step back
97 const subprocess = hasWrites ? getReadableSubprocess() : execa('empty.js');
98 const stream = subprocess[methodName]();99

TweaksSindre Sorhusbefore adoption698a1b8

lines 100–105why, one step back
100 const error = await assertRejects(finishedStream(stream));
101 assertLike(error, prematureClose);102 assertWritableAborted(subprocess.stdin);103 assert.equal(subprocess.stdout.readableEnded, true);104 assert.equal(subprocess.stderr.readableEnded, true);105 await assertSubprocessOutput(subprocess, hasWrites ? foobarString : '');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 106–107why, one step back
106};
107

TweaksSindre Sorhusbefore adoption698a1b8

lines 108–111why, one step back
108test('subprocess early success with no writes -> .writable() abort', () => testEarlySuccess('writable', false));
109test('subprocess early success with no writes -> .duplex() abort', () => testEarlySuccess('duplex', false));110test('subprocess early success with writes -> .writable() abort', () => testEarlySuccess('writable', true));111test('subprocess early success with writes -> .duplex() abort', () => testEarlySuccess('duplex', true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 112why, one step back
112

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 114–118why, one step back
114 const subprocess = getWritableSubprocess();
115 const stream = subprocess.writable();116117 stream.destroy();118

TweaksSindre Sorhusbefore adoption698a1b8

lines 119–125why, one step back
119 const error = await assertRejects(finishedStream(stream));
120 assertLike(error, prematureClose);121 assertProcessNormalExit(error);122 assertWritableAborted(subprocess.stdin);123 assert.equal(subprocess.stdout.readableEnded, true);124 assert.equal(subprocess.stderr.readableEnded, true);125 await assertSubprocessError(subprocess, error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 126–127why, one step back
126});
127

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 129–134why, one step back
129 const subprocess = getWritableSubprocess();
130 const stream = subprocess.writable();131132 const cause = new Error(foobarString);133 stream.destroy(cause);134

TweaksSindre Sorhusbefore adoption698a1b8

lines 135–140why, one step back
135 const error = await assertStreamError(stream, {cause});
136 assertProcessNormalExit(error);137 assert.equal(subprocess.stdin.errored, cause);138 assert.equal(subprocess.stdout.readableEnded, true);139 assert.equal(subprocess.stderr.readableEnded, true);140 await assertSubprocessError(subprocess, error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 141–142why, one step back
141});
142

TweaksSindre Sorhusbefore adoption698a1b8

line 143why, one step back
143test('.writable() EPIPE error -> subprocess success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 144–150why, one step back
144 const subprocess = getWritableSubprocess();
145 const stream = subprocess.writable();146147 const error = new Error(foobarString);148 error.code = 'EPIPE';149 stream.destroy(error);150

TweaksSindre Sorhusbefore adoption698a1b8

lines 151–154why, one step back
151 await assertStreamError(stream, error);
152 assert.equal(subprocess.stdin.errored, error);153 assert.equal(subprocess.stdout.readableEnded, true);154 assert.equal(subprocess.stderr.readableEnded, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 155–157why, one step back
155 await subprocess;
156});157

TweaksSindre Sorhusbefore adoption698a1b8

line 158why, one step back
158test('subprocess.stdin end -> .writable() end + subprocess success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 159–164why, one step back
159 const subprocess = getReadWriteSubprocess();
160 const stream = subprocess.writable();161162 subprocess.stdin.end(foobarString);163164 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 166–167why, one step back
166});
167

TweaksSindre Sorhusbefore adoption698a1b8

line 168why, one step back
168test('subprocess.stdin end -> .duplex() end + subprocess success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 169–173why, one step back
169 const subprocess = getReadWriteSubprocess();
170 const stream = subprocess.duplex();171172 subprocess.stdin.end(foobarString);173

TweaksSindre Sorhusbefore adoption698a1b8

lines 174–175why, one step back
174 await assertStreamOutput(stream);
175 await assertSubprocessOutput(subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 176–177why, one step back
176});
177

TweaksSindre Sorhusbefore adoption698a1b8

line 178why, one step back
178const testStdinAbort = async methodName => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 179–183why, one step back
179 const subprocess = getReadWriteSubprocess();
180 const stream = subprocess[methodName]();181182 subprocess.stdin.destroy();183

TweaksSindre Sorhusbefore adoption698a1b8

lines 184–192why, one step back
184 const error = await assertRejects(finishedStream(stream));
185 assertLike(error, prematureClose);186 assertWritableAborted(subprocess.stdin);187 assert.equal(subprocess.stdout.readableEnded, true);188 assert.equal(subprocess.stderr.readableEnded, true);189 const subprocessError = await assertRejects(subprocess);190 assertLike(subprocessError, prematureClose);191 assertLike(subprocessError.cause, prematureClose);192 assertProcessNormalExit(subprocessError);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 193–194why, one step back
193};
194

TweaksSindre Sorhusbefore adoption698a1b8

lines 195–196why, one step back
195test('subprocess.stdin abort -> .writable() error + subprocess fail', () => testStdinAbort('writable'));
196test('subprocess.stdin abort -> .duplex() error + subprocess fail', () => testStdinAbort('duplex'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 197why, one step back
197

TweaksSindre Sorhusbefore adoption698a1b8

line 198why, one step back
198const testStdinError = async methodName => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 199–204why, one step back
199 const subprocess = getReadWriteSubprocess();
200 const stream = subprocess[methodName]();201202 const cause = new Error(foobarString);203 subprocess.stdin.destroy(cause);204

TweaksSindre Sorhusbefore adoption698a1b8

lines 205–210why, one step back
205 const error = await assertStreamError(stream, {cause});
206 assertProcessNormalExit(error);207 assert.equal(subprocess.stdin.errored, cause);208 assert.equal(subprocess.stderr.readableEnded, true);209 assert.equal(subprocess.stdout.readableEnded, true);210 await assertSubprocessError(subprocess, error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 213–214why, one step back
213test('subprocess.stdin error -> .writable() error + subprocess fail', () => testStdinError('writable'));
214test('subprocess.stdin error -> .duplex() error + subprocess fail', () => testStdinError('duplex'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 215why, one step back
215

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 217–224why, one step back
217 const subprocess = getWritableSubprocess();
218 const inputStream = Readable.from([foobarString]);219 const stream = subprocess.writable();220221 await pipeline(inputStream, stream);222223 await finishedStream(inputStream);224 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

line 225why, one step back
225 await assertSubprocessOutput(subprocess, foobarString, 2);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 229–232why, one step back
229 const subprocess = execa('noop-stdin-fail.js', ['2']);
230 const inputStream = Readable.from([foobarString]);231 const stream = subprocess.writable();232

TweaksSindre Sorhusbefore adoption698a1b8

lines 233–235why, one step back
233 const error = await assertRejects(pipeline(inputStream, stream));
234 assertProcessNormalExit(error, 2);235 assert.equal(error.stderr, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 236–237why, one step back
236
237 await finishedStream(inputStream);

TweaksSindre Sorhusbefore adoption698a1b8

lines 238–239why, one step back
238 await assertStreamError(stream, error);
239 await assertSubprocessError(subprocess, error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 240–241why, one step back
240});
241

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 243–249why, one step back
243 const subprocess = getWritableSubprocess();
244 const inputStream = Readable.from([foobarString]);245 const stream = subprocess.writable();246247 const cause = new Error('test');248 inputStream.destroy(cause);249

TweaksSindre Sorhusbefore adoption698a1b8

lines 250–251why, one step back
250 await assertPromiseError(pipeline(inputStream, stream), cause);
251 await assertRejects(finishedStream(stream));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 252why, one step back
252

TweaksSindre Sorhusbefore adoption698a1b8

lines 253–255why, one step back
253 await assertStreamError(inputStream, cause);
254 const error = await assertStreamError(stream, cause);255 await assertSubprocessError(subprocess, {cause: error});

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 259–263why, one step back
259 const subprocess = getWritableSubprocess();
260 const inputStream = Readable.from([foobarString]);261 const stream = subprocess.writable();262263 await finishedStream(compose(inputStream, stream));

TweaksSindre Sorhusbefore adoption698a1b8

line 264why, one step back
264 await assertSubprocessOutput(subprocess, foobarString, 2);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 268–269why, one step back
268 const subprocess = getReadWriteSubprocess({stdin: serializeGenerator(true, true)});
269 const stream = subprocess.writable();

TweaksSindre Sorhusbefore adoption698a1b8

lines 270–271why, one step back
270 assert.equal(stream.writableObjectMode, true);
271 assert.equal(stream.writableHighWaterMark, defaultObjectHighWaterMark);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 272–274why, one step back
272 stream.end(foobarObject);
273274 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 276–277why, one step back
276});
277

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 279–280why, one step back
279 const subprocess = getReadWriteSubprocess({stdin: serializeGenerator(true, true)});
280 const stream = subprocess.duplex();

TweaksSindre Sorhusbefore adoption698a1b8

lines 281–284why, one step back
281 assert.equal(stream.readableObjectMode, false);
282 assert.equal(stream.readableHighWaterMark, defaultHighWaterMark);283 assert.equal(stream.writableObjectMode, true);284 assert.equal(stream.writableHighWaterMark, defaultObjectHighWaterMark);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 285–286why, one step back
285 stream.end(foobarObject);
286

TweaksSindre Sorhusbefore adoption698a1b8

lines 287–288why, one step back
287 await assertStreamOutput(stream, foobarObjectString);
288 await assertSubprocessOutput(subprocess, foobarObjectString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 294why, one step back
294 assert.equal(stream.writableHighWaterMark, defaultHighWaterMark);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 295–298why, one step back
295 stream.end();
296 await finishedStream(stream);297});298

TweaksSindre Sorhusbefore adoption698a1b8

line 299why, one step back
299const writeUntilFull = async (stream, subprocess) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 300–302why, one step back
300 const size = stream.writableHighWaterMark / 2;
301 const chunk = '.'.repeat(size);302

TweaksSindre Sorhusbefore adoption698a1b8

lines 303–306why, one step back
303 assert.equal(subprocess.stdin.writableLength, 0);
304 assert.equal(stream.writableLength, 0);305 assert.equal(subprocess.stdin.writableNeedDrain, false);306 assert.equal(stream.writableNeedDrain, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 307why, one step back
307

TweaksSindre Sorhusbefore adoption698a1b8

lines 308–312why, one step back
308 assert.ok(stream.write(chunk));
309 assert.equal(subprocess.stdin.writableLength, size);310 assert.equal(stream.writableLength, 0);311 assert.equal(subprocess.stdin.writableNeedDrain, false);312 assert.equal(stream.writableNeedDrain, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 313why, one step back
313

TweaksSindre Sorhusbefore adoption698a1b8

lines 314–318why, one step back
314 assert.ok(stream.write(chunk));
315 assert.equal(subprocess.stdin.writableLength, size * 2);316 assert.equal(stream.writableLength, size);317 assert.equal(subprocess.stdin.writableNeedDrain, true);318 assert.equal(stream.writableNeedDrain, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 319why, one step back
319

TweaksSindre Sorhusbefore adoption698a1b8

lines 320–324why, one step back
320 assert.ok(!stream.write(chunk));
321 assert.equal(subprocess.stdin.writableLength, size * 2);322 assert.equal(stream.writableLength, size * 2);323 assert.equal(subprocess.stdin.writableNeedDrain, true);324 assert.equal(stream.writableNeedDrain, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 325–331why, one step back
325
326 await once(stream, 'drain');327 stream.end();328329 return '.'.repeat(size * 3);330};331

TweaksSindre Sorhusbefore adoption698a1b8

line 332why, one step back
332test('.writable() waits when its buffer is full', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 333–335why, one step back
333 const subprocess = getReadWriteSubprocess({stdin: noopAsyncGenerator(false, true)});
334 const stream = subprocess.writable();335

TweaksSindre Sorhusbefore adoption698a1b8

line 336why, one step back
336 const expectedOutput = await writeUntilFull(stream, subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 337why, one step back
337

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 339–340why, one step back
339});
340

TweaksSindre Sorhusbefore adoption698a1b8

line 341why, one step back
341test('.duplex() waits when its buffer is full', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 342–344why, one step back
342 const subprocess = getReadWriteSubprocess({stdin: noopAsyncGenerator(false, true)});
343 const stream = subprocess.duplex();344

TweaksSindre Sorhusbefore adoption698a1b8

line 345why, one step back
345 const expectedOutput = await writeUntilFull(stream, subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 346why, one step back
346

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 349–350why, one step back
349});
350

TweaksSindre Sorhusbefore adoption698a1b8

line 351why, one step back
351const testPropagateError = async methodName => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 352–355why, one step back
352 const cause = new Error(foobarString);
353 const subprocess = getReadWriteSubprocess({stdin: throwingGenerator(cause)()});354 const stream = subprocess[methodName]();355 stream.end('.');

TweaksSindre Sorhusbefore adoption698a1b8

line 356why, one step back
356 await assertStreamError(stream, {cause});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 357–358why, one step back
357};
358

TweaksSindre Sorhusbefore adoption698a1b8

lines 359–360why, one step back
359test('.writable() propagates write errors', () => testPropagateError('writable'));
360test('.duplex() propagates write errors', () => testPropagateError('duplex'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 361why, one step back
361

TweaksSindre Sorhusbefore adoption698a1b8

line 362why, one step back
362const testWritev = async (methodName, waitForStream) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 363–367why, one step back
363 const subprocess = getReadWriteSubprocess({stdin: noopAsyncGenerator()});
364 const stream = subprocess[methodName]();365366 const chunk = '.'.repeat(stream.writableHighWaterMark);367 stream.write(chunk);

TweaksSindre Sorhusbefore adoption698a1b8

line 368why, one step back
368 assert.equal(stream.writableNeedDrain, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 369–373why, one step back
369
370 const [writeInOneTick] = await Promise.race([371 Promise.all([true, promisify(stream.write.bind(stream))(chunk)]),372 Promise.all([false, scheduler.yield()]),373 ]);

TweaksSindre Sorhusbefore adoption698a1b8

line 374why, one step back
374 assert.equal(writeInOneTick, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 375–379why, one step back
375
376 stream.end();377 await waitForStream(stream);378};379

TweaksSindre Sorhusbefore adoption698a1b8

lines 380–381why, one step back
380test('.writable() can use .writev()', () => testWritev('writable', finishedStream));
381test('.duplex() can use .writev()', () => testWritev('duplex', text));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 382why, one step back
382

TweaksSindre Sorhusbefore adoption698a1b8

line 383why, one step back
383test('.writable() can set encoding', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 384–389why, one step back
384 const subprocess = getReadWriteSubprocess();
385 const stream = subprocess.writable();386387 stream.end(foobarBuffer.toString('hex'), 'hex');388389 await finishedStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 391–392why, one step back
391});
392

TweaksSindre Sorhusbefore adoption698a1b8

line 393why, one step back
393test('.duplex() can set encoding', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 394–398why, one step back
394 const subprocess = getReadWriteSubprocess();
395 const stream = subprocess.duplex();396397 stream.end(foobarBuffer.toString('hex'), 'hex');398

TweaksSindre Sorhusbefore adoption698a1b8

lines 399–400why, one step back
399 await assertStreamOutput(stream);
400 await assertSubprocessOutput(subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 401why, one step back
401});