Fix errors thrown by `.pipe()` (#854)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 4c4e882 · Browse files · 11 files·+267 added−189 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+267 added−189 removed
- tests:+126 added−101 removed
- other:+141 added−88 removed
Provenance
- Commit
46ba4b4- Tree
f793fda- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
4c4e882
11 files changed+267 added−189 removed
modified:lib/pipe/abort.js+3 added-3 removed
122345678891011121213import {aborted} from 'node:util';import {createNonCommandError} from './validate.js';import {createNonCommandError} from './throw.js';
export const unpipeOnAbort = (signal, ...args) => signal === undefined ? [] : [unpipeOnSignalAbort(signal, ...args)];
const unpipeOnSignalAbort = async (signal, sourceStream, mergedStream, {stdioStreamsGroups, options}) => {const unpipeOnSignalAbort = async (signal, {sourceStream, mergedStream, stdioStreamsGroups, sourceOptions}) => { await aborted(signal, sourceStream); await mergedStream.remove(sourceStream); const error = new Error('Pipe cancelled by `signal` option.'); throw createNonCommandError({error, stdioStreamsGroups, options}); throw createNonCommandError({error, stdioStreamsGroups, sourceOptions});};modified:lib/pipe/setup.js+26 added-11 removed
1234567788910111213141314151617181920212223242526272829303132333435363738394020414243444546262728293031import {normalizePipeArguments} from './validate.js';import {handlePipeArgumentsError} from './throw.js';import {waitForBothProcesses} from './sequence.js';import {pipeProcessStream} from './streaming.js';import {unpipeOnAbort} from './abort.js';
// Pipe a process' `stdout`/`stderr`/`stdio` into another process' `stdin`export const pipeToProcess = (sourceInfo, destination, pipeOptions) => { const promise = handlePipePromise(sourceInfo, destination, pipeOptions);export const pipeToProcess = (sourceInfo, ...args) => { const {destination, ...normalizedInfo} = normalizePipeArguments(sourceInfo, ...args); const promise = handlePipePromise({...normalizedInfo, destination}); promise.pipe = pipeToProcess.bind(undefined, {...sourceInfo, source: destination, sourcePromise: promise}); return promise;};
const handlePipePromise = async (sourceInfo, destination, {from, signal} = {}) => { const {sourcePromise, sourceStream, destinationStream} = normalizePipeArguments(destination, from, sourceInfo);const handlePipePromise = async ({ sourcePromise, sourceStream, sourceOptions, sourceError, destination, destinationStream, destinationError, signal, stdioStreamsGroups,}) => { handlePipeArgumentsError({ sourcePromise, sourceStream, sourceError, destination, destinationStream, destinationError, stdioStreamsGroups, sourceOptions, }); const maxListenersController = new AbortController(); try { const mergedStream = pipeProcessStream(sourceStream, destinationStream, maxListenersController); return await Promise.race([ waitForBothProcesses(sourcePromise, destination), ...unpipeOnAbort(signal, sourceStream, mergedStream, sourceInfo), ...unpipeOnAbort(signal, {sourceStream, mergedStream, sourceOptions, stdioStreamsGroups}), ]); } finally { maxListenersController.abort(); }};
export const dummyPipeToProcess = (source, destination) => { const promise = Promise.all([source, destination]); promise.pipe = dummyPipeToProcess.bind(undefined, promise); return promise;};added:lib/pipe/throw.js+54 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import {makeEarlyError} from '../return/error.js';import {abortSourceStream, endDestinationStream} from './streaming.js';
export const handlePipeArgumentsError = ({ sourcePromise, sourceStream, sourceError, destination, destinationStream, destinationError, stdioStreamsGroups, sourceOptions,}) => { const error = getPipeArgumentsError({sourceStream, sourceError, destinationStream, destinationError}); if (error === undefined) { return; }
preventUnhandledRejection(sourcePromise, destination); throw createNonCommandError({error, stdioStreamsGroups, sourceOptions});};
const getPipeArgumentsError = ({sourceStream, sourceError, destinationStream, destinationError}) => { if (sourceError !== undefined && destinationError !== undefined) { return destinationError; }
if (destinationError !== undefined) { abortSourceStream(sourceStream); return destinationError; }
if (sourceError !== undefined) { endDestinationStream(destinationStream); return sourceError; }};
// `.pipe()` awaits the child process promises.// When invalid arguments are passed to `.pipe()`, we throw an error, which prevents awaiting them.// We need to ensure this does not create unhandled rejections.const preventUnhandledRejection = (sourcePromise, destination) => { Promise.allSettled([sourcePromise, destination]);};
export const createNonCommandError = ({error, stdioStreamsGroups, sourceOptions}) => makeEarlyError({ error, command: PIPE_COMMAND_MESSAGE, escapedCommand: PIPE_COMMAND_MESSAGE, stdioStreamsGroups, options: sourceOptions,});
const PIPE_COMMAND_MESSAGE = 'source.pipe(destination)';modified:lib/pipe/validate.js+39 added-52 removed
1-import {STANDARD_STREAMS_ALIASES, isExecaChildProcess} from '../utils.js';2-import {makeEarlyError} from '../return/error.js';3-import {abortSourceStream, endDestinationStream} from './streaming.js';1+import {STANDARD_STREAMS_ALIASES} from '../utils.js';2 5-export const normalizePipeArguments = (destination, from, {source, sourcePromise, stdioStreamsGroups, options}) => {6- const {destinationStream, destinationError} = getDestinationStream(destination);7- const {sourceStream, sourceError} = getSourceStream(source, stdioStreamsGroups, from, options);8- handlePipeArgumentsError({sourceStream, sourceError, destinationStream, destinationError, stdioStreamsGroups, options});9- return {source, sourcePromise, sourceStream, destinationStream};3+export const normalizePipeArguments = ({source, sourcePromise, stdioStreamsGroups}, ...args) => {4+ const sourceOptions = PROCESS_OPTIONS.get(source);5+ const {6+ destination,7+ destinationStream,8+ destinationError,9+ pipeOptions: {from, signal} = {},10+ } = getDestinationStream(...args);11+ const {sourceStream, sourceError} = getSourceStream(source, stdioStreamsGroups, from, sourceOptions);12+ return {13+ sourcePromise,14+ sourceStream,15+ sourceOptions,16+ sourceError,17+ destination,18+ destinationStream,19+ destinationError,20+ signal,21+ stdioStreamsGroups,22+ };23 };24 12-const getDestinationStream = destination => {25+const getDestinationStream = (...args) => {26 try {14- if (!isExecaChildProcess(destination)) {15- throw new TypeError(`The first argument must be an Execa child process: ${destination}`);16- }17-27+ const {destination, pipeOptions} = getDestination(...args);28 const destinationStream = destination.stdin;29 if (destinationStream === null) {30 throw new TypeError('The destination child process\'s stdin must be available. Please set its "stdin" option to "pipe".');31 }32 23- return {destinationStream};33+ return {destination, destinationStream, pipeOptions};34 } catch (error) {35 return {destinationError: error};36 }37 };38 39+const getDestination = (firstArgument, ...args) => {40+ if (!PROCESS_OPTIONS.has(firstArgument)) {41+ throw new TypeError(`The first argument must be an Execa child process: ${firstArgument}`);42+ }43+44+ return {destination: firstArgument, pipeOptions: args[0]};45+};46+47+export const PROCESS_OPTIONS = new WeakMap();48+29-const getSourceStream = (source, stdioStreamsGroups, from, options) => {49+const getSourceStream = (source, stdioStreamsGroups, from, sourceOptions) => {50 try {51 const streamIndex = getStreamIndex(stdioStreamsGroups, from);52 const sourceStream = streamIndex === 'all' ? source.all : source.stdio[streamIndex];53 54 if (sourceStream === null || sourceStream === undefined) {35- throw new TypeError(getInvalidStdioOptionMessage(streamIndex, from, options));55+ throw new TypeError(getInvalidStdioOptionMessage(streamIndex, from, sourceOptions));56 }57 58 return {sourceStream};59 } catch (error) {32 unmodified lines92 93 return streamIndex;94 };95 76-const getInvalidStdioOptionMessage = (streamIndex, from, options) => {77- if (streamIndex === 'all' && !options.all) {96+const getInvalidStdioOptionMessage = (streamIndex, from, sourceOptions) => {97+ if (streamIndex === 'all' && !sourceOptions.all) {98 return 'The "all" option must be true to use `childProcess.pipe(destinationProcess, {from: "all"})`.';99 }100 81- const {optionName, optionValue} = getInvalidStdioOption(streamIndex, options);101+ const {optionName, optionValue} = getInvalidStdioOption(streamIndex, sourceOptions);102 const pipeOptions = from === undefined ? '' : `, {from: ${serializeOptionValue(from)}}`;103 return `The \`${optionName}: ${serializeOptionValue(optionValue)}\` option is incompatible with using \`childProcess.pipe(destinationProcess${pipeOptions})\`.104 Please set this option with "pipe" instead.`;105 };18 unmodified lines124 }125 126 return typeof optionValue === 'number' ? `${optionValue}` : 'Stream';127 };108-109-const handlePipeArgumentsError = ({sourceStream, sourceError, destinationStream, destinationError, stdioStreamsGroups, options}) => {110- const error = getPipeArgumentsError({sourceStream, sourceError, destinationStream, destinationError});111- if (error !== undefined) {112- throw createNonCommandError({error, stdioStreamsGroups, options});113- }114-};115-116-const getPipeArgumentsError = ({sourceStream, sourceError, destinationStream, destinationError}) => {117- if (sourceError !== undefined && destinationError !== undefined) {118- return destinationError;119- }120-121- if (destinationError !== undefined) {122- abortSourceStream(sourceStream);123- return destinationError;124- }125-126- if (sourceError !== undefined) {127- endDestinationStream(destinationStream);128- return sourceError;129- }130-};131-132-export const createNonCommandError = ({error, stdioStreamsGroups, options}) => makeEarlyError({133- error,134- command: PIPE_COMMAND_MESSAGE,135- escapedCommand: PIPE_COMMAND_MESSAGE,136- stdioStreamsGroups,137- options,138-});139-140-const PIPE_COMMAND_MESSAGE = 'source.pipe(destination)';modified:lib/return/early-error.js+6 added-13 removed
12343645678913141516171019111222232413141516171819202122232432252627282911 unmodified linesimport {ChildProcess} from 'node:child_process';import {PassThrough} from 'node:stream';import {mergePromise} from '../promise.js';import {dummyPipeToProcess} from '../pipe/setup.js';import {cleanupStdioStreams} from '../stdio/async.js';import {makeAllStream} from '../stream/all.js';import {makeEarlyError} from './error.js';
// When the child process fails to spawn.// We ensure the returned error is always both a promise and a child process.export const handleEarlyError = ({error, command, escapedCommand, stdioStreamsGroups, options}) => { cleanupStdioStreams(stdioStreamsGroups); const spawned = createDummyProcess(options); const errorInstance = makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options}); mergePromise(spawned, handleDummyPromise(errorInstance, options)); return spawned;};
const createDummyProcess = options => { const spawned = new ChildProcess(); createDummyStreams(spawned); spawned.all = makeAllStream(spawned, options); spawned.pipe = dummyPipeToProcess.bind(undefined, spawned); return spawned;
const errorInstance = makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options}); const promise = handleDummyPromise(errorInstance, options); return {spawned, promise, options, stdioStreamsGroups};};
const createDummyStreams = spawned => { const stdin = createDummyStream(); const stdout = createDummyStream(); const stderr = createDummyStream(); const all = createDummyStream(); const stdio = [stdin, stdout, stderr]; Object.assign(spawned, {stdin, stdout, stderr, stdio}); Object.assign(spawned, {stdin, stdout, stderr, all, stdio});};
const createDummyStream = () => { const stream = new PassThrough();11 unmodified linesmodified:lib/async.js+10 added-3 removed
6 unmodified lines7 import {handleInputAsync, pipeOutputAsync} from './stdio/async.js';8 import {spawnedKill} from './exit/kill.js';9 import {cleanupOnExit} from './exit/cleanup.js';10 import {pipeToProcess} from './pipe/setup.js';11+import {PROCESS_OPTIONS} from './pipe/validate.js';12 import {makeAllStream} from './stream/all.js';13 import {getSpawnedResult} from './stream/resolve.js';14 import {mergePromise} from './promise.js';15 16 export const execa = (rawFile, rawArgs, rawOptions) => {17+ const {spawned, promise, options, stdioStreamsGroups} = runExeca(rawFile, rawArgs, rawOptions);18+ spawned.pipe = pipeToProcess.bind(undefined, {source: spawned, sourcePromise: promise, stdioStreamsGroups});19+ mergePromise(spawned, promise);20+ PROCESS_OPTIONS.set(spawned, options);21+ return spawned;22+};23+24+const runExeca = (rawFile, rawArgs, rawOptions) => {25 const {file, args, command, escapedCommand, options} = handleAsyncArguments(rawFile, rawArgs, rawOptions);26 const stdioStreamsGroups = handleInputAsync(options);27 28 let spawned;13 unmodified lines42 spawned.kill = spawnedKill.bind(undefined, {kill: spawned.kill.bind(spawned), spawned, options, controller});43 spawned.all = makeAllStream(spawned, options);44 45 const promise = handlePromise({spawned, options, stdioStreamsGroups, originalStreams, command, escapedCommand, controller});37- spawned.pipe = pipeToProcess.bind(undefined, {source: spawned, sourcePromise: promise, stdioStreamsGroups, options});38- mergePromise(spawned, promise);39- return spawned;46+ return {spawned, promise, options, stdioStreamsGroups};47 };48 49 const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {50 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);46 unmodified linesmodified:lib/script.js+3 added-2 removed
1 import isPlainObject from 'is-plain-obj';2-import {isBinary, binaryToString, isChildProcess, isExecaChildProcess} from './utils.js';2+import {isBinary, binaryToString, isChildProcess} from './utils.js';3 import {execa} from './async.js';4 import {execaSync} from './sync.js';5+import {PROCESS_OPTIONS} from './pipe/validate.js';6 7 const create$ = options => {8 function $(templatesOrOptions, ...expressions) {9 if (isPlainObject(templatesOrOptions)) {36 unmodified lines46 return returnValue;47 };48 49 const scriptPipe = (pipeMethod, options, firstArgument, ...args) => {49- if (isExecaChildProcess(firstArgument)) {50+ if (PROCESS_OPTIONS.has(firstArgument)) {51 if (Object.keys(options).length > 0) {52 throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).');53 }54 152 unmodified linesmodified:lib/utils.js-4 removed
25 unmodified lines26272829303132333025 unmodified lines eventEmitter.setMaxListeners(eventEmitter.getMaxListeners() - maxListenersIncrement); });};
export const isExecaChildProcess = value => isChildProcess(value) && typeof value.then === 'function' && typeof value.pipe === 'function';
export const isChildProcess = value => value instanceof ChildProcess;added:test/pipe/template.js+106 added
1+import {spawn} from 'node:child_process';2+import test from 'ava';3+import {$} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {foobarString} from '../helpers/input.js';6+7+setFixtureDir();8+9+test('$.pipe(childProcess)', async t => {10+ const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);11+ t.is(stdout, foobarString);12+});13+14+test('$.pipe.pipe(childProcess)', async t => {15+ const {stdout} = await $`noop.js ${foobarString}`16+ .pipe($({stdin: 'pipe'})`stdin.js`)17+ .pipe($({stdin: 'pipe'})`stdin.js`);18+ t.is(stdout, foobarString);19+});20+21+test('$.pipe`command`', async t => {22+ const {stdout} = await $`noop.js ${foobarString}`.pipe`stdin.js`;23+ t.is(stdout, foobarString);24+});25+26+test('$.pipe.pipe`command`', async t => {27+ const {stdout} = await $`noop.js ${foobarString}`28+ .pipe`stdin.js`29+ .pipe`stdin.js`;30+ t.is(stdout, foobarString);31+});32+33+test('$.pipe(childProcess, pipeOptions)', async t => {34+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});35+ t.is(stdout, foobarString);36+});37+38+test('$.pipe.pipe(childProcess, pipeOptions)', async t => {39+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`40+ .pipe($({stdin: 'pipe'})`noop-stdin-fd.js 2`, {from: 'stderr'})41+ .pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});42+ t.is(stdout, foobarString);43+});44+45+test('$.pipe(pipeOptions)`command`', async t => {46+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe({from: 'stderr'})`stdin.js`;47+ t.is(stdout, foobarString);48+});49+50+test('$.pipe.pipe(pipeOptions)`command`', async t => {51+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`52+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`53+ .pipe({from: 'stderr'})`stdin.js`;54+ t.is(stdout, foobarString);55+});56+57+test('$.pipe(options)`command`', async t => {58+ const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;59+ t.is(stdout, `${foobarString}\n`);60+});61+62+test('$.pipe.pipe(options)`command`', async t => {63+ const {stdout} = await $`noop.js ${foobarString}`64+ .pipe({})`stdin.js`65+ .pipe({stripFinalNewline: false})`stdin.js`;66+ t.is(stdout, `${foobarString}\n`);67+});68+69+test('$.pipe(pipeAndProcessOptions)`command`', async t => {70+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;71+ t.is(stdout, `${foobarString}\n`);72+});73+74+test('$.pipe.pipe(pipeAndProcessOptions)`command`', async t => {75+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`76+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`77+ .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;78+ t.is(stdout, `${foobarString}\n`);79+});80+81+test('$.pipe(options)(secondOptions)`command`', async t => {82+ const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;83+ t.is(stdout, foobarString);84+});85+86+test('$.pipe.pipe(options)(secondOptions)`command`', async t => {87+ const {stdout} = await $`noop.js ${foobarString}`88+ .pipe({})({})`stdin.js`89+ .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;90+ t.is(stdout, foobarString);91+});92+93+test('$.pipe(options)(childProcess) fails', t => {94+ t.throws(() => {95+ $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`);96+ }, {message: /Please use \.pipe/});97+});98+99+const testInvalidPipe = (t, ...args) => {100+ t.throws(() => {101+ $`empty.js`.pipe(...args);102+ }, {message: /must be a template string/});103+};104+105+test('$.pipe(nonExecaChildProcess) fails', testInvalidPipe, spawn('node', ['--version']));106+test('$.pipe(false) fails', testInvalidPipe, false);modified:test/pipe/validate.js+20 added
161 unmodified lines162 163 await assertPipeError(t, pipePromise, 'an Execa child process');164 t.like(await source, {stdout: undefined});165 });166+167+test('Sets the right error message when the "all" option is incompatible - execa.execa', async t => {168+ await assertPipeError(169+ t,170+ execa('empty.js')171+ .pipe(execa('stdin.js', {all: false}))172+ .pipe(execa('empty.js'), {from: 'all'}),173+ '"all" option must be true',174+ );175+});176+177+test('Sets the right error message when the "all" option is incompatible - early error', async t => {178+ await assertPipeError(179+ t,180+ execa('empty.js', {killSignal: false})181+ .pipe(execa('stdin.js', {all: false}))182+ .pipe(execa('empty.js'), {from: 'all'}),183+ '"all" option must be true',184+ );185+});modified:test/script.js-101 removed
1-import {spawn} from 'node:child_process';1 import test from 'ava';2 import {isStream} from 'is-stream';3 import {$} from '../index.js';4 import {setFixtureDir} from './helpers/fixtures-dir.js';6-import {foobarString} from './helpers/input.js';5 6 setFixtureDir();7 8 // Workaround since some text editors or IDEs do not allow inputting \r directly356 unmodified lines365 366 test('$ stdin has no default value when stdio is set', t => {367 t.true(isStream($({stdio: 'pipe'})`noop.js`.stdin));368 });371-372-test('$.pipe(childProcess)', async t => {373- const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);374- t.is(stdout, foobarString);375-});376-377-test('$.pipe.pipe(childProcess)', async t => {378- const {stdout} = await $`noop.js ${foobarString}`379- .pipe($({stdin: 'pipe'})`stdin.js`)380- .pipe($({stdin: 'pipe'})`stdin.js`);381- t.is(stdout, foobarString);382-});383-384-test('$.pipe`command`', async t => {385- const {stdout} = await $`noop.js ${foobarString}`.pipe`stdin.js`;386- t.is(stdout, foobarString);387-});388-389-test('$.pipe.pipe`command`', async t => {390- const {stdout} = await $`noop.js ${foobarString}`391- .pipe`stdin.js`392- .pipe`stdin.js`;393- t.is(stdout, foobarString);394-});395-396-test('$.pipe(childProcess, pipeOptions)', async t => {397- const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});398- t.is(stdout, foobarString);399-});400-401-test('$.pipe.pipe(childProcess, pipeOptions)', async t => {402- const {stdout} = await $`noop-fd.js 2 ${foobarString}`403- .pipe($({stdin: 'pipe'})`noop-stdin-fd.js 2`, {from: 'stderr'})404- .pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});405- t.is(stdout, foobarString);406-});407-408-test('$.pipe(pipeOptions)`command`', async t => {409- const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe({from: 'stderr'})`stdin.js`;410- t.is(stdout, foobarString);411-});412-413-test('$.pipe.pipe(pipeOptions)`command`', async t => {414- const {stdout} = await $`noop-fd.js 2 ${foobarString}`415- .pipe({from: 'stderr'})`noop-stdin-fd.js 2`416- .pipe({from: 'stderr'})`stdin.js`;417- t.is(stdout, foobarString);418-});419-420-test('$.pipe(options)`command`', async t => {421- const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;422- t.is(stdout, `${foobarString}\n`);423-});424-425-test('$.pipe.pipe(options)`command`', async t => {426- const {stdout} = await $`noop.js ${foobarString}`427- .pipe({})`stdin.js`428- .pipe({stripFinalNewline: false})`stdin.js`;429- t.is(stdout, `${foobarString}\n`);430-});431-432-test('$.pipe(pipeAndProcessOptions)`command`', async t => {433- const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;434- t.is(stdout, `${foobarString}\n`);435-});436-437-test('$.pipe.pipe(pipeAndProcessOptions)`command`', async t => {438- const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`439- .pipe({from: 'stderr'})`noop-stdin-fd.js 2`440- .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;441- t.is(stdout, `${foobarString}\n`);442-});443-444-test('$.pipe(options)(secondOptions)`command`', async t => {445- const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;446- t.is(stdout, foobarString);447-});448-449-test('$.pipe.pipe(options)(secondOptions)`command`', async t => {450- const {stdout} = await $`noop.js ${foobarString}`451- .pipe({})({})`stdin.js`452- .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;453- t.is(stdout, foobarString);454-});455-456-test('$.pipe(options)(childProcess) fails', t => {457- t.throws(() => {458- $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`);459- }, {message: /Please use \.pipe/});460-});461-462-const testInvalidPipe = (t, ...args) => {463- t.throws(() => {464- $`empty.js`.pipe(...args);465- }, {message: /must be a template string/});466-};467-468-test('$.pipe(nonExecaChildProcess) fails', testInvalidPipe, spawn('node', ['--version']));469-test('$.pipe(false) fails', testInvalidPipe, false);