Skip to content
Myr

input.js

This file

Path

test/stdio/input.js

50 lines · 2.7 KiB · JavaScript

Last changed by

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

History of this file

Take it

Validate `input` option's type (#668)ehmickybefore adoption65742c6

lines 1–2why, one step back
1import {Buffer} from 'node:buffer';
2import {Writable} from 'node:stream';

Refactor tests (#628)ehmickybefore adoption30ecc81

line 3why, one step back
3import test from 'ava';

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 4why, one step back
4import {execa, execaSync} from '../../index.js';

Refactor tests (#628)ehmickybefore adoption30ecc81

line 5why, one step back
5import {setFixtureDir} from '../helpers/fixtures-dir.js';

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 6why, one step back
6import {runExeca, runExecaSync, runScript, runScriptSync} from '../helpers/run.js';

Refactor tests (#628)ehmickybefore adoption30ecc81

lines 7–11why, one step back
7
8setFixtureDir();910const textEncoder = new TextEncoder();11const binaryFoobar = textEncoder.encode('foobar');

Validate `input` option's type (#668)ehmickybefore adoption65742c6

lines 12–15why, one step back
12const bufferFoobar = Buffer.from(binaryFoobar);
13const arrayBufferFoobar = binaryFoobar.buffer;14const dataViewFoobar = new DataView(arrayBufferFoobar);15const uint16ArrayFoobar = new Uint16Array(arrayBufferFoobar);

Refactor tests (#628)ehmickybefore adoption30ecc81

lines 16–21why, one step back
16
17const testInput = async (t, input, execaMethod) => {18 const {stdout} = await execaMethod('stdin.js', {input});19 t.is(stdout, 'foobar');20};21

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

lines 22–27why, one step back
22test('input option can be a String', testInput, 'foobar', runExeca);
23test('input option can be a Uint8Array', testInput, binaryFoobar, runExeca);24test('input option can be a String - sync', testInput, 'foobar', runExecaSync);25test('input option can be a Uint8Array - sync', testInput, binaryFoobar, runExecaSync);26test('input option can be used with $', testInput, 'foobar', runScript);27test('input option can be used with $.sync', testInput, 'foobar', runScriptSync);

Refactor tests (#628)ehmickybefore adoption30ecc81

line 28why, one step back
28

Validate `input` option's type (#668)ehmickybefore adoption65742c6

lines 29–30why, one step back
29const testInvalidInput = async (t, input, execaMethod) => {
30 t.throws(() => {

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 31why, one step back
31 execaMethod('empty.js', {input});

Validate `input` option's type (#668)ehmickybefore adoption65742c6

lines 32–50why, one step back
32 }, {message: /a string, a Uint8Array/});
33};3435test('input option cannot be a Buffer', testInvalidInput, bufferFoobar, execa);36test('input option cannot be an ArrayBuffer', testInvalidInput, arrayBufferFoobar, execa);37test('input option cannot be a DataView', testInvalidInput, dataViewFoobar, execa);38test('input option cannot be a Uint16Array', testInvalidInput, uint16ArrayFoobar, execa);39test('input option cannot be 0', testInvalidInput, 0, execa);40test('input option cannot be false', testInvalidInput, false, execa);41test('input option cannot be null', testInvalidInput, null, execa);42test('input option cannot be a non-Readable stream', testInvalidInput, new Writable(), execa);43test('input option cannot be a Buffer - sync', testInvalidInput, bufferFoobar, execaSync);44test('input option cannot be an ArrayBuffer - sync', testInvalidInput, arrayBufferFoobar, execaSync);45test('input option cannot be a DataView - sync', testInvalidInput, dataViewFoobar, execaSync);46test('input option cannot be a Uint16Array - sync', testInvalidInput, uint16ArrayFoobar, execaSync);47test('input option cannot be 0 - sync', testInvalidInput, 0, execaSync);48test('input option cannot be false - sync', testInvalidInput, false, execaSync);49test('input option cannot be null - sync', testInvalidInput, null, execaSync);50test('input option cannot be a non-Readable stream - sync', testInvalidInput, new Writable(), execaSync);