Skip to content
Myr

direction.js

This file

Path

test/stdio/direction.js

50 lines · 2.7 KiB · JavaScript

Last changed by

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–40why, one step back
1import {readFile, writeFile, rm} from 'node:fs/promises';
2import process from 'node:process';3import test from 'ava';4import tempfile from 'tempfile';5import {execa, execaSync} from '../../index.js';6import {getStdio} from '../helpers/stdio.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';89setFixtureDir();1011const testInputOutput = (t, stdioOption, execaMethod) => {12 t.throws(() => {13 execaMethod('empty.js', getStdio(3, [new ReadableStream(), stdioOption]));14 }, {message: /readable and writable/});15};1617test('Cannot pass both readable and writable values to stdio[*] - WritableStream', testInputOutput, new WritableStream(), execa);18test('Cannot pass both readable and writable values to stdio[*] - 1', testInputOutput, 1, execa);19test('Cannot pass both readable and writable values to stdio[*] - 2', testInputOutput, 2, execa);20test('Cannot pass both readable and writable values to stdio[*] - process.stdout', testInputOutput, process.stdout, execa);21test('Cannot pass both readable and writable values to stdio[*] - process.stderr', testInputOutput, process.stderr, execa);22test('Cannot pass both readable and writable values to stdio[*] - WritableStream - sync', testInputOutput, new WritableStream(), execaSync);23test('Cannot pass both readable and writable values to stdio[*] - 1 - sync', testInputOutput, 1, execaSync);24test('Cannot pass both readable and writable values to stdio[*] - 2 - sync', testInputOutput, 2, execaSync);25test('Cannot pass both readable and writable values to stdio[*] - process.stdout - sync', testInputOutput, process.stdout, execaSync);26test('Cannot pass both readable and writable values to stdio[*] - process.stderr - sync', testInputOutput, process.stderr, execaSync);2728const testAmbiguousDirection = async (t, execaMethod) => {29 const [filePathOne, filePathTwo] = [tempfile(), tempfile()];30 await execaMethod('noop-fd.js', ['3', 'foobar'], getStdio(3, [{file: filePathOne}, {file: filePathTwo}]));31 t.deepEqual(32 await Promise.all([readFile(filePathOne, 'utf8'), readFile(filePathTwo, 'utf8')]),33 ['foobar', 'foobar'],34 );35 await Promise.all([rm(filePathOne), rm(filePathTwo)]);36};3738test('stdio[*] default direction is output', testAmbiguousDirection, execa);39test('stdio[*] default direction is output - sync', testAmbiguousDirection, execaSync);40

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 41why, one step back
41const testAmbiguousMultiple = async (t, fdNumber) => {

Split files (#837)ehmickybefore adoption672c2d7

lines 42–43why, one step back
42 const filePath = tempfile();
43 await writeFile(filePath, 'foobar');

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 44why, one step back
44 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [{file: filePath}, ['foo', 'bar']]));

Split files (#837)ehmickybefore adoption672c2d7

lines 45–50why, one step back
45 t.is(stdout, 'foobarfoobar');
46 await rm(filePath);47};4849test('stdin ambiguous direction is influenced by other values', testAmbiguousMultiple, 0);50test('stdio[*] ambiguous direction is influenced by other values', testAmbiguousMultiple, 3);