Skip to content
Myr

stdio.js

This file

Path

test/helpers/stdio.js

39 lines · 1.2 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

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

lines 2–25why, one step back
2import process, {platform} from 'node:process';
3import {noopReadable} from './stream.js';45export const identity = value => value;67export const getStdio = (fdNumberOrName, stdioOption, length = 3) => {8 if (typeof fdNumberOrName === 'string') {9 return {[fdNumberOrName]: stdioOption};10 }1112 const stdio = Array.from({length}).fill('pipe');13 stdio[fdNumberOrName] = stdioOption;14 return {stdio};15};1617export const fullStdio = getStdio(3, 'pipe');18export const fullReadableStdio = () => getStdio(3, ['pipe', noopReadable()]);1920export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];2122export const prematureClose = {code: 'ERR_STREAM_PREMATURE_CLOSE'};2324const isWindows = platform === 'win32';25

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26export const assertEpipe = (stderr, fdNumber = 1) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 27why, one step back
27 if (fdNumber === 1 && !isWindows) {

TweaksSindre Sorhusbefore adoption698a1b8

line 28why, one step back
28 assert.ok(stderr.includes('EPIPE'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 29–37why, one step back
29 }
30};3132export const parseStdioOption = stdioOption => {33 const optionValue = JSON.parse(stdioOption);34 if (typeof optionValue === 'string' && optionValue in process) {35 return process[optionValue];36 }37

TweaksSindre Sorhusbefore adoption698a1b8

line 38why, one step back
38 return Array.isArray(optionValue) && typeof optionValue[0] === 'string' && optionValue[0] in process ? [process[optionValue[0]], ...optionValue.slice(1)] : optionValue;

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 39why, one step back
39};