pipe.js
This file
Path
test/pipe.js
80 lines · 4.2 KiB · JavaScript
Last changed by
Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
History of this fileTake it
Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 1–2why, one step back1import {PassThrough, Readable} from 'node:stream';2import {spawn} from 'node:child_process';Refactor tests (#628)ehmickybefore adoption30ecc81
line 3why, one step back3import {readFile, rm} from 'node:fs/promises';Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 4–11why, one step back4import tempfile from 'tempfile';5import test from 'ava';6import getStream from 'get-stream';7import {execa} from '../index.js';8import {setFixtureDir} from './helpers/fixtures-dir.js';910setFixtureDir();11Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 12–13why, one step back12const pipeToProcess = async (t, index, funcName) => {13 const {stdout} = await execa('noop-fd.js', [`${index}`, 'test'], {all: true})[funcName](execa('stdin.js'));Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 14–16why, one step back14 t.is(stdout, 'test');15};16Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 17–20why, one step back17test('pipeStdout() can pipe to Execa child processes', pipeToProcess, 1, 'pipeStdout');18test('pipeStderr() can pipe to Execa child processes', pipeToProcess, 2, 'pipeStderr');19test('pipeAll() can pipe stdout to Execa child processes', pipeToProcess, 1, 'pipeAll');20test('pipeAll() can pipe stderr to Execa child processes', pipeToProcess, 2, 'pipeAll');Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
line 21why, one step back21Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 22why, one step back22const pipeToStream = async (t, index, funcName) => {Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
line 23why, one step back23 const stream = new PassThrough();Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 24–26why, one step back24 const result = await execa('noop-fd.js', [`${index}`, 'test'], {all: true})[funcName](stream);25 t.is(result.stdio[index], 'test');26 t.is(await getStream(stream), 'test');Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 27–28why, one step back27};28Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 29–32why, one step back29test('pipeStdout() can pipe to streams', pipeToStream, 1, 'pipeStdout');30test('pipeStderr() can pipe to streams', pipeToStream, 2, 'pipeStderr');31test('pipeAll() can pipe stdout to streams', pipeToStream, 1, 'pipeAll');32test('pipeAll() can pipe stderr to streams', pipeToStream, 2, 'pipeAll');Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
line 33why, one step back33Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 34why, one step back34const pipeToFile = async (t, index, funcName) => {Refactor tests (#628)ehmickybefore adoption30ecc81
line 35why, one step back35 const file = tempfile();Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 36–38why, one step back36 const result = await execa('noop-fd.js', [`${index}`, 'test'], {all: true})[funcName](file);37 t.is(result.stdio[index], 'test');38 t.is(await readFile(file, 'utf8'), 'test');Refactor tests (#628)ehmickybefore adoption30ecc81
line 39why, one step back39 await rm(file);Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 40–41why, one step back40};41Fix `.pipeStdout(filePath)` tests (#602)ehmickybefore adoptionff22803
line 42why, one step back42// `test.serial()` is due to a race condition: `execa(...).pipe*(file)` might resolve before the file stream has resolvedAdd `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 43–46why, one step back43test.serial('pipeStdout() can pipe to files', pipeToFile, 1, 'pipeStdout');44test.serial('pipeStderr() can pipe to files', pipeToFile, 2, 'pipeStderr');45test.serial('pipeAll() can pipe stdout to files', pipeToFile, 1, 'pipeAll');46test.serial('pipeAll() can pipe stderr to files', pipeToFile, 2, 'pipeAll');Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 47–48why, one step back4748const invalidTarget = (t, funcName, getTarget) => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 49why, one step back49 t.throws(() => execa('empty.js', {all: true})[funcName](getTarget()), {Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 50–71why, one step back50 message: /a stream or an Execa child process/,51 });52};5354test('pipeStdout() can only pipe to writable streams', invalidTarget, 'pipeStdout', () => new Readable());55test('pipeStderr() can only pipe to writable streams', invalidTarget, 'pipeStderr', () => new Readable());56test('pipeAll() can only pipe to writable streams', invalidTarget, 'pipeAll', () => new Readable());57test('pipeStdout() cannot pipe to non-processes', invalidTarget, 'pipeStdout', () => ({stdin: new PassThrough()}));58test('pipeStderr() cannot pipe to non-processes', invalidTarget, 'pipeStderr', () => ({stdin: new PassThrough()}));59test('pipeAll() cannot pipe to non-processes', invalidTarget, 'pipeStderr', () => ({stdin: new PassThrough()}));60test('pipeStdout() cannot pipe to non-Execa processes', invalidTarget, 'pipeStdout', () => spawn('node', ['--version']));61test('pipeStderr() cannot pipe to non-Execa processes', invalidTarget, 'pipeStderr', () => spawn('node', ['--version']));62test('pipeAll() cannot pipe to non-Execa processes', invalidTarget, 'pipeStderr', () => spawn('node', ['--version']));6364const invalidSource = (t, funcName) => {65 t.false(funcName in execa('noop.js', {stdout: 'ignore', stderr: 'ignore'}));66};6768test('Must set "stdout" option to "pipe" to use pipeStdout()', invalidSource, 'pipeStdout');69test('Must set "stderr" option to "pipe" to use pipeStderr()', invalidSource, 'pipeStderr');70test('Must set "stdout" or "stderr" option to "pipe" to use pipeAll()', invalidSource, 'pipeAll');71Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 72–73why, one step back72const invalidPipeToProcess = async (t, index, funcName) => {73 t.throws(() => execa('noop-fd.js', [`${index}`, 'test'], {all: true})[funcName](execa('stdin.js', {stdin: 'ignore'})), {Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 74–77why, one step back74 message: /stdin must be available/,75 });76};77Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 78–80why, one step back78test('Must set target "stdin" option to "pipe" to use pipeStdout()', invalidPipeToProcess, 1, 'pipeStdout');79test('Must set target "stdin" option to "pipe" to use pipeStderr()', invalidPipeToProcess, 2, 'pipeStderr');80test('Must set target "stdin" option to "pipe" to use pipeAll()', invalidPipeToProcess, 1, 'pipeAll');