Skip to content
Myr

file-descriptor.js

This file

Path

test/stdio/file-descriptor.js

44 lines · 2.0 KiB · JavaScript

Last changed by

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 2why, one step back
2import {readFile, open, rm} from 'node:fs/promises';

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–10why, one step back
4import tempfile from 'tempfile';
5import {execa, execaSync} from '../../index.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {getStdio} from '../helpers/stdio.js';89setFixtureDirectory();10

TweaksSindre Sorhusbefore adoption698a1b8

line 11why, one step back
11const testFileDescriptorOption = async (fdNumber, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 12–14why, one step back
12 const filePath = tempfile();
13 const fileDescriptor = await open(filePath, 'w');14 await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, fileDescriptor));

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15 assert.equal(await readFile(filePath, 'utf8'), 'foobar');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 16–19why, one step back
16 await rm(filePath);
17 await fileDescriptor.close();18};19

TweaksSindre Sorhusbefore adoption698a1b8

lines 20–25why, one step back
20test('pass `stdout` to a file descriptor', () => testFileDescriptorOption(1, execa));
21test('pass `stderr` to a file descriptor', () => testFileDescriptorOption(2, execa));22test('pass `stdio[*]` to a file descriptor', () => testFileDescriptorOption(3, execa));23test('pass `stdout` to a file descriptor - sync', () => testFileDescriptorOption(1, execaSync));24test('pass `stderr` to a file descriptor - sync', () => testFileDescriptorOption(2, execaSync));25test('pass `stdio[*]` to a file descriptor - sync', () => testFileDescriptorOption(3, execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 26why, one step back
26

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

lines 27–35why, one step back
27test('pass `stdout` to a file descriptor in a single-item array', async () => {
28 const filePath = tempfile();29 const fileDescriptor = await open(filePath, 'w');30 await execa('noop-fd.js', ['1', 'foobar'], {stdout: [fileDescriptor]});31 assert.equal(await readFile(filePath, 'utf8'), 'foobar');32 await rm(filePath);33 await fileDescriptor.close();34});35

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36const testStdinWrite = async fdNumber => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 37–39why, one step back
37 const subprocess = execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, 'pipe'));
38 subprocess.stdio[fdNumber].end('unicorns');39 const {stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 40why, one step back
40 assert.equal(stdout, 'unicorns');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 41–42why, one step back
41};
42

TweaksSindre Sorhusbefore adoption698a1b8

lines 43–44why, one step back
43test('you can write to subprocess.stdin', () => testStdinWrite(0));
44test('you can write to subprocess.stdio[*]', () => testStdinWrite(3));