writable.js
This file
Path
test/convert/writable.js
401 lines · 13.8 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
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
lines 2–7why, one step back2import {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 back8import test from 'node:test';9import {assertRejects, assertLike} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 10–30why, one step back10import {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 back31import {getStdio, prematureClose, fullReadableStdio} from '../helpers/stdio.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 32–40why, one step back32import {33 throwingGenerator,34 serializeGenerator,35 noopAsyncGenerator,36} from '../helpers/generator.js';37import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js';3839setFixtureDirectory();40TweaksSindre Sorhusbefore adoption698a1b8
line 41why, one step back41test('.writable() success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 42–44why, one step back42 const subprocess = getWritableSubprocess();43 const stream = subprocess.writable();44TweaksSindre Sorhusbefore adoption698a1b8
lines 45–48why, one step back45 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 back4950 stream.end(foobarString);5152 await finishedStream(stream);TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53 await assertSubprocessOutput(subprocess, foobarString, 2);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 54–55why, one step back54});55TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56const testWritableDefault = async (fdNumber, to, options) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 57–62why, one step back57 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 back63 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 64–65why, one step back64};65TweaksSindre Sorhusbefore adoption698a1b8
lines 66–70why, one step back66test('.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 back71TweaksSindre Sorhusbefore adoption698a1b8
line 72why, one step back72test('.writable() hangs until ended', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 73–80why, one step back73 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 back81 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 82–83why, one step back82});83TweaksSindre Sorhusbefore adoption698a1b8
line 84why, one step back84test('.duplex() hangs until ended', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 85–91why, one step back85 const subprocess = getReadWriteSubprocess();86 const stream = subprocess.duplex();8788 stream.write(foobarString);89 await setTimeout(1e2);90 stream.end();91TweaksSindre Sorhusbefore adoption698a1b8
lines 92–93why, one step back92 await assertStreamOutput(stream);93 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 94–95why, one step back94});95TweaksSindre Sorhusbefore adoption698a1b8
line 96why, one step back96const testEarlySuccess = async (methodName, hasWrites) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 97–99why, one step back97 const subprocess = hasWrites ? getReadableSubprocess() : execa('empty.js');98 const stream = subprocess[methodName]();99TweaksSindre Sorhusbefore adoption698a1b8
lines 100–105why, one step back100 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 back106};107TweaksSindre Sorhusbefore adoption698a1b8
lines 108–111why, one step back108test('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 back112TweaksSindre Sorhusbefore adoption698a1b8
line 113why, one step back113test('.writable() abort -> subprocess fail', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 114–118why, one step back114 const subprocess = getWritableSubprocess();115 const stream = subprocess.writable();116117 stream.destroy();118TweaksSindre Sorhusbefore adoption698a1b8
lines 119–125why, one step back119 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 back126});127TweaksSindre Sorhusbefore adoption698a1b8
line 128why, one step back128test('.writable() error -> subprocess fail', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 129–134why, one step back129 const subprocess = getWritableSubprocess();130 const stream = subprocess.writable();131132 const cause = new Error(foobarString);133 stream.destroy(cause);134TweaksSindre Sorhusbefore adoption698a1b8
lines 135–140why, one step back135 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 back141});142TweaksSindre Sorhusbefore adoption698a1b8
line 143why, one step back143test('.writable() EPIPE error -> subprocess success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 144–150why, one step back144 const subprocess = getWritableSubprocess();145 const stream = subprocess.writable();146147 const error = new Error(foobarString);148 error.code = 'EPIPE';149 stream.destroy(error);150TweaksSindre Sorhusbefore adoption698a1b8
lines 151–154why, one step back151 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 back155 await subprocess;156});157TweaksSindre Sorhusbefore adoption698a1b8
line 158why, one step back158test('subprocess.stdin end -> .writable() end + subprocess success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 159–164why, one step back159 const subprocess = getReadWriteSubprocess();160 const stream = subprocess.writable();161162 subprocess.stdin.end(foobarString);163164 await finishedStream(stream);TweaksSindre Sorhusbefore adoption698a1b8
line 165why, one step back165 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 166–167why, one step back166});167TweaksSindre Sorhusbefore adoption698a1b8
line 168why, one step back168test('subprocess.stdin end -> .duplex() end + subprocess success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 169–173why, one step back169 const subprocess = getReadWriteSubprocess();170 const stream = subprocess.duplex();171172 subprocess.stdin.end(foobarString);173TweaksSindre Sorhusbefore adoption698a1b8
lines 174–175why, one step back174 await assertStreamOutput(stream);175 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 176–177why, one step back176});177TweaksSindre Sorhusbefore adoption698a1b8
line 178why, one step back178const testStdinAbort = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 179–183why, one step back179 const subprocess = getReadWriteSubprocess();180 const stream = subprocess[methodName]();181182 subprocess.stdin.destroy();183TweaksSindre Sorhusbefore adoption698a1b8
lines 184–192why, one step back184 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 back193};194TweaksSindre Sorhusbefore adoption698a1b8
lines 195–196why, one step back195test('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 back197TweaksSindre Sorhusbefore adoption698a1b8
line 198why, one step back198const testStdinError = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 199–204why, one step back199 const subprocess = getReadWriteSubprocess();200 const stream = subprocess[methodName]();201202 const cause = new Error(foobarString);203 subprocess.stdin.destroy(cause);204TweaksSindre Sorhusbefore adoption698a1b8
lines 205–210why, one step back205 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 back211};212TweaksSindre Sorhusbefore adoption698a1b8
lines 213–214why, one step back213test('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 back215TweaksSindre Sorhusbefore adoption698a1b8
line 216why, one step back216test('.writable() can be used with Stream.pipeline()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 217–224why, one step back217 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 back225 await assertSubprocessOutput(subprocess, foobarString, 2);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 226–227why, one step back226});227TweaksSindre Sorhusbefore adoption698a1b8
line 228why, one step back228test('.writable() can error with Stream.pipeline()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 229–232why, one step back229 const subprocess = execa('noop-stdin-fail.js', ['2']);230 const inputStream = Readable.from([foobarString]);231 const stream = subprocess.writable();232TweaksSindre Sorhusbefore adoption698a1b8
lines 233–235why, one step back233 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 back236237 await finishedStream(inputStream);TweaksSindre Sorhusbefore adoption698a1b8
lines 238–239why, one step back238 await assertStreamError(stream, error);239 await assertSubprocessError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 240–241why, one step back240});241TweaksSindre Sorhusbefore adoption698a1b8
line 242why, one step back242test('.writable() can pipe to errored stream with Stream.pipeline()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 243–249why, one step back243 const subprocess = getWritableSubprocess();244 const inputStream = Readable.from([foobarString]);245 const stream = subprocess.writable();246247 const cause = new Error('test');248 inputStream.destroy(cause);249TweaksSindre Sorhusbefore adoption698a1b8
lines 250–251why, one step back250 await assertPromiseError(pipeline(inputStream, stream), cause);251 await assertRejects(finishedStream(stream));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 252why, one step back252TweaksSindre Sorhusbefore adoption698a1b8
lines 253–255why, one step back253 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 back256});257TweaksSindre Sorhusbefore adoption698a1b8
line 258why, one step back258test('.writable() can be used with Stream.compose()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 259–263why, one step back259 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 back264 await assertSubprocessOutput(subprocess, foobarString, 2);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 265–266why, one step back265});266TweaksSindre Sorhusbefore adoption698a1b8
line 267why, one step back267test('.writable() works with objectMode', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 268–269why, one step back268 const subprocess = getReadWriteSubprocess({stdin: serializeGenerator(true, true)});269 const stream = subprocess.writable();TweaksSindre Sorhusbefore adoption698a1b8
lines 270–271why, one step back270 assert.equal(stream.writableObjectMode, true);271 assert.equal(stream.writableHighWaterMark, defaultObjectHighWaterMark);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 272–274why, one step back272 stream.end(foobarObject);273274 await finishedStream(stream);TweaksSindre Sorhusbefore adoption698a1b8
line 275why, one step back275 await assertSubprocessOutput(subprocess, foobarObjectString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 276–277why, one step back276});277TweaksSindre Sorhusbefore adoption698a1b8
line 278why, one step back278test('.duplex() works with objectMode and writes', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 279–280why, one step back279 const subprocess = getReadWriteSubprocess({stdin: serializeGenerator(true, true)});280 const stream = subprocess.duplex();TweaksSindre Sorhusbefore adoption698a1b8
lines 281–284why, one step back281 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 back285 stream.end(foobarObject);286TweaksSindre Sorhusbefore adoption698a1b8
lines 287–288why, one step back287 await assertStreamOutput(stream, foobarObjectString);288 await assertSubprocessOutput(subprocess, foobarObjectString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 289–290why, one step back289});290TweaksSindre Sorhusbefore adoption698a1b8
line 291why, one step back291test('.writable() has the right highWaterMark', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 292–293why, one step back292 const subprocess = getReadWriteSubprocess();293 const stream = subprocess.writable();TweaksSindre Sorhusbefore adoption698a1b8
line 294why, one step back294 assert.equal(stream.writableHighWaterMark, defaultHighWaterMark);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 295–298why, one step back295 stream.end();296 await finishedStream(stream);297});298TweaksSindre Sorhusbefore adoption698a1b8
line 299why, one step back299const writeUntilFull = async (stream, subprocess) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 300–302why, one step back300 const size = stream.writableHighWaterMark / 2;301 const chunk = '.'.repeat(size);302TweaksSindre Sorhusbefore adoption698a1b8
lines 303–306why, one step back303 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 back307TweaksSindre Sorhusbefore adoption698a1b8
lines 308–312why, one step back308 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 back313TweaksSindre Sorhusbefore adoption698a1b8
lines 314–318why, one step back314 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 back319TweaksSindre Sorhusbefore adoption698a1b8
lines 320–324why, one step back320 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 back325326 await once(stream, 'drain');327 stream.end();328329 return '.'.repeat(size * 3);330};331TweaksSindre Sorhusbefore adoption698a1b8
line 332why, one step back332test('.writable() waits when its buffer is full', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 333–335why, one step back333 const subprocess = getReadWriteSubprocess({stdin: noopAsyncGenerator(false, true)});334 const stream = subprocess.writable();335TweaksSindre Sorhusbefore adoption698a1b8
line 336why, one step back336 const expectedOutput = await writeUntilFull(stream, subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 337why, one step back337TweaksSindre Sorhusbefore adoption698a1b8
line 338why, one step back338 await assertSubprocessOutput(subprocess, expectedOutput);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 339–340why, one step back339});340TweaksSindre Sorhusbefore adoption698a1b8
line 341why, one step back341test('.duplex() waits when its buffer is full', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 342–344why, one step back342 const subprocess = getReadWriteSubprocess({stdin: noopAsyncGenerator(false, true)});343 const stream = subprocess.duplex();344TweaksSindre Sorhusbefore adoption698a1b8
line 345why, one step back345 const expectedOutput = await writeUntilFull(stream, subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 346why, one step back346TweaksSindre Sorhusbefore adoption698a1b8
lines 347–348why, one step back347 await assertStreamOutput(stream, expectedOutput);348 await assertSubprocessOutput(subprocess, expectedOutput);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 349–350why, one step back349});350TweaksSindre Sorhusbefore adoption698a1b8
line 351why, one step back351const testPropagateError = async methodName => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 352–355why, one step back352 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 back356 await assertStreamError(stream, {cause});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 357–358why, one step back357};358TweaksSindre Sorhusbefore adoption698a1b8
lines 359–360why, one step back359test('.writable() propagates write errors', () => testPropagateError('writable'));360test('.duplex() propagates write errors', () => testPropagateError('duplex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 361why, one step back361TweaksSindre Sorhusbefore adoption698a1b8
line 362why, one step back362const testWritev = async (methodName, waitForStream) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 363–367why, one step back363 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 back368 assert.equal(stream.writableNeedDrain, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 369–373why, one step back369370 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 back374 assert.equal(writeInOneTick, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 375–379why, one step back375376 stream.end();377 await waitForStream(stream);378};379TweaksSindre Sorhusbefore adoption698a1b8
lines 380–381why, one step back380test('.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 back382TweaksSindre Sorhusbefore adoption698a1b8
line 383why, one step back383test('.writable() can set encoding', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 384–389why, one step back384 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 back390 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 391–392why, one step back391});392TweaksSindre Sorhusbefore adoption698a1b8
line 393why, one step back393test('.duplex() can set encoding', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 394–398why, one step back394 const subprocess = getReadWriteSubprocess();395 const stream = subprocess.duplex();396397 stream.end(foobarBuffer.toString('hex'), 'hex');398TweaksSindre Sorhusbefore adoption698a1b8
lines 399–400why, one step back399 await assertStreamOutput(stream);400 await assertSubprocessOutput(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 401why, one step back401});