no-buffer.js
This file
Path
test/stream/no-buffer.js
110 lines · 5.5 KiB · JavaScript
Last changed by
Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–10why, one step back1import {once} from 'node:events';2import test from 'ava';3import getStream from 'get-stream';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {fullStdio, getStdio} from '../helpers/stdio.js';7import {foobarString} from '../helpers/input.js';89setFixtureDir();10Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 11–12why, one step back11const testLateStream = async (t, fdNumber, all) => {12 const subprocess = execa('noop-fd-ipc.js', [`${fdNumber}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});Split files (#837)ehmickybefore adoption672c2d7
lines 13–14why, one step back13 await once(subprocess, 'message');14 const [output, allOutput] = await Promise.all([Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 15why, one step back15 getStream(subprocess.stdio[fdNumber]),Split files (#837)ehmickybefore adoption672c2d7
lines 16–37why, one step back16 all ? getStream(subprocess.all) : undefined,17 subprocess,18 ]);1920 t.is(output, '');2122 if (all) {23 t.is(allOutput, '');24 }25};2627test('Lacks some data when stdout is read too late `buffer` set to `false`', testLateStream, 1, false);28test('Lacks some data when stderr is read too late `buffer` set to `false`', testLateStream, 2, false);29test('Lacks some data when stdio[*] is read too late `buffer` set to `false`', testLateStream, 3, false);30test('Lacks some data when all is read too late `buffer` set to `false`', testLateStream, 1, true);3132const getFirstDataEvent = async stream => {33 const [output] = await once(stream, 'data');34 return output.toString();35};3637// eslint-disable-next-line max-paramsRename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 38–39why, one step back38const testIterationBuffer = async (t, fdNumber, buffer, useDataEvents, all) => {39 const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], {...fullStdio, buffer, all});Split files (#837)ehmickybefore adoption672c2d7
lines 40–42why, one step back40 const getOutput = useDataEvents ? getFirstDataEvent : getStream;41 const [result, output, allOutput] = await Promise.all([42 subprocess,Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 43why, one step back43 getOutput(subprocess.stdio[fdNumber]),Split files (#837)ehmickybefore adoption672c2d7
lines 44–46why, one step back44 all ? getOutput(subprocess.all) : undefined,45 ]);46Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 47why, one step back47 const expectedResult = buffer ? foobarString : undefined;Split files (#837)ehmickybefore adoption672c2d7
line 48why, one step back48Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 49why, one step back49 t.is(result.stdio[fdNumber], expectedResult);Upgrade `get-stream` (#908)ehmickybefore adoption3ecd447
line 50why, one step back50 t.is(output, foobarString);Split files (#837)ehmickybefore adoption672c2d7
lines 51–52why, one step back5152 if (all) {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 53why, one step back53 t.is(result.all, expectedResult);Upgrade `get-stream` (#908)ehmickybefore adoption3ecd447
line 54why, one step back54 t.is(allOutput, foobarString);Split files (#837)ehmickybefore adoption672c2d7
lines 55–61why, one step back55 }56};5758test('Can iterate stdout when `buffer` set to `false`', testIterationBuffer, 1, false, false, false);59test('Can iterate stderr when `buffer` set to `false`', testIterationBuffer, 2, false, false, false);60test('Can iterate stdio[*] when `buffer` set to `false`', testIterationBuffer, 3, false, false, false);61test('Can iterate all when `buffer` set to `false`', testIterationBuffer, 1, false, false, true);Upgrade `get-stream` (#908)ehmickybefore adoption3ecd447
lines 62–65why, one step back62test('Can iterate stdout when `buffer` set to `true`', testIterationBuffer, 1, true, false, false);63test('Can iterate stderr when `buffer` set to `true`', testIterationBuffer, 2, true, false, false);64test('Can iterate stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, false, false);65test('Can iterate all when `buffer` set to `true`', testIterationBuffer, 1, true, false, true);Split files (#837)ehmickybefore adoption672c2d7
lines 66–74why, one step back66test('Can listen to `data` events on stdout when `buffer` set to `false`', testIterationBuffer, 1, false, true, false);67test('Can listen to `data` events on stderr when `buffer` set to `false`', testIterationBuffer, 2, false, true, false);68test('Can listen to `data` events on stdio[*] when `buffer` set to `false`', testIterationBuffer, 3, false, true, false);69test('Can listen to `data` events on all when `buffer` set to `false`', testIterationBuffer, 1, false, true, true);70test('Can listen to `data` events on stdout when `buffer` set to `true`', testIterationBuffer, 1, true, true, false);71test('Can listen to `data` events on stderr when `buffer` set to `true`', testIterationBuffer, 2, true, true, false);72test('Can listen to `data` events on stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, true, false);73test('Can listen to `data` events on all when `buffer` set to `true`', testIterationBuffer, 1, true, true, true);74Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 75–77why, one step back75const testNoBufferStreamError = async (t, fdNumber, all) => {76 const subprocess = execa('noop-fd.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});77 const stream = all ? subprocess.all : subprocess.stdio[fdNumber];Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 78–80why, one step back78 const cause = new Error('test');79 stream.destroy(cause);80 t.like(await t.throwsAsync(subprocess), {cause});Split files (#837)ehmickybefore adoption672c2d7
lines 81–91why, one step back81};8283test('Listen to stdout errors even when `buffer` is `false`', testNoBufferStreamError, 1, false);84test('Listen to stderr errors even when `buffer` is `false`', testNoBufferStreamError, 2, false);85test('Listen to stdio[*] errors even when `buffer` is `false`', testNoBufferStreamError, 3, false);86test('Listen to all errors even when `buffer` is `false`', testNoBufferStreamError, 1, true);8788test('buffer: false > promise resolves', async t => {89 await t.notThrowsAsync(execa('noop.js', {buffer: false}));90});91Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 92why, one step back92test('buffer: false > promise rejects when subprocess returns non-zero', async t => {Split files (#837)ehmickybefore adoption672c2d7
lines 93–96why, one step back93 const {exitCode} = await t.throwsAsync(execa('fail.js', {buffer: false}));94 t.is(exitCode, 2);95});96Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 97why, one step back97const testStreamEnd = async (t, fdNumber, buffer) => {Split files (#837)ehmickybefore adoption672c2d7
lines 98–100why, one step back98 const subprocess = execa('wrong command', {...fullStdio, buffer});99 await Promise.all([100 t.throwsAsync(subprocess, {message: /wrong command/}),Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 101why, one step back101 once(subprocess.stdio[fdNumber], 'end'),Split files (#837)ehmickybefore adoption672c2d7
lines 102–110why, one step back102 ]);103};104105test('buffer: false > emits end event on stdout when promise is rejected', testStreamEnd, 1, false);106test('buffer: false > emits end event on stderr when promise is rejected', testStreamEnd, 2, false);107test('buffer: false > emits end event on stdio[*] when promise is rejected', testStreamEnd, 3, false);108test('buffer: true > emits end event on stdout when promise is rejected', testStreamEnd, 1, true);109test('buffer: true > emits end event on stderr when promise is rejected', testStreamEnd, 2, true);110test('buffer: true > emits end event on stdio[*] when promise is rejected', testStreamEnd, 3, true);