max-buffer.js
This file
Path
test/stream/max-buffer.js
108 lines · 4.6 KiB · JavaScript
Last changed by
Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–11why, one step back1import {Buffer} from 'node:buffer';2import test from 'ava';3import getStream from 'get-stream';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {fullStdio} from '../helpers/stdio.js';78setFixtureDir();910const maxBuffer = 10;11Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 12–13why, one step back12const testMaxBufferSuccess = async (t, fdNumber, all) => {13 await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, maxBuffer, all}));Split files (#837)ehmickybefore adoption672c2d7
lines 14–29why, one step back14};1516test('maxBuffer does not affect stdout if too high', testMaxBufferSuccess, 1, false);17test('maxBuffer does not affect stderr if too high', testMaxBufferSuccess, 2, false);18test('maxBuffer does not affect stdio[*] if too high', testMaxBufferSuccess, 3, false);19test('maxBuffer does not affect all if too high', testMaxBufferSuccess, 1, true);2021test('maxBuffer uses killSignal', async t => {22 const {isTerminated, signal} = await t.throwsAsync(23 execa('noop-forever.js', ['.'.repeat(maxBuffer + 1)], {maxBuffer, killSignal: 'SIGINT'}),24 {message: /maxBuffer exceeded/},25 );26 t.true(isTerminated);27 t.is(signal, 'SIGINT');28});29Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 30why, one step back30const testMaxBufferLimit = async (t, fdNumber, all) => {Split files (#837)ehmickybefore adoption672c2d7
lines 31–32why, one step back31 const length = all ? maxBuffer * 2 : maxBuffer;32 const result = await t.throwsAsync(Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 33why, one step back33 execa('max-buffer.js', [`${fdNumber}`, `${length + 1}`], {...fullStdio, maxBuffer, all}),Split files (#837)ehmickybefore adoption672c2d7
lines 34–35why, one step back34 {message: /maxBuffer exceeded/},35 );Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 36why, one step back36 t.is(all ? result.all : result.stdio[fdNumber], '.'.repeat(length));Split files (#837)ehmickybefore adoption672c2d7
lines 37–43why, one step back37};3839test('maxBuffer affects stdout', testMaxBufferLimit, 1, false);40test('maxBuffer affects stderr', testMaxBufferLimit, 2, false);41test('maxBuffer affects stdio[*]', testMaxBufferLimit, 3, false);42test('maxBuffer affects all', testMaxBufferLimit, 1, true);43Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 44why, one step back44const testMaxBufferEncoding = async (t, fdNumber) => {Split files (#837)ehmickybefore adoption672c2d7
line 45why, one step back45 const result = await t.throwsAsync(Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 46why, one step back46 execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'buffer'}),Split files (#837)ehmickybefore adoption672c2d7
line 47why, one step back47 );Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 48why, one step back48 const stream = result.stdio[fdNumber];Split files (#837)ehmickybefore adoption672c2d7
lines 49–56why, one step back49 t.true(stream instanceof Uint8Array);50 t.is(Buffer.from(stream).toString(), '.'.repeat(maxBuffer));51};5253test('maxBuffer works with encoding buffer and stdout', testMaxBufferEncoding, 1);54test('maxBuffer works with encoding buffer and stderr', testMaxBufferEncoding, 2);55test('maxBuffer works with encoding buffer and stdio[*]', testMaxBufferEncoding, 3);56Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 57why, one step back57const testMaxBufferHex = async (t, fdNumber) => {Split files (#837)ehmickybefore adoption672c2d7
lines 58–59why, one step back58 const halfMaxBuffer = maxBuffer / 2;59 const {stdio} = await t.throwsAsync(Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 60why, one step back60 execa('max-buffer.js', [`${fdNumber}`, `${halfMaxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'hex'}),Split files (#837)ehmickybefore adoption672c2d7
line 61why, one step back61 );Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 62why, one step back62 t.is(stdio[fdNumber], Buffer.from('.'.repeat(halfMaxBuffer)).toString('hex'));Split files (#837)ehmickybefore adoption672c2d7
lines 63–68why, one step back63};6465test('maxBuffer works with other encodings and stdout', testMaxBufferHex, 1);66test('maxBuffer works with other encodings and stderr', testMaxBufferHex, 2);67test('maxBuffer works with other encodings and stdio[*]', testMaxBufferHex, 3);68Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 69–70why, one step back69const testNoMaxBuffer = async (t, fdNumber) => {70 const subprocess = execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, buffer: false});Split files (#837)ehmickybefore adoption672c2d7
lines 71–72why, one step back71 const [result, output] = await Promise.all([72 subprocess,Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 73why, one step back73 getStream(subprocess.stdio[fdNumber]),Split files (#837)ehmickybefore adoption672c2d7
line 74why, one step back74 ]);Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 75why, one step back75 t.is(result.stdio[fdNumber], undefined);Split files (#837)ehmickybefore adoption672c2d7
lines 76–82why, one step back76 t.is(output, '.'.repeat(maxBuffer));77};7879test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1);80test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2);81test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3);82Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 83why, one step back83const testNoMaxBufferOption = async (t, fdNumber) => {Split files (#837)ehmickybefore adoption672c2d7
line 84why, one step back84 const length = maxBuffer + 1;Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 85why, one step back85 const subprocess = execa('max-buffer.js', [`${fdNumber}`, `${length}`], {...fullStdio, maxBuffer, buffer: false});Split files (#837)ehmickybefore adoption672c2d7
lines 86–87why, one step back86 const [result, output] = await Promise.all([87 subprocess,Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 88why, one step back88 getStream(subprocess.stdio[fdNumber]),Split files (#837)ehmickybefore adoption672c2d7
line 89why, one step back89 ]);Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 90why, one step back90 t.is(result.stdio[fdNumber], undefined);Split files (#837)ehmickybefore adoption672c2d7
lines 91–97why, one step back91 t.is(output, '.'.repeat(length));92};9394test('do not hit maxBuffer when `buffer` is `false` with stdout', testNoMaxBufferOption, 1);95test('do not hit maxBuffer when `buffer` is `false` with stderr', testNoMaxBufferOption, 2);96test('do not hit maxBuffer when `buffer` is `false` with stdio[*]', testNoMaxBufferOption, 3);97Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 98–99why, one step back98const testMaxBufferAbort = async (t, fdNumber) => {99 const childProcess = execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer});Split files (#837)ehmickybefore adoption672c2d7
lines 100–101why, one step back100 await Promise.all([101 t.throwsAsync(childProcess, {message: /maxBuffer exceeded/}),Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 102why, one step back102 t.throwsAsync(getStream(childProcess.stdio[fdNumber]), {code: 'ABORT_ERR'}),Split files (#837)ehmickybefore adoption672c2d7
lines 103–108why, one step back103 ]);104};105106test('abort stream when hitting maxBuffer with stdout', testMaxBufferAbort, 1);107test('abort stream when hitting maxBuffer with stderr', testMaxBufferAbort, 2);108test('abort stream when hitting maxBuffer with stdio[*]', testMaxBufferAbort, 3);