max-buffer.js
This file
Path
test/io/max-buffer.js
518 lines · 26.9 KiB · JavaScript
Last changed by
Fix CISindre Sorhusbefore adoptioncfac59f
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import {Buffer} from 'node:buffer';TweaksSindre Sorhusbefore adoption698a1b8
lines 3–4why, one step back3import {readFile, rm} from 'node:fs/promises';4import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 5why, one step back5import getStream from 'get-stream';TweaksSindre Sorhusbefore adoption698a1b8
lines 6–7why, one step back6import tempfile from 'tempfile';7import {assertThrows, assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 8–10why, one step back8import {execa, execaSync} from '../../index.js';9import {setFixtureDirectory} from '../helpers/fixtures-directory.js';10import {fullStdio} from '../helpers/stdio.js';Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 11why, one step back11import {getEarlyErrorSubprocess} from '../helpers/early-error.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 12why, one step back12import {maxBuffer, assertErrorMessage} from '../helpers/max-buffer.js';Do not disconnect IPC on `error` event on process (#1086)ehmickybefore adoptiond6f5d9a
line 13why, one step back13import {foobarArray} from '../helpers/input.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 14–19why, one step back1415setFixtureDirectory();1617const maxBufferMessage = {message: /maxBuffer exceeded/};18const maxBufferCodeSync = {code: 'ENOBUFS'};19TweaksSindre Sorhusbefore adoption698a1b8
line 20why, one step back20const runMaxBuffer = async (execaMethod, fdNumber, options) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 21why, one step back21 const error = execaMethod === execaTweaksSindre Sorhusbefore adoption698a1b8
lines 22–23why, one step back22 ? await assertRejects(getMaxBufferSubprocess(execaMethod, fdNumber, options), maxBufferMessage)23 : assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 24–25why, one step back24 getMaxBufferSubprocess(execaMethod, fdNumber, options);25 }, maxBufferCodeSync);TweaksSindre Sorhusbefore adoption698a1b8
lines 26–27why, one step back26 assert.equal(error.isMaxBuffer, true);27 assert.equal(error.maxBufferInfo, undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 28–35why, one step back28 return error;29};3031const getMaxBufferSubprocess = (execaMethod, fdNumber, {length = maxBuffer, ...options} = {}) =>32 execaMethod('max-buffer.js', [`${fdNumber}`, `${length + 1}`], {...fullStdio, maxBuffer, ...options});3334const getExpectedOutput = (length = maxBuffer) => '.'.repeat(length);35TweaksSindre Sorhusbefore adoption698a1b8
line 36why, one step back36const testMaxBufferSuccess = async (execaMethod, fdNumber, all) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 37why, one step back37 const {isMaxBuffer} = await getMaxBufferSubprocess(execaMethod, fdNumber, {all, length: maxBuffer - 1});TweaksSindre Sorhusbefore adoption698a1b8
line 38why, one step back38 assert.equal(isMaxBuffer, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 39–40why, one step back39};40TweaksSindre Sorhusbefore adoption698a1b8
lines 41–48why, one step back41test('maxBuffer does not affect stdout if too high', () => testMaxBufferSuccess(execa, 1, false));42test('maxBuffer does not affect stderr if too high', () => testMaxBufferSuccess(execa, 2, false));43test('maxBuffer does not affect stdio[*] if too high', () => testMaxBufferSuccess(execa, 3, false));44test('maxBuffer does not affect all if too high', () => testMaxBufferSuccess(execa, 1, true));45test('maxBuffer does not affect stdout if too high, sync', () => testMaxBufferSuccess(execaSync, 1, false));46test('maxBuffer does not affect stderr if too high, sync', () => testMaxBufferSuccess(execaSync, 2, false));47test('maxBuffer does not affect stdio[*] if too high, sync', () => testMaxBufferSuccess(execaSync, 3, false));48test('maxBuffer does not affect all if too high, sync', () => testMaxBufferSuccess(execaSync, 1, true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 49why, one step back49TweaksSindre Sorhusbefore adoption698a1b8
lines 50–51why, one step back50const testGracefulExit = async (fixtureName, expectedExitCode) => {51 const {isMaxBuffer, shortMessage, exitCode, signal, stdout} = await assertRejects(100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 52–54why, one step back52 execa(fixtureName, ['1', '.'.repeat(maxBuffer + 1)], {maxBuffer}),53 maxBufferMessage,54 );TweaksSindre Sorhusbefore adoption698a1b8
lines 55–59why, one step back55 assert.equal(isMaxBuffer, true);56 assertErrorMessage(shortMessage);57 assert.equal(exitCode, expectedExitCode);58 assert.equal(signal, undefined);59 assert.equal(stdout, getExpectedOutput());100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 60–61why, one step back60};61TweaksSindre Sorhusbefore adoption698a1b8
lines 62–63why, one step back62test('maxBuffer terminates stream gracefully, more writes', () => testGracefulExit('noop-repeat.js', 1));63test('maxBuffer terminates stream gracefully, no more writes', () => testGracefulExit('noop-fd.js', 0));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 64why, one step back64TweaksSindre Sorhusbefore adoption698a1b8
lines 65–66why, one step back65const testGracefulExitSync = fixtureName => {66 const {isMaxBuffer, shortMessage, exitCode, signal, stdout} = assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 67–68why, one step back67 execaSync(fixtureName, ['1', '.'.repeat(maxBuffer + 1)], {maxBuffer, killSignal: 'SIGINT'});68 }, maxBufferCodeSync);TweaksSindre Sorhusbefore adoption698a1b8
lines 69–73why, one step back69 assert.equal(isMaxBuffer, true);70 assertErrorMessage(shortMessage, {execaMethod: execaSync});71 assert.equal(exitCode, undefined);72 assert.equal(signal, 'SIGINT');73 assert.equal(stdout, getExpectedOutput());100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 74–75why, one step back74};75TweaksSindre Sorhusbefore adoption698a1b8
lines 76–77why, one step back76test('maxBuffer terminate stream with killSignal, more writes, sync', () => testGracefulExitSync('noop-repeat.js'));77test('maxBuffer terminate stream with killSignal, no more writes, sync', () => testGracefulExitSync('noop-fd.js'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 78why, one step back78TweaksSindre Sorhusbefore adoption698a1b8
line 79why, one step back79const testMaxBufferLimit = async (execaMethod, fdNumber, all) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 80why, one step back80 const length = all && execaMethod === execa ? maxBuffer * 2 : maxBuffer;TweaksSindre Sorhusbefore adoption698a1b8
lines 81–83why, one step back81 const {shortMessage, all: allOutput, stdio} = await runMaxBuffer(execaMethod, fdNumber, {all, length});82 assertErrorMessage(shortMessage, {execaMethod, fdNumber});83 assert.equal(all ? allOutput : stdio[fdNumber], getExpectedOutput(length));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 84–85why, one step back84};85TweaksSindre Sorhusbefore adoption698a1b8
lines 86–93why, one step back86test('maxBuffer truncates stdout', () => testMaxBufferLimit(execa, 1, false));87test('maxBuffer truncates stderr', () => testMaxBufferLimit(execa, 2, false));88test('maxBuffer truncates stdio[*]', () => testMaxBufferLimit(execa, 3, false));89test('maxBuffer truncates all', () => testMaxBufferLimit(execa, 1, true));90test('maxBuffer truncates stdout, sync', () => testMaxBufferLimit(execaSync, 1, false));91test('maxBuffer truncates stderr, sync', () => testMaxBufferLimit(execaSync, 2, false));92test('maxBuffer truncates stdio[*], sync', () => testMaxBufferLimit(execaSync, 3, false));93test('maxBuffer truncates all, sync', () => testMaxBufferLimit(execaSync, 1, true));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 94–96why, one step back9495const MAX_BUFFER_DEFAULT = 1e8;96TweaksSindre Sorhusbefore adoption698a1b8
line 97why, one step back97const testMaxBufferDefault = async (execaMethod, fdNumber, maxBuffer) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 98why, one step back98 const length = MAX_BUFFER_DEFAULT;TweaksSindre Sorhusbefore adoption698a1b8
lines 99–101why, one step back99 const {shortMessage, stdio} = await runMaxBuffer(execaMethod, fdNumber, {length: MAX_BUFFER_DEFAULT + 1, maxBuffer});100 assertErrorMessage(shortMessage, {execaMethod, fdNumber, length});101 assert.equal(stdio[fdNumber], getExpectedOutput(length));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 102–103why, one step back102};103TweaksSindre Sorhusbefore adoption698a1b8
lines 104–113why, one step back104test('maxBuffer has a default value with stdout', () => testMaxBufferDefault(execa, 1, undefined));105test('maxBuffer has a default value with stderr', () => testMaxBufferDefault(execa, 2, undefined));106test('maxBuffer has a default value with stdio[*]', () => testMaxBufferDefault(execa, 3, undefined));107test('maxBuffer has a default value with stdout, sync', () => testMaxBufferDefault(execaSync, 1, undefined));108test('maxBuffer has a default value with stderr, sync', () => testMaxBufferDefault(execaSync, 2, undefined));109test('maxBuffer has a default value with stdio[*], sync', () => testMaxBufferDefault(execaSync, 3, undefined));110test('maxBuffer has a default value with stdout with fd-specific options', () => testMaxBufferDefault(execa, 1, {stderr: 1e9}));111test('maxBuffer has a default value with stderr with fd-specific options', () => testMaxBufferDefault(execa, 2, {stdout: 1e9}));112test('maxBuffer has a default value with stdio[*] with fd-specific options', () => testMaxBufferDefault(execa, 3, {stdout: 1e9}));113test('maxBuffer has a default value with stdout with empty fd-specific options', () => testMaxBufferDefault(execa, 1, {}));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 114why, one step back114TweaksSindre Sorhusbefore adoption698a1b8
line 115why, one step back115const testFdSpecific = async (fdNumber, fdName, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 116why, one step back116 const length = 1;TweaksSindre Sorhusbefore adoption698a1b8
lines 117–119why, one step back117 const {shortMessage, stdio} = await runMaxBuffer(execaMethod, fdNumber, {maxBuffer: {[fdName]: length}});118 assertErrorMessage(shortMessage, {execaMethod, fdNumber, length});119 assert.equal(stdio[fdNumber], getExpectedOutput(length));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 120–121why, one step back120};121TweaksSindre Sorhusbefore adoption698a1b8
lines 122–131why, one step back122test('maxBuffer truncates file descriptors with fd-specific options, stdout', () => testFdSpecific(1, 'stdout', execa));123test('maxBuffer truncates file descriptors with fd-specific options, fd1', () => testFdSpecific(1, 'fd1', execa));124test('maxBuffer truncates file descriptors with fd-specific options, stderr', () => testFdSpecific(2, 'stderr', execa));125test('maxBuffer truncates file descriptors with fd-specific options, fd2', () => testFdSpecific(2, 'fd2', execa));126test('maxBuffer truncates file descriptors with fd-specific options, stdout, all', () => testFdSpecific(1, 'all', execa));127test('maxBuffer truncates file descriptors with fd-specific options, stderr, all', () => testFdSpecific(2, 'all', execa));128test('maxBuffer truncates file descriptors with fd-specific options, fd3', () => testFdSpecific(3, 'fd3', execa));129test('maxBuffer.stdout is used for stdout with fd-specific options, stdout, sync', () => testFdSpecific(1, 'stdout', execaSync));130test('maxBuffer.stderr is used for stderr with fd-specific options, stderr, sync', () => testFdSpecific(2, 'stderr', execaSync));131test('maxBuffer.fd3 is used for stdio[*] with fd-specific options, fd3, sync', () => testFdSpecific(3, 'fd3', execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 132why, one step back132TweaksSindre Sorhusbefore adoption698a1b8
line 133why, one step back133test('maxBuffer does not affect other file descriptors with fd-specific options', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 134why, one step back134 const {isMaxBuffer} = await getMaxBufferSubprocess(execa, 2, {maxBuffer: {stdout: 1}});TweaksSindre Sorhusbefore adoption698a1b8
line 135why, one step back135 assert.equal(isMaxBuffer, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 136–137why, one step back136});137TweaksSindre Sorhusbefore adoption698a1b8
lines 138–139why, one step back138test('maxBuffer.fd3 is invalid without stdio[3], even with ipc', () => {139 const {message} = assertThrows(() => {Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883
lines 140–141why, one step back140 execa('ipc-send-twice.js', {ipc: true, maxBuffer: {fd3: 1}});141 });TweaksSindre Sorhusbefore adoption698a1b8
line 142why, one step back142 assert.ok(message.includes('"maxBuffer.fd3" is invalid: that file descriptor does not exist.'));Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883
lines 143–144why, one step back143});144TweaksSindre Sorhusbefore adoption698a1b8
line 145why, one step back145test('maxBuffer.fd3 and maxBuffer.ipc are distinct', async () => {Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883
lines 146–153why, one step back146 const {isMaxBuffer, ipcOutput} = await execa('ipc-send-twice.js', {147 ipc: true,148 stdio: ['ignore', 'pipe', 'pipe', 'pipe'],149 maxBuffer: {150 fd3: 1,151 ipc: 2,152 },153 });TweaksSindre Sorhusbefore adoption698a1b8
lines 154–155why, one step back154 assert.equal(isMaxBuffer, false);155 assert.deepEqual(ipcOutput, foobarArray);Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883
lines 156–157why, one step back156});157TweaksSindre Sorhusbefore adoption698a1b8
line 158why, one step back158test('maxBuffer.stdout is used for other file descriptors with fd-specific options, sync', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 159why, one step back159 const length = 1;TweaksSindre Sorhusbefore adoption698a1b8
lines 160–162why, one step back160 const {shortMessage, stderr} = await runMaxBuffer(execaSync, 2, {maxBuffer: {stdout: length}});161 assertErrorMessage(shortMessage, {execaMethod: execaSync, fdNumber: 2, length});162 assert.equal(stderr, getExpectedOutput(length));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 163–164why, one step back163});164Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 165why, one step back165// `spawnSync()`'s native `maxBuffer` is `maxBuffer.stdout`, so a lower limit on another file descriptor is only enforced from the output, after the subprocess exitsTweaksSindre Sorhusbefore adoption698a1b8
line 166why, one step back166test('maxBuffer.stderr is used when lower than maxBuffer.stdout, sync', () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 167why, one step back167 const length = 3;TweaksSindre Sorhusbefore adoption698a1b8
line 168why, one step back168 const error = assertThrows(() => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 169–170why, one step back169 execaSync('noop-both.js', ['.'.repeat(maxBuffer + 1)], {maxBuffer: {stdout: 1e8, stderr: length}});170 }, maxBufferCodeSync);TweaksSindre Sorhusbefore adoption698a1b8
lines 171–177why, one step back171 assert.equal(error.isMaxBuffer, true);172 assert.equal(error.maxBufferInfo, undefined);173 assertErrorMessage(error.shortMessage, {execaMethod: execaSync, fdNumber: 2, length});174 assert.equal(error.stdout, getExpectedOutput(maxBuffer + 1));175 assert.equal(error.stderr, getExpectedOutput(length));176 assert.equal(error.signal, undefined);177 assert.equal(error.exitCode, 0);Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 178–179why, one step back178});179TweaksSindre Sorhusbefore adoption698a1b8
line 180why, one step back180test('maxBuffer.stderr is used when lower than maxBuffer.stdout', async () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 181why, one step back181 const length = 3;TweaksSindre Sorhusbefore adoption698a1b8
lines 182–188why, one step back182 const error = await assertRejects(execa('noop-both.js', ['.'.repeat(maxBuffer + 1)], {maxBuffer: {stdout: 1e8, stderr: length}}));183 assert.equal(error.isMaxBuffer, true);184 assertErrorMessage(error.shortMessage, {fdNumber: 2, length});185 assert.equal(error.stdout, getExpectedOutput(maxBuffer + 1));186 assert.equal(error.stderr, getExpectedOutput(length));187 assert.equal(error.signal, undefined);188 assert.equal(error.exitCode, 0);Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 189–190why, one step back189});190TweaksSindre Sorhusbefore adoption698a1b8
line 191why, one step back191test('maxBuffer is not hit when under each file descriptor\'s value, sync', () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 192–193why, one step back192 const length = 9;193 const {isMaxBuffer, stdout, stderr} = execaSync('noop-both.js', ['.'.repeat(length)], {maxBuffer: {stdout: 1e8, stderr: 10}});TweaksSindre Sorhusbefore adoption698a1b8
lines 194–196why, one step back194 assert.equal(isMaxBuffer, false);195 assert.equal(stdout, getExpectedOutput(length));196 assert.equal(stderr, getExpectedOutput(length));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 197–198why, one step back197});198TweaksSindre Sorhusbefore adoption698a1b8
lines 199–222why, one step back199// Like with asynchronous methods, a file descriptor which is not buffered is not limited by its own `maxBuffer` value.200// With synchronous methods, it still counts towards `maxBuffer.stdout`, which limits the total output.201const testMaxBufferNoBuffer = async execaMethod => {202 const filePath = tempfile();203 const length = 3;204 const {isMaxBuffer, stderr} = await execaMethod('noop-both.js', ['.'.repeat(length + 1)], {buffer: {stderr: false}, maxBuffer: {stderr: length}, stderr: ['pipe', {file: filePath}]});205 assert.equal(isMaxBuffer, false);206 assert.equal(stderr, undefined);207 assert.equal(await readFile(filePath, 'utf8'), `${'.'.repeat(length + 1)}\n`);208 await rm(filePath);209};210211test('maxBuffer.stderr is ignored with buffer: false', () => testMaxBufferNoBuffer(execa));212test('maxBuffer.stderr is ignored with buffer: false, sync', () => testMaxBufferNoBuffer(execaSync));213214// `spawnSync()`'s native `maxBuffer` limits the total output of all file descriptors, even when none of them is over its own limit215test('maxBuffer.stdout limits the total output, sync', () => {216 const length = 10;217 const {isMaxBuffer, shortMessage} = execaSync('noop-both.js', ['.'.repeat(length / 2)], {maxBuffer: length, reject: false});218 assert.equal(isMaxBuffer, true);219 assert.ok(shortMessage.startsWith(`Command's output was larger than ${length} bytes`));220});221222const testAll = async shouldFail => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 223–235why, one step back223 const difference = shouldFail ? 0 : 1;224 const maxBufferStdout = 2;225 const maxBufferStderr = 4 - difference;226 const {isMaxBuffer, shortMessage, stdout, stderr, all} = await execa(227 'noop-both.js',228 ['\n'.repeat(maxBufferStdout - 1), '\n'.repeat(maxBufferStderr - difference)],229 {230 maxBuffer: {stdout: maxBufferStdout, stderr: maxBufferStderr},231 all: true,232 stripFinalNewline: false,233 reject: false,234 },235 );TweaksSindre Sorhusbefore adoption698a1b8
line 236why, one step back236 assert.equal(isMaxBuffer, shouldFail);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 237why, one step back237 if (shouldFail) {TweaksSindre Sorhusbefore adoption698a1b8
line 238why, one step back238 assertErrorMessage(shortMessage, {fdNumber: 2, length: maxBufferStderr});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 239–240why, one step back239 }240TweaksSindre Sorhusbefore adoption698a1b8
lines 241–243why, one step back241 assert.equal(stdout, '\n'.repeat(maxBufferStdout));242 assert.equal(stderr, '\n'.repeat(maxBufferStderr));243 assert.equal(all, '\n'.repeat(maxBufferStdout + maxBufferStderr));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 244–245why, one step back244};245TweaksSindre Sorhusbefore adoption698a1b8
lines 246–247why, one step back246test('maxBuffer.stdout can differ from maxBuffer.stderr, combined with all, below threshold', () => testAll(false));247test('maxBuffer.stdout can differ from maxBuffer.stderr, combined with all, above threshold', () => testAll(true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 248why, one step back248TweaksSindre Sorhusbefore adoption698a1b8
lines 249–250why, one step back249const testInvalidFd = async (fdName, execaMethod) => {250 const {message} = assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 251–252why, one step back251 execaMethod('empty.js', {maxBuffer: {[fdName]: 0}});252 });TweaksSindre Sorhusbefore adoption698a1b8
line 253why, one step back253 assert.ok(message.includes(`"maxBuffer.${fdName}" is invalid`));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 254–255why, one step back254};255TweaksSindre Sorhusbefore adoption698a1b8
lines 256–263why, one step back256test('maxBuffer.stdin is invalid', () => testInvalidFd('stdin', execa));257test('maxBuffer.fd0 is invalid', () => testInvalidFd('fd0', execa));258test('maxBuffer.other is invalid', () => testInvalidFd('other', execa));259test('maxBuffer.fd10 is invalid', () => testInvalidFd('fd10', execa));260test('maxBuffer.stdin is invalid, sync', () => testInvalidFd('stdin', execaSync));261test('maxBuffer.fd0 is invalid, sync', () => testInvalidFd('fd0', execaSync));262test('maxBuffer.other is invalid, sync', () => testInvalidFd('other', execaSync));263test('maxBuffer.fd10 is invalid, sync', () => testInvalidFd('fd10', execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 264why, one step back264Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 265–268why, one step back265// These tests need the subprocess to have written its output before the timeout kills it, which is only guaranteed if the timeout leaves room for the subprocess to start. On a busy machine, starting Node.js can take over a second.266const SYNC_TIMEOUT = 1e4;267268// A file descriptor limit lower than `maxBuffer.stdout` does not stop the subprocess with synchronous methods, so the subprocess can still time out afterwardsTweaksSindre Sorhusbefore adoption698a1b8
line 269why, one step back269const testMaxBufferTimeoutSync = (fdNumber, fdName) => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 270why, one step back270 const length = 3;TweaksSindre Sorhusbefore adoption698a1b8
line 271why, one step back271 const error = assertThrows(() => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 272–273why, one step back272 execaSync('max-buffer-forever.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, timeout: SYNC_TIMEOUT, maxBuffer: {[fdName]: length}});273 }, {code: 'ETIMEDOUT'});TweaksSindre Sorhusbefore adoption698a1b8
lines 274–279why, one step back274 assert.equal(error.timedOut, true);275 assert.equal(error.isMaxBuffer, false);276 assert.equal(error.maxBufferInfo, undefined);277 assert.ok(!Object.hasOwn(error.cause, 'maxBufferInfo'));278 assert.ok(error.shortMessage.startsWith(`Command timed out after ${SYNC_TIMEOUT} milliseconds`));279 assert.equal(error.stdio[fdNumber], getExpectedOutput(length));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 280–281why, one step back280};281TweaksSindre Sorhusbefore adoption698a1b8
lines 282–283why, one step back282test('timeout is reported instead of maxBuffer.stderr, sync', () => testMaxBufferTimeoutSync(2, 'stderr'));283test('timeout is reported instead of maxBuffer.fd3, sync', () => testMaxBufferTimeoutSync(3, 'fd3'));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 284why, one step back284TweaksSindre Sorhusbefore adoption698a1b8
lines 285–286why, one step back285test('timeout does not truncate output under maxBuffer.stderr, sync', () => {286 const {timedOut, isMaxBuffer, stderr} = assertThrows(() => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 287–288why, one step back287 execaSync('max-buffer-forever.js', ['2', `${maxBuffer}`], {timeout: SYNC_TIMEOUT, maxBuffer: {stderr: maxBuffer}});288 }, {code: 'ETIMEDOUT'});TweaksSindre Sorhusbefore adoption698a1b8
lines 289–291why, one step back289 assert.equal(timedOut, true);290 assert.equal(isMaxBuffer, false);291 assert.equal(stderr, getExpectedOutput(maxBuffer));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 292–294why, one step back292});293294// `maxBuffer.stdout` is enforced by `spawnSync()` itself, which stops the subprocess before it can time outTweaksSindre Sorhusbefore adoption698a1b8
line 295why, one step back295test('maxBuffer.stdout is reported before timeout, sync', () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 296why, one step back296 const length = 3;TweaksSindre Sorhusbefore adoption698a1b8
line 297why, one step back297 const error = assertThrows(() => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 298–299why, one step back298 execaSync('max-buffer-forever.js', ['1', `${maxBuffer}`], {timeout: SYNC_TIMEOUT, maxBuffer: {stdout: length}});299 }, maxBufferCodeSync);TweaksSindre Sorhusbefore adoption698a1b8
lines 300–304why, one step back300 assert.equal(error.timedOut, false);301 assert.equal(error.isMaxBuffer, true);302 assert.equal(error.maxBufferInfo, undefined);303 assertErrorMessage(error.shortMessage, {execaMethod: execaSync, length});304 assert.equal(error.stdout, getExpectedOutput(length));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 305–306why, one step back305});306TweaksSindre Sorhusbefore adoption698a1b8
line 307why, one step back307test('maxBuffer.stderr is reported with a non-zero exit code, sync', () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 308why, one step back308 const length = 3;TweaksSindre Sorhusbefore adoption698a1b8
line 309why, one step back309 const error = assertThrows(() => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 310–311why, one step back310 execaSync('noop-both-fail.js', ['.'.repeat(maxBuffer)], {maxBuffer: {stdout: 1e8, stderr: length}});311 });TweaksSindre Sorhusbefore adoption698a1b8
lines 312–317why, one step back312 assert.equal(error.isMaxBuffer, true);313 assert.equal(error.maxBufferInfo, undefined);314 assertErrorMessage(error.shortMessage, {execaMethod: execaSync, fdNumber: 2, length});315 assert.equal(error.exitCode, 1);316 assert.equal(error.stdout, getExpectedOutput(maxBuffer));317 assert.equal(error.stderr, getExpectedOutput(length));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 318–319why, one step back318});319TweaksSindre Sorhusbefore adoption698a1b8
line 320why, one step back320test('maxBuffer.stderr works with reject false, sync', () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 321–322why, one step back321 const length = 3;322 const {failed, isMaxBuffer, maxBufferInfo, shortMessage, stderr} = execaSync('noop-fd.js', ['2', '.'.repeat(maxBuffer)], {maxBuffer: {stdout: 1e8, stderr: length}, reject: false});TweaksSindre Sorhusbefore adoption698a1b8
lines 323–327why, one step back323 assert.equal(failed, true);324 assert.equal(isMaxBuffer, true);325 assert.equal(maxBufferInfo, undefined);326 assertErrorMessage(shortMessage, {execaMethod: execaSync, fdNumber: 2, length});327 assert.equal(stderr, getExpectedOutput(length));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 328–329why, one step back328});329TweaksSindre Sorhusbefore adoption698a1b8
line 330why, one step back330test('maxBuffer.stderr works with lines, sync', () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 331why, one step back331 const length = 3;TweaksSindre Sorhusbefore adoption698a1b8
line 332why, one step back332 const {isMaxBuffer, stderr} = assertThrows(() => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 333–334why, one step back333 execaSync('noop-both.js', ['.'.repeat(maxBuffer)], {maxBuffer: {stdout: 1e8, stderr: length}, lines: true});334 }, maxBufferCodeSync);TweaksSindre Sorhusbefore adoption698a1b8
lines 335–336why, one step back335 assert.equal(isMaxBuffer, true);336 assert.deepEqual(stderr, [getExpectedOutput(length)]);Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 337–338why, one step back337});338TweaksSindre Sorhusbefore adoption698a1b8
line 339why, one step back339test('maxBuffer.stdout is an upper bound for maxBuffer.stderr, sync', () => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 340why, one step back340 const length = 3;TweaksSindre Sorhusbefore adoption698a1b8
line 341why, one step back341 const {isMaxBuffer, shortMessage, stderr} = assertThrows(() => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 342–343why, one step back342 execaSync('noop-fd.js', ['2', '.'.repeat(maxBuffer)], {maxBuffer: {stdout: length, stderr: 1e8}});343 }, maxBufferCodeSync);TweaksSindre Sorhusbefore adoption698a1b8
lines 344–346why, one step back344 assert.equal(isMaxBuffer, true);345 assertErrorMessage(shortMessage, {execaMethod: execaSync, fdNumber: 2, length});346 assert.equal(stderr, getExpectedOutput(length));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 347–348why, one step back347});348TweaksSindre Sorhusbefore adoption698a1b8
lines 349–350why, one step back349test('maxBuffer.stderr is not reported on spawn errors, sync', () => {350 const {code, isMaxBuffer} = assertThrows(() => {Fix CISindre Sorhusbefore adoptioncfac59f
line 351why, one step back351 execaSync('empty.js', {cwd: 'does_not_exist', maxBuffer: {stderr: 1}});Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 352why, one step back352 });TweaksSindre Sorhusbefore adoption698a1b8
lines 353–354why, one step back353 assert.equal(code, 'ENOENT');354 assert.equal(isMaxBuffer, false);Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 355–356why, one step back355});356TweaksSindre Sorhusbefore adoption698a1b8
lines 357–359why, one step back357const testMaxBufferEncoding = async (execaMethod, fdNumber) => {358 const {shortMessage, stdio} = await runMaxBuffer(execaMethod, fdNumber, {encoding: 'buffer'});359 assertErrorMessage(shortMessage, {execaMethod, fdNumber, unit: 'bytes'});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 360why, one step back360 const stream = stdio[fdNumber];TweaksSindre Sorhusbefore adoption698a1b8
lines 361–362why, one step back361 assert.ok(stream instanceof Uint8Array);362 assert.equal(Buffer.from(stream).toString(), getExpectedOutput());100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 363–364why, one step back363};364TweaksSindre Sorhusbefore adoption698a1b8
lines 365–370why, one step back365test('maxBuffer works with encoding buffer and stdout', () => testMaxBufferEncoding(execa, 1));366test('maxBuffer works with encoding buffer and stderr', () => testMaxBufferEncoding(execa, 2));367test('maxBuffer works with encoding buffer and stdio[*]', () => testMaxBufferEncoding(execa, 3));368test('maxBuffer works with encoding buffer and stdout, sync', () => testMaxBufferEncoding(execaSync, 1));369test('maxBuffer works with encoding buffer and stderr, sync', () => testMaxBufferEncoding(execaSync, 2));370test('maxBuffer works with encoding buffer and stdio[*], sync', () => testMaxBufferEncoding(execaSync, 3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 371why, one step back371TweaksSindre Sorhusbefore adoption698a1b8
line 372why, one step back372const testMaxBufferHex = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 373why, one step back373 const length = maxBuffer / 2;TweaksSindre Sorhusbefore adoption698a1b8
lines 374–376why, one step back374 const {shortMessage, stdio} = await runMaxBuffer(execa, fdNumber, {length, encoding: 'hex'});375 assertErrorMessage(shortMessage, {fdNumber});376 assert.equal(stdio[fdNumber], Buffer.from(getExpectedOutput(length)).toString('hex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 377–378why, one step back377};378TweaksSindre Sorhusbefore adoption698a1b8
lines 379–381why, one step back379test('maxBuffer works with other encodings and stdout', () => testMaxBufferHex(1));380test('maxBuffer works with other encodings and stderr', () => testMaxBufferHex(2));381test('maxBuffer works with other encodings and stdio[*]', () => testMaxBufferHex(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 382why, one step back382TweaksSindre Sorhusbefore adoption698a1b8
line 383why, one step back383const testMaxBufferHexSync = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 384–385why, one step back384 const length = maxBuffer / 2;385 const {isMaxBuffer, stdio} = await getMaxBufferSubprocess(execaSync, fdNumber, {length, encoding: 'hex'});TweaksSindre Sorhusbefore adoption698a1b8
lines 386–387why, one step back386 assert.equal(isMaxBuffer, false);387 assert.equal(stdio[fdNumber], Buffer.from(getExpectedOutput(length + 1)).toString('hex'));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 388–389why, one step back388};389TweaksSindre Sorhusbefore adoption698a1b8
lines 390–392why, one step back390test('maxBuffer ignores other encodings and stdout, sync', () => testMaxBufferHexSync(1));391test('maxBuffer ignores other encodings and stderr, sync', () => testMaxBufferHexSync(2));392test('maxBuffer ignores other encodings and stdio[*], sync', () => testMaxBufferHexSync(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 393why, one step back393TweaksSindre Sorhusbefore adoption698a1b8
line 394why, one step back394const testNoMaxBuffer = async (fdNumber, buffer) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 395–399why, one step back395 const subprocess = getMaxBufferSubprocess(execa, fdNumber, {buffer});396 const [{isMaxBuffer, stdio}, output] = await Promise.all([397 subprocess,398 getStream(subprocess.stdio[fdNumber]),399 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 400–402why, one step back400 assert.equal(isMaxBuffer, false);401 assert.equal(stdio[fdNumber], undefined);402 assert.equal(output, getExpectedOutput(maxBuffer + 1));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 403–404why, one step back403};404TweaksSindre Sorhusbefore adoption698a1b8
lines 405–410why, one step back405test('do not buffer stdout when `buffer` set to `false`', () => testNoMaxBuffer(1, false));406test('do not buffer stdout when `buffer` set to `false`, fd-specific', () => testNoMaxBuffer(1, {stdout: false}));407test('do not buffer stderr when `buffer` set to `false`', () => testNoMaxBuffer(2, false));408test('do not buffer stderr when `buffer` set to `false`, fd-specific', () => testNoMaxBuffer(2, {stderr: false}));409test('do not buffer stdio[*] when `buffer` set to `false`', () => testNoMaxBuffer(3, false));410test('do not buffer stdio[*] when `buffer` set to `false`, fd-specific', () => testNoMaxBuffer(3, {fd3: false}));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 411why, one step back411TweaksSindre Sorhusbefore adoption698a1b8
line 412why, one step back412const testNoMaxBufferSync = (fdNumber, buffer) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 413why, one step back413 const {isMaxBuffer, stdio} = getMaxBufferSubprocess(execaSync, fdNumber, {buffer});TweaksSindre Sorhusbefore adoption698a1b8
lines 414–415why, one step back414 assert.equal(isMaxBuffer, false);415 assert.equal(stdio[fdNumber], undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 416–419why, one step back416};417418// @todo: add tests for fd3 once the following Node.js bug is fixed.419// https://github.com/nodejs/node/issues/52422TweaksSindre Sorhusbefore adoption698a1b8
lines 420–423why, one step back420test('do not buffer stdout when `buffer` set to `false`, sync', () => testNoMaxBufferSync(1, false));421test('do not buffer stdout when `buffer` set to `false`, fd-specific, sync', () => testNoMaxBufferSync(1, {stdout: false}));422test('do not buffer stderr when `buffer` set to `false`, sync', () => testNoMaxBufferSync(2, false));423test('do not buffer stderr when `buffer` set to `false`, fd-specific, sync', () => testNoMaxBufferSync(2, {stderr: false}));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 424why, one step back424TweaksSindre Sorhusbefore adoption698a1b8
line 425why, one step back425const testNoMaxBufferSyncObjectPipe = (fdNumber, fdName, stdioOption) => {Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)Sindre Sorhusbefore adoption487a3a4
lines 426–430why, one step back426 const {isMaxBuffer, stdio} = execaSync('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {427 [fdName]: stdioOption,428 buffer: false,429 maxBuffer,430 });TweaksSindre Sorhusbefore adoption698a1b8
lines 431–432why, one step back431 assert.equal(isMaxBuffer, false);432 assert.equal(stdio[fdNumber], undefined);Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)Sindre Sorhusbefore adoption487a3a4
lines 433–434why, one step back433};434TweaksSindre Sorhusbefore adoption698a1b8
lines 435–438why, one step back435test('do not buffer stdout object pipe when `buffer` set to `false`, sync', () => testNoMaxBufferSyncObjectPipe(1, 'stdout', {value: 'pipe'}));436test('do not buffer stdout object pipe with input false when `buffer` set to `false`, sync', () => testNoMaxBufferSyncObjectPipe(1, 'stdout', {value: 'pipe', input: false}));437test('do not buffer stdout object pipe with input true when `buffer` set to `false`, sync', () => testNoMaxBufferSyncObjectPipe(1, 'stdout', {value: 'pipe', input: true}));438test('do not buffer stderr object pipe with input true when `buffer` set to `false`, sync', () => testNoMaxBufferSyncObjectPipe(2, 'stderr', {value: 'pipe', input: true}));Add `{value: 'pipe', input: true}` to use an additional file descriptor as input (#1246)Sindre Sorhusbefore adoption487a3a4
line 439why, one step back439TweaksSindre Sorhusbefore adoption698a1b8
line 440why, one step back440const testMaxBufferAbort = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 441–442why, one step back441 const subprocess = getMaxBufferSubprocess(execa, fdNumber);442 const [{isMaxBuffer, shortMessage}] = await Promise.all([TweaksSindre Sorhusbefore adoption698a1b8
lines 443–444why, one step back443 assertRejects(subprocess, maxBufferMessage),444 assertRejects(getStream(subprocess.stdio[fdNumber]), {code: 'ERR_STREAM_PREMATURE_CLOSE'}),100% test coverage (#1018)ehmickybefore adoption9f65b86
line 445why, one step back445 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 446–447why, one step back446 assert.equal(isMaxBuffer, true);447 assertErrorMessage(shortMessage, {execaMethod: execa, fdNumber});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 448–449why, one step back448};449TweaksSindre Sorhusbefore adoption698a1b8
lines 450–452why, one step back450test('abort stream when hitting maxBuffer with stdout', () => testMaxBufferAbort(1));451test('abort stream when hitting maxBuffer with stderr', () => testMaxBufferAbort(2));452test('abort stream when hitting maxBuffer with stdio[*]', () => testMaxBufferAbort(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 453why, one step back453TweaksSindre Sorhusbefore adoption698a1b8
line 454why, one step back454test('error.isMaxBuffer is false on early errors', async () => {Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 455why, one step back455 const {failed, isMaxBuffer} = await getEarlyErrorSubprocess({reject: false, maxBuffer: 1});TweaksSindre Sorhusbefore adoption698a1b8
lines 456–457why, one step back456 assert.equal(failed, true);457 assert.equal(isMaxBuffer, false);Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 458why, one step back458});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 459why, one step back459TweaksSindre Sorhusbefore adoption698a1b8
line 460why, one step back460test('maxBuffer works with result.ipcOutput', async () => {Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
lines 461–465why, one step back461 const {462 isMaxBuffer,463 shortMessage,464 message,465 stderr,Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 466why, one step back466 ipcOutput,TweaksSindre Sorhusbefore adoption698a1b8
lines 467–472why, one step back467 } = await assertRejects(execa('ipc-send-twice.js', {ipc: true, maxBuffer: {ipc: 1}}));468 assert.equal(isMaxBuffer, true);469 assert.equal(shortMessage, 'Command\'s IPC output was larger than 1 messages: ipc-send-twice.js\nmaxBuffer exceeded');470 assert.ok(message.endsWith(`\n\n${foobarArray[0]}`));471 assert.equal(stderr, '');472 assert.deepEqual(ipcOutput, [foobarArray[0]]);Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
lines 473–474why, one step back473});474TweaksSindre Sorhusbefore adoption698a1b8
line 475why, one step back475test('maxBuffer is ignored with result.ipcOutput if buffer is false', async () => {Do not disconnect IPC on `error` event on process (#1086)ehmickybefore adoptiond6f5d9a
line 476why, one step back476 const {ipcOutput} = await execa('ipc-send-twice.js', {ipc: true, maxBuffer: {ipc: 1}, buffer: false});TweaksSindre Sorhusbefore adoption698a1b8
line 477why, one step back477 assert.deepEqual(ipcOutput, []);Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 478why, one step back478});Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 479–483why, one step back479480/*481`result.ipcOutput` is counted in messages, which are indivisible, so any `maxBuffer` value the count cannot land on exactly must still be enforced.482The threshold is hit as soon as buffering one more message would exceed it, which is how the stream-based `maxBuffer` behaves too.483*/TweaksSindre Sorhusbefore adoption698a1b8
lines 484–487why, one step back484const testIpcMaxBufferValue = async (maxBuffer, expectedOutput) => {485 const {isMaxBuffer, ipcOutput} = await assertRejects(execa('ipc-send-twice.js', {ipc: true, maxBuffer: {ipc: maxBuffer}}));486 assert.equal(isMaxBuffer, true);487 assert.deepEqual(ipcOutput, expectedOutput);Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 488–489why, one step back488};489TweaksSindre Sorhusbefore adoption698a1b8
lines 490–494why, one step back490test('maxBuffer works with result.ipcOutput, negative', () => testIpcMaxBufferValue(-1, []));491test('maxBuffer works with result.ipcOutput, 0', () => testIpcMaxBufferValue(0, []));492test('maxBuffer works with result.ipcOutput, below 1', () => testIpcMaxBufferValue(0.5, []));493test('maxBuffer works with result.ipcOutput, 1', () => testIpcMaxBufferValue(1, [foobarArray[0]]));494test('maxBuffer works with result.ipcOutput, fractional', () => testIpcMaxBufferValue(1.5, [foobarArray[0]]));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 495why, one step back495TweaksSindre Sorhusbefore adoption698a1b8
line 496why, one step back496const testIpcMaxBufferNotHit = async maxBuffer => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
line 497why, one step back497 const {isMaxBuffer, ipcOutput} = await execa('ipc-send-twice.js', {ipc: true, maxBuffer: {ipc: maxBuffer}});TweaksSindre Sorhusbefore adoption698a1b8
lines 498–499why, one step back498 assert.equal(isMaxBuffer, false);499 assert.deepEqual(ipcOutput, foobarArray);Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 500–501why, one step back500};501TweaksSindre Sorhusbefore adoption698a1b8
lines 502–503why, one step back502test('maxBuffer is not hit with result.ipcOutput, exact count', () => testIpcMaxBufferNotHit(2));503test('maxBuffer is not hit with result.ipcOutput, fractional', () => testIpcMaxBufferNotHit(2.5));Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 504–505why, one step back504505// The same `maxBuffer` value must be interpreted the same way whether the output is buffered as messages or as charactersTweaksSindre Sorhusbefore adoption698a1b8
line 506why, one step back506const testIpcMaxBufferLikeStream = async maxBuffer => {Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 507–510why, one step back507 const [ipcResult, streamResult] = await Promise.all([508 execa('ipc-send-twice.js', {ipc: true, maxBuffer: {ipc: maxBuffer}, reject: false}),509 execa('noop-fd.js', ['1', 'ab'], {maxBuffer, reject: false}),510 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 511–512why, one step back511 assert.equal(ipcResult.isMaxBuffer, streamResult.isMaxBuffer);512 assert.equal(ipcResult.ipcOutput.length, streamResult.stdout.length);Fix `maxBuffer` being ignored or wrongly appliedSindre Sorhusbefore adoption9547e51
lines 513–514why, one step back513};514TweaksSindre Sorhusbefore adoption698a1b8
lines 515–518why, one step back515test('maxBuffer with result.ipcOutput matches stdout, 0.5', () => testIpcMaxBufferLikeStream(0.5));516test('maxBuffer with result.ipcOutput matches stdout, 1', () => testIpcMaxBufferLikeStream(1));517test('maxBuffer with result.ipcOutput matches stdout, 1.5', () => testIpcMaxBufferLikeStream(1.5));518test('maxBuffer with result.ipcOutput matches stdout, 2', () => testIpcMaxBufferLikeStream(2));