Skip to content
Myr

direction.js

This file

Path

test/stdio/direction.js

51 lines · 2.8 KiB · JavaScript

Last changed by

Fix passing the same file or stream to both `stdout` and `stderr` (#1004)ehmickybefore adoptionea889c7

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–6why, 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';

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 7why, one step back
7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

Fix passing the same file or stream to both `stdout` and `stderr` (#1004)ehmickybefore adoptionea889c7

line 8why, one step back
8import {foobarString} from '../helpers/input.js';

Split files (#837)ehmickybefore adoption672c2d7

line 9why, one step back
9

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 10why, one step back
10setFixtureDirectory();

Split files (#837)ehmickybefore adoption672c2d7

lines 11–30why, one step back
11
12const testInputOutput = (t, stdioOption, execaMethod) => {13 t.throws(() => {14 execaMethod('empty.js', getStdio(3, [new ReadableStream(), stdioOption]));15 }, {message: /readable and writable/});16};1718test('Cannot pass both readable and writable values to stdio[*] - WritableStream', testInputOutput, new WritableStream(), execa);19test('Cannot pass both readable and writable values to stdio[*] - 1', testInputOutput, 1, execa);20test('Cannot pass both readable and writable values to stdio[*] - 2', testInputOutput, 2, execa);21test('Cannot pass both readable and writable values to stdio[*] - process.stdout', testInputOutput, process.stdout, execa);22test('Cannot pass both readable and writable values to stdio[*] - process.stderr', testInputOutput, process.stderr, execa);23test('Cannot pass both readable and writable values to stdio[*] - WritableStream - sync', testInputOutput, new WritableStream(), execaSync);24test('Cannot pass both readable and writable values to stdio[*] - 1 - sync', testInputOutput, 1, execaSync);25test('Cannot pass both readable and writable values to stdio[*] - 2 - sync', testInputOutput, 2, execaSync);26test('Cannot pass both readable and writable values to stdio[*] - process.stdout - sync', testInputOutput, process.stdout, execaSync);27test('Cannot pass both readable and writable values to stdio[*] - process.stderr - sync', testInputOutput, process.stderr, execaSync);2829const testAmbiguousDirection = async (t, execaMethod) => {30 const [filePathOne, filePathTwo] = [tempfile(), tempfile()];

Fix passing the same file or stream to both `stdout` and `stderr` (#1004)ehmickybefore adoptionea889c7

line 31why, one step back
31 await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, [{file: filePathOne}, {file: filePathTwo}]));

Split files (#837)ehmickybefore adoption672c2d7

lines 32–33why, one step back
32 t.deepEqual(
33 await Promise.all([readFile(filePathOne, 'utf8'), readFile(filePathTwo, 'utf8')]),

Fix passing the same file or stream to both `stdout` and `stderr` (#1004)ehmickybefore adoptionea889c7

line 34why, one step back
34 [foobarString, foobarString],

Split files (#837)ehmickybefore adoption672c2d7

lines 35–41why, one step back
35 );
36 await Promise.all([rm(filePathOne), rm(filePathTwo)]);37};3839test('stdio[*] default direction is output', testAmbiguousDirection, execa);40test('stdio[*] default direction is output - sync', testAmbiguousDirection, execaSync);41

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

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

Split files (#837)ehmickybefore adoption672c2d7

line 43why, one step back
43 const filePath = tempfile();

Fix passing the same file or stream to both `stdout` and `stderr` (#1004)ehmickybefore adoptionea889c7

line 44why, one step back
44 await writeFile(filePath, foobarString);

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

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

Fix passing the same file or stream to both `stdout` and `stderr` (#1004)ehmickybefore adoptionea889c7

line 46why, one step back
46 t.is(stdout, `${foobarString}${foobarString}`);

Split files (#837)ehmickybefore adoption672c2d7

lines 47–51why, one step back
47 await rm(filePath);
48};4950test('stdin ambiguous direction is influenced by other values', testAmbiguousMultiple, 0);51test('stdio[*] ambiguous direction is influenced by other values', testAmbiguousMultiple, 3);