Skip to content
Myr

sync.js

This file

Path

test/stdio/sync.js

47 lines · 4.3 KiB · JavaScript

Last changed by

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

History of this file

Take it

Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9

lines 1–47why, one step back
1import {fileURLToPath} from 'node:url';
2import process from 'node:process';3import test from 'ava';4import {execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {getStdio} from '../helpers/stdio.js';7import {noopReadable, noopWritable} from '../helpers/stream.js';89setFixtureDir();1011const getArrayMessage = singleValueName => `The \`${singleValueName}\` option cannot be set as an array`;12const getInputMessage = (singleValueName, inputName) => `The \`${singleValueName}\` and the \`${inputName}\` options cannot be both set`;1314const inputOptions = {input: ''};15const inputFileOptions = {inputFile: fileURLToPath(import.meta.url)};1617// eslint-disable-next-line max-params18const testInvalidStdioArraySync = (t, fdNumber, stdioOption, options, expectedMessage) => {19 const {message} = t.throws(() => {20 execaSync('empty.js', {...getStdio(fdNumber, stdioOption), ...options});21 });22 t.true(message.includes(expectedMessage));23};2425test('Cannot use ["inherit", "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, ['inherit', 'pipe'], {}, getArrayMessage('stdin: "inherit"'));26test('Cannot use [0, "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, [0, 'pipe'], {}, getArrayMessage('stdin: 0'));27test('Cannot use [process.stdin, "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, [process.stdin, 'pipe'], {}, getArrayMessage('stdin: Stream'));28test('Cannot use [Readable, "pipe"] with stdin, sync', testInvalidStdioArraySync, 0, [noopReadable(), 'pipe'], {}, getArrayMessage('stdin: Stream'));29test('Cannot use "inherit" + "input" with stdin, sync', testInvalidStdioArraySync, 0, 'inherit', inputOptions, getInputMessage('stdin: "inherit"', 'input'));30test('Cannot use 0 + "input" with stdin, sync', testInvalidStdioArraySync, 0, 0, inputOptions, getInputMessage('stdin: 0', 'input'));31test('Cannot use process.stdin + "input" with stdin, sync', testInvalidStdioArraySync, 0, process.stdin, inputOptions, getInputMessage('stdin: Stream', 'input'));32test('Cannot use Readable + "input" with stdin, sync', testInvalidStdioArraySync, 0, noopReadable(), inputOptions, getInputMessage('stdin: Stream', 'input'));33test('Cannot use "inherit" + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, 'inherit', inputFileOptions, getInputMessage('stdin: "inherit"', 'inputFile'));34test('Cannot use 0 + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, 0, inputFileOptions, getInputMessage('stdin: 0', 'inputFile'));35test('Cannot use process.stdin + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, process.stdin, inputFileOptions, getInputMessage('stdin: Stream', 'inputFile'));36test('Cannot use Readable + "inputFile" with stdin, sync', testInvalidStdioArraySync, 0, noopReadable(), inputFileOptions, getInputMessage('stdin: Stream', 'inputFile'));37test('Cannot use ["inherit", "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, ['inherit', 'pipe'], {}, getArrayMessage('stdout: "inherit"'));38test('Cannot use [1, "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, [1, 'pipe'], {}, getArrayMessage('stdout: 1'));39test('Cannot use [process.stdout, "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, [process.stdout, 'pipe'], {}, getArrayMessage('stdout: Stream'));40test('Cannot use [Writable, "pipe"] with stdout, sync', testInvalidStdioArraySync, 1, [noopWritable(), 'pipe'], {}, getArrayMessage('stdout: Stream'));41test('Cannot use ["inherit", "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, ['inherit', 'pipe'], {}, getArrayMessage('stderr: "inherit"'));42test('Cannot use [2, "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, [2, 'pipe'], {}, getArrayMessage('stderr: 2'));43test('Cannot use [process.stderr, "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, [process.stderr, 'pipe'], {}, getArrayMessage('stderr: Stream'));44test('Cannot use [Writable, "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, [noopWritable(), 'pipe'], {}, getArrayMessage('stderr: Stream'));45test('Cannot use ["inherit", "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, ['inherit', 'pipe'], {}, getArrayMessage('stdio[3]: "inherit"'));46test('Cannot use [3, "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, [3, 'pipe'], {}, getArrayMessage('stdio[3]: 3'));47test('Cannot use [Writable, "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, [noopWritable(), 'pipe'], {}, getArrayMessage('stdio[3]: Stream'));