node-stream.js
This file
Path
test/stdio/node-stream.js
106 lines · 4.5 KiB · JavaScript
Last changed by
Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
History of this fileTake it
Refactor tests (#628)ehmickybefore adoption30ecc81
lines 1–8why, one step back1import {once} from 'node:events';2import {createReadStream, createWriteStream} from 'node:fs';3import {readFile, writeFile, rm} from 'node:fs/promises';4import {Readable, Writable, PassThrough} from 'node:stream';5import test from 'ava';6import tempfile from 'tempfile';7import {execa, execaSync} from '../../index.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 9why, one step back9import {getStdio} from '../helpers/stdio.js';Refactor tests (#628)ehmickybefore adoption30ecc81
lines 10–19why, one step back1011setFixtureDir();1213const createNoFileReadable = value => {14 const stream = new PassThrough();15 stream.write(value);16 stream.end();17 return stream;18};19Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 20why, one step back20const testNodeStreamSync = (t, StreamClass, index, optionName) => {Refactor tests (#628)ehmickybefore adoption30ecc81
line 21why, one step back21 t.throws(() => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 22why, one step back22 execaSync('empty.js', getStdio(index, new StreamClass()));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 23–25why, one step back23 }, {message: `The \`${optionName}\` option cannot be a Node.js stream in sync mode.`});24};25Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 26–31why, one step back26test('input cannot be a Node.js Readable - sync', testNodeStreamSync, Readable, 'input', 'input');27test('stdin cannot be a Node.js Readable - sync', testNodeStreamSync, Readable, 0, 'stdin');28test('stdio[*] cannot be a Node.js Readable - sync', testNodeStreamSync, Readable, 3, 'stdio[3]');29test('stdout cannot be a Node.js Writable - sync', testNodeStreamSync, Writable, 1, 'stdout');30test('stderr cannot be a Node.js Writable - sync', testNodeStreamSync, Writable, 2, 'stderr');31test('stdio[*] cannot be a Node.js Writable - sync', testNodeStreamSync, Writable, 3, 'stdio[3]');Refactor tests (#628)ehmickybefore adoption30ecc81
lines 32–37why, one step back3233test('input can be a Node.js Readable without a file descriptor', async t => {34 const {stdout} = await execa('stdin.js', {input: createNoFileReadable('foobar')});35 t.is(stdout, 'foobar');36});37Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 38–39why, one step back38const testNoFileStream = async (t, index, StreamClass) => {39 await t.throwsAsync(execa('empty.js', getStdio(index, new StreamClass())), {code: 'ERR_INVALID_ARG_VALUE'});Refactor tests (#628)ehmickybefore adoption30ecc81
lines 40–41why, one step back40};41Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 42–46why, one step back42test('stdin cannot be a Node.js Readable without a file descriptor', testNoFileStream, 0, Readable);43test('stdout cannot be a Node.js Writable without a file descriptor', testNoFileStream, 1, Writable);44test('stderr cannot be a Node.js Writable without a file descriptor', testNoFileStream, 2, Writable);45test('stdio[*] cannot be a Node.js Readable without a file descriptor', testNoFileStream, 3, Readable);46test('stdio[*] cannot be a Node.js Writable without a file descriptor', testNoFileStream, 3, Writable);Refactor tests (#628)ehmickybefore adoption30ecc81
line 47why, one step back47Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 48why, one step back48const testFileReadable = async (t, index) => {Refactor tests (#628)ehmickybefore adoption30ecc81
lines 49–53why, one step back49 const filePath = tempfile();50 await writeFile(filePath, 'foobar');51 const stream = createReadStream(filePath);52 await once(stream, 'open');53Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 54–55why, one step back54 const indexString = index === 'input' ? '0' : `${index}`;55 const {stdout} = await execa('stdin-fd.js', [indexString], getStdio(index, stream));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 56–60why, one step back56 t.is(stdout, 'foobar');5758 await rm(filePath);59};60Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 61–63why, one step back61test('input can be a Node.js Readable with a file descriptor', testFileReadable, 'input');62test('stdin can be a Node.js Readable with a file descriptor', testFileReadable, 0);63test('stdio[*] can be a Node.js Readable with a file descriptor', testFileReadable, 3);Refactor tests (#628)ehmickybefore adoption30ecc81
line 64why, one step back64Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 65why, one step back65const testFileWritable = async (t, index) => {Refactor tests (#628)ehmickybefore adoption30ecc81
lines 66–69why, one step back66 const filePath = tempfile();67 const stream = createWriteStream(filePath);68 await once(stream, 'open');69Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 70–71why, one step back70 await execa('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, stream));71 t.is(await readFile(filePath, 'utf8'), 'foobar');Refactor tests (#628)ehmickybefore adoption30ecc81
lines 72–75why, one step back7273 await rm(filePath);74};75Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 76–78why, one step back76test('stdout can be a Node.js Writable with a file descriptor', testFileWritable, 1);77test('stderr can be a Node.js Writable with a file descriptor', testFileWritable, 2);78test('stdio[*] can be a Node.js Writable with a file descriptor', testFileWritable, 3);Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
line 79why, one step back79Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 80why, one step back80const testLazyFileReadable = async (t, index) => {Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 81–84why, one step back81 const filePath = tempfile();82 await writeFile(filePath, 'foobar');83 const stream = createReadStream(filePath);84Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 85why, one step back85 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stream, 'pipe']));Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 86–90why, one step back86 t.is(stdout, 'foobar');8788 await rm(filePath);89};90Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 91–92why, one step back91test('stdin can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 0);92test('stdio[*] can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 3);Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
line 93why, one step back93Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 94why, one step back94const testLazyFileWritable = async (t, index) => {Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 95–97why, one step back95 const filePath = tempfile();96 const stream = createWriteStream(filePath);97Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 98–99why, one step back98 await execa('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, [stream, 'pipe']));99 t.is(await readFile(filePath, 'utf8'), 'foobar');Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 100–103why, one step back100101 await rm(filePath);102};103Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 104–106why, one step back104test('stdout can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 1);105test('stderr can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 2);106test('stdio[*] can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 3);