concurrent.js
This file
Path
test/convert/concurrent.js
372 lines · 12.7 KiB · JavaScript
Last changed by
Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
History of this fileTake it
Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 1–54why, one step back1import {setTimeout} from 'node:timers/promises';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {foobarString} from '../helpers/input.js';6import {fullReadableStdio} from '../helpers/stdio.js';7import {8 finishedStream,9 assertStreamOutput,10 assertStreamError,11 assertStreamReadError,12 assertSubprocessOutput,13 assertSubprocessError,14 getReadWriteSubprocess,15} from '../helpers/convert.js';1617setFixtureDir();1819const endStream = async stream => {20 stream.end(foobarString);21 await setTimeout(0);22};2324// eslint-disable-next-line max-params25const endSameWritable = async (t, stream, secondStream, subprocess, fdNumber) => {26 await endStream(stream);27 t.true(subprocess.stdio[fdNumber].writable);2829 await endStream(secondStream);30 t.false(subprocess.stdio[fdNumber].writable);31};3233// eslint-disable-next-line max-params34const endDifferentWritable = async (t, stream, secondStream, subprocess, fdNumber = 0, secondFdNumber = 3) => {35 await endStream(stream);36 t.false(subprocess.stdio[fdNumber].writable);37 t.true(subprocess.stdio[secondFdNumber].writable);3839 await endStream(secondStream);40 t.false(subprocess.stdio[secondFdNumber].writable);41};4243const testReadableTwice = async (t, fdNumber, from) => {44 const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString]);45 const stream = subprocess.readable({from});46 const secondStream = subprocess.readable({from});4748 await Promise.all([49 assertStreamOutput(t, stream),50 assertStreamOutput(t, secondStream),51 ]);52 await assertSubprocessOutput(t, subprocess, foobarString, fdNumber);53};54Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 55why, one step back55test('Can call .readable() twice on same file descriptor', testReadableTwice, 1);Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 56–57why, one step back56test('Can call .readable({from: "stderr"}) twice on same file descriptor', testReadableTwice, 2, 'stderr');57Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 58why, one step back58const testWritableTwice = async (t, fdNumber, to, options) => {Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
line 59why, one step back59 const subprocess = execa('stdin-fd.js', [`${fdNumber}`], options);Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
lines 60–61why, one step back60 const stream = subprocess.writable({to});61 const secondStream = subprocess.writable({to});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 62–70why, one step back6263 await Promise.all([64 finishedStream(stream),65 finishedStream(secondStream),66 endSameWritable(t, stream, secondStream, subprocess, fdNumber),67 ]);68 await assertSubprocessOutput(t, subprocess, `${foobarString}${foobarString}`);69};70Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
lines 71–72why, one step back71test('Can call .writable() twice on same file descriptor', testWritableTwice, 0, undefined, {});72test('Can call .writable({to: "fd3"}) twice on same file descriptor', testWritableTwice, 3, 'fd3', fullReadableStdio());Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
line 73why, one step back73Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 74why, one step back74const testDuplexTwice = async (t, fdNumber, to, options) => {Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
line 75why, one step back75 const subprocess = execa('stdin-fd.js', [`${fdNumber}`], options);Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
lines 76–77why, one step back76 const stream = subprocess.duplex({to});77 const secondStream = subprocess.duplex({to});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 78–87why, one step back7879 const expectedOutput = `${foobarString}${foobarString}`;80 await Promise.all([81 assertStreamOutput(t, stream, expectedOutput),82 assertStreamOutput(t, secondStream, expectedOutput),83 endSameWritable(t, stream, secondStream, subprocess, fdNumber),84 ]);85 await assertSubprocessOutput(t, subprocess, expectedOutput);86};87Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
lines 88–89why, one step back88test('Can call .duplex() twice on same file descriptor', testDuplexTwice, 0, undefined, {});89test('Can call .duplex({to: "fd3"}) twice on same file descriptor', testDuplexTwice, 3, 'fd3', fullReadableStdio());Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 90–92why, one step back9091test('Can call .duplex() twice on same readable file descriptor but different writable one', async t => {92 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
lines 93–94why, one step back93 const stream = subprocess.duplex();94 const secondStream = subprocess.duplex({to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 95–121why, one step back9596 const expectedOutput = `${foobarString}${foobarString}`;97 await Promise.all([98 assertStreamOutput(t, stream, expectedOutput),99 assertStreamOutput(t, secondStream, expectedOutput),100 endDifferentWritable(t, stream, secondStream, subprocess),101 ]);102 await assertSubprocessOutput(t, subprocess, expectedOutput);103});104105test('Can call .readable() twice on different file descriptors', async t => {106 const subprocess = execa('noop-both.js', [foobarString]);107 const stream = subprocess.readable();108 const secondStream = subprocess.readable({from: 'stderr'});109110 const expectedOutput = `${foobarString}\n`;111 await Promise.all([112 assertStreamOutput(t, stream, expectedOutput),113 assertStreamOutput(t, secondStream, expectedOutput),114 ]);115 await assertSubprocessOutput(t, subprocess);116 await assertSubprocessOutput(t, subprocess, foobarString, 2);117});118119test('Can call .writable() twice on different file descriptors', async t => {120 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());121 const stream = subprocess.writable();Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 122why, one step back122 const secondStream = subprocess.writable({to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 123–134why, one step back123124 await Promise.all([125 finishedStream(stream),126 finishedStream(secondStream),127 endDifferentWritable(t, stream, secondStream, subprocess),128 ]);129 await assertSubprocessOutput(t, subprocess, `${foobarString}${foobarString}`);130});131132test('Can call .duplex() twice on different file descriptors', async t => {133 const subprocess = execa('stdin-twice-both.js', ['3'], fullReadableStdio());134 const stream = subprocess.duplex();Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 135why, one step back135 const secondStream = subprocess.duplex({from: 'stderr', to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 136–161why, one step back136137 await Promise.all([138 assertStreamOutput(t, stream),139 assertStreamOutput(t, secondStream),140 endDifferentWritable(t, stream, secondStream, subprocess),141 ]);142 await assertSubprocessOutput(t, subprocess);143 await assertSubprocessOutput(t, subprocess, foobarString, 2);144});145146test('Can call .readable() and .writable()', async t => {147 const subprocess = getReadWriteSubprocess();148 const stream = subprocess.writable();149 const secondStream = subprocess.readable();150 stream.end(foobarString);151152 await Promise.all([153 finishedStream(stream),154 assertStreamOutput(t, secondStream),155 ]);156 await assertSubprocessOutput(t, subprocess);157});158159test('Can call .writable() and .duplex()', async t => {160 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());161 const stream = subprocess.duplex();Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 162why, one step back162 const secondStream = subprocess.writable({to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 163–282why, one step back163164 const expectedOutput = `${foobarString}${foobarString}`;165 await Promise.all([166 assertStreamOutput(t, stream, expectedOutput),167 finishedStream(secondStream),168 endDifferentWritable(t, stream, secondStream, subprocess),169 ]);170 await assertSubprocessOutput(t, subprocess, expectedOutput);171});172173test('Can call .readable() and .duplex()', async t => {174 const subprocess = execa('stdin-both.js');175 const stream = subprocess.duplex();176 const secondStream = subprocess.readable({from: 'stderr'});177 stream.end(foobarString);178179 await Promise.all([180 assertStreamOutput(t, stream),181 assertStreamOutput(t, secondStream),182 ]);183 await assertSubprocessOutput(t, subprocess);184 await assertSubprocessOutput(t, subprocess, foobarString, 2);185});186187test('Can error one of two .readable() on same file descriptor', async t => {188 const subprocess = execa('noop-fd.js', ['1', foobarString]);189 const stream = subprocess.readable();190 const secondStream = subprocess.readable();191 const cause = new Error(foobarString);192 stream.destroy(cause);193194 await Promise.all([195 assertStreamReadError(t, stream, cause),196 assertStreamOutput(t, secondStream),197 ]);198 await assertSubprocessOutput(t, subprocess);199});200201test('Can error both .readable() on same file descriptor', async t => {202 const subprocess = execa('noop-fd.js', ['1', foobarString]);203 const stream = subprocess.readable();204 const secondStream = subprocess.readable();205 const cause = new Error(foobarString);206 stream.destroy(cause);207 secondStream.destroy(cause);208209 const [error, secondError] = await Promise.all([210 assertStreamReadError(t, stream, {cause}),211 assertStreamReadError(t, secondStream, {cause}),212 ]);213 t.is(error, secondError);214 await assertSubprocessError(t, subprocess, error);215});216217test('Can error one of two .readable() on different file descriptors', async t => {218 const subprocess = execa('noop-both.js', [foobarString]);219 const stream = subprocess.readable();220 const secondStream = subprocess.readable({from: 'stderr'});221 const cause = new Error(foobarString);222 stream.destroy(cause);223224 const [error, secondError] = await Promise.all([225 assertStreamReadError(t, stream, {cause}),226 assertStreamReadError(t, secondStream, {cause}),227 ]);228 t.is(error, secondError);229 t.is(error.stderr, foobarString);230 await assertSubprocessError(t, subprocess, error);231});232233test('Can error both .readable() on different file descriptors', async t => {234 const subprocess = execa('noop-both.js', [foobarString]);235 const stream = subprocess.readable();236 const secondStream = subprocess.readable({from: 'stderr'});237 const cause = new Error(foobarString);238 stream.destroy(cause);239 secondStream.destroy(cause);240241 const [error, secondError] = await Promise.all([242 assertStreamReadError(t, stream, {cause}),243 assertStreamReadError(t, secondStream, {cause}),244 ]);245 t.is(error, secondError);246 await assertSubprocessError(t, subprocess, error);247});248249test('Can error one of two .writable() on same file descriptor', async t => {250 const subprocess = execa('stdin.js');251 const stream = subprocess.writable();252 const secondStream = subprocess.writable();253 const cause = new Error(foobarString);254 stream.destroy(cause);255 secondStream.end(foobarString);256257 await Promise.all([258 assertStreamError(t, stream, cause),259 finishedStream(secondStream),260 ]);261 await assertSubprocessOutput(t, subprocess);262});263264test('Can error both .writable() on same file descriptor', async t => {265 const subprocess = execa('stdin.js');266 const stream = subprocess.writable();267 const secondStream = subprocess.writable();268 const cause = new Error(foobarString);269 stream.destroy(cause);270 secondStream.destroy(cause);271272 const [error, secondError] = await Promise.all([273 assertStreamError(t, stream, {cause}),274 assertStreamError(t, secondStream, {cause}),275 ]);276 t.is(error, secondError);277 await assertSubprocessError(t, subprocess, error);278});279280test('Can error one of two .writable() on different file descriptors', async t => {281 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());282 const stream = subprocess.writable();Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 283why, one step back283 const secondStream = subprocess.writable({to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 284–299why, one step back284 const cause = new Error(foobarString);285 stream.destroy(cause);286 secondStream.end(foobarString);287288 const [error, secondError] = await Promise.all([289 assertStreamError(t, stream, {cause}),290 assertStreamError(t, secondStream, {cause}),291 ]);292 t.is(error, secondError);293 t.is(error.stdout, foobarString);294 await assertSubprocessError(t, subprocess, error);295});296297test('Can error both .writable() on different file descriptors', async t => {298 const subprocess = execa('stdin-fd-both.js', ['3'], fullReadableStdio());299 const stream = subprocess.writable();Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 300why, one step back300 const secondStream = subprocess.writable({to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 301–345why, one step back301 const cause = new Error(foobarString);302 stream.destroy(cause);303 secondStream.destroy(cause);304305 const [error, secondError] = await Promise.all([306 assertStreamError(t, stream, {cause}),307 assertStreamError(t, secondStream, {cause}),308 ]);309 t.is(error, secondError);310 await assertSubprocessError(t, subprocess, error);311});312313test('Can error one of two .duplex() on same file descriptor', async t => {314 const subprocess = execa('stdin.js');315 const stream = subprocess.duplex();316 const secondStream = subprocess.duplex();317 const cause = new Error(foobarString);318 stream.destroy(cause);319 secondStream.end(foobarString);320321 await Promise.all([322 assertStreamReadError(t, stream, cause),323 assertStreamOutput(t, secondStream),324 ]);325 await assertSubprocessOutput(t, subprocess);326});327328test('Can error both .duplex() on same file descriptor', async t => {329 const subprocess = execa('stdin.js');330 const stream = subprocess.duplex();331 const secondStream = subprocess.duplex();332 const cause = new Error(foobarString);333 stream.destroy(cause);334 secondStream.destroy(cause);335336 await Promise.all([337 assertStreamReadError(t, stream, cause),338 assertStreamReadError(t, secondStream, cause),339 ]);340 await assertSubprocessError(t, subprocess, {cause});341});342343test('Can error one of two .duplex() on different file descriptors', async t => {344 const subprocess = execa('stdin-twice-both.js', ['3'], fullReadableStdio());345 const stream = subprocess.duplex();Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 346why, one step back346 const secondStream = subprocess.duplex({from: 'stderr', to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 347–361why, one step back347 const cause = new Error(foobarString);348 stream.destroy(cause);349 secondStream.end(foobarString);350351 const [error] = await Promise.all([352 assertStreamReadError(t, secondStream, {cause}),353 assertStreamReadError(t, stream, cause),354 ]);355 t.is(error.stderr, foobarString);356 await assertSubprocessError(t, subprocess, error);357});358359test('Can error both .duplex() on different file descriptors', async t => {360 const subprocess = execa('stdin-twice-both.js', ['3'], fullReadableStdio());361 const stream = subprocess.duplex();Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91
line 362why, one step back362 const secondStream = subprocess.duplex({from: 'stderr', to: 'fd3'});Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
lines 363–372why, one step back363 const cause = new Error(foobarString);364 stream.destroy(cause);365 secondStream.destroy(cause);366367 await Promise.all([368 assertStreamReadError(t, stream, cause),369 assertStreamReadError(t, secondStream, cause),370 ]);371 await assertSubprocessError(t, subprocess, {cause});372});