input-pipe.test-d.ts
This file
Path
test-d/stdio/option/input-pipe.test-d.ts
64 lines · 3.0 KiB · TypeScript
Last changed by
Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147
History of this fileTake it
Generalize `{value, input}` to any direction-ambiguous stdio value (#1249)Sindre Sorhusbefore adoption9fbf5ba
line 1why, one step back1import {Writable} from 'node:stream';Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147
line 2why, one step back2import {expectTypeOf, expectError} from 'nz';Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)Sindre Sorhusbefore adoption487a3a4
lines 3–12why, one step back3import {4 execa,5 execaSync,6 type StdinOption,7 type StdinSyncOption,8 type StdoutStderrOption,9 type StdoutStderrSyncOption,10} from '../../../index.js';1112const inputPipe = {value: 'pipe', input: true} as const;Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
lines 13–14why, one step back13const isInput = true as boolean;14const booleanInputPipe = {value: 'pipe', input: isInput} as const;Generalize `{value, input}` to any direction-ambiguous stdio value (#1249)Sindre Sorhusbefore adoption9fbf5ba
lines 15–17why, one step back15const transform = function * (line: string) {16 yield line;17};Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)Sindre Sorhusbefore adoption487a3a4
lines 18–36why, one step back1819await execa('unicorns', {stdin: inputPipe});20execaSync('unicorns', {stdin: inputPipe});21await execa('unicorns', {stdout: inputPipe});22execaSync('unicorns', {stdout: inputPipe});23await execa('unicorns', {stderr: inputPipe});24execaSync('unicorns', {stderr: inputPipe});2526await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', inputPipe]});27expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', inputPipe]}));28await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', booleanInputPipe]});29expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', booleanInputPipe]}));3031await execa('unicorns', {stdin: {value: 'pipe'}});32await execa('unicorns', {stdin: {value: 'overlapped', input: true}});33expectError(execaSync('unicorns', {stdin: {value: 'overlapped', input: true}}));3435expectError(await execa('unicorns', {stdin: {value: 'other', input: true}}));36expectError(await execa('unicorns', {stdin: {value: 'pipe', input: 'true'}}));Generalize `{value, input}` to any direction-ambiguous stdio value (#1249)Sindre Sorhusbefore adoption9fbf5ba
lines 37–42why, one step back3738// The `{value, input}` form works with any direction-ambiguous value, not just `'pipe'`/`'overlapped'`.39await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'inherit', input: true}]});40await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: new URL('file:///test'), input: true}]});41await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: {file: './example'}, input: true}]});42await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: transform, input: true}]});Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147
lines 43–44why, one step back43({value: 'inherit', input: true}) satisfies StdinOption;44({value: {file: './example'}, input: true}) satisfies StdinOption;Generalize `{value, input}` to any direction-ambiguous stdio value (#1249)Sindre Sorhusbefore adoption9fbf5ba
lines 45–47why, one step back4546// A value with a fixed direction cannot be marked as input.47expectError(await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: new Writable(), input: true}]}));Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)Sindre Sorhusbefore adoption487a3a4
line 48why, one step back48Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147
lines 49–64why, one step back49expectTypeOf(inputPipe).toBeAssignableTo<StdinOption>();50expectTypeOf(booleanInputPipe).toBeAssignableTo<StdinOption>();51expectTypeOf(inputPipe).toBeAssignableTo<StdinSyncOption>();52expectTypeOf(booleanInputPipe).toBeAssignableTo<StdinSyncOption>();53expectTypeOf(inputPipe).toBeAssignableTo<StdoutStderrOption>();54expectTypeOf(booleanInputPipe).toBeAssignableTo<StdoutStderrOption>();55expectTypeOf(inputPipe).toBeAssignableTo<StdoutStderrSyncOption>();56expectTypeOf(booleanInputPipe).toBeAssignableTo<StdoutStderrSyncOption>();57[inputPipe] satisfies StdinOption;58[booleanInputPipe] satisfies StdinOption;59[inputPipe] satisfies StdinSyncOption;60[booleanInputPipe] satisfies StdinSyncOption;61[inputPipe] satisfies StdoutStderrOption;62[booleanInputPipe] satisfies StdoutStderrOption;63[inputPipe] satisfies StdoutStderrSyncOption;64[booleanInputPipe] satisfies StdoutStderrSyncOption;