Skip to content
Myr

lines-max-buffer.js

This file

Path

test/stdio/lines-max-buffer.js

52 lines · 2.5 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

lines 1–3why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';3import {assertThrows, assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–12why, one step back
4import {execa, execaSync} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {simpleLines, noNewlinesChunks, getSimpleChunkSubprocessAsync} from '../helpers/lines.js';7import {assertErrorMessage} from '../helpers/max-buffer.js';89setFixtureDirectory();1011const maxBuffer = simpleLines.length - 1;12

TweaksSindre Sorhusbefore adoption698a1b8

line 13why, one step back
13const testBelowMaxBuffer = async lines => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 14why, one step back
14 const {isMaxBuffer, stdout} = await getSimpleChunkSubprocessAsync({lines, maxBuffer: maxBuffer + 1});

TweaksSindre Sorhusbefore adoption698a1b8

lines 15–16why, one step back
15 assert.equal(isMaxBuffer, false);
16 assert.deepEqual(stdout, noNewlinesChunks);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 17–18why, one step back
17};
18

TweaksSindre Sorhusbefore adoption698a1b8

lines 19–20why, one step back
19test('"lines: true" can be below "maxBuffer"', () => testBelowMaxBuffer(true));
20test('"lines: true" can be below "maxBuffer", fd-specific', () => testBelowMaxBuffer({stdout: true}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 21why, one step back
21

TweaksSindre Sorhusbefore adoption698a1b8

lines 22–26why, one step back
22const testAboveMaxBuffer = async lines => {
23 const {isMaxBuffer, shortMessage, stdout} = await assertRejects(getSimpleChunkSubprocessAsync({lines, maxBuffer}));24 assert.equal(isMaxBuffer, true);25 assertErrorMessage(shortMessage, {length: maxBuffer, unit: 'lines'});26 assert.deepEqual(stdout, noNewlinesChunks.slice(0, maxBuffer));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 27–28why, one step back
27};
28

TweaksSindre Sorhusbefore adoption698a1b8

lines 29–30why, one step back
29test('"lines: true" can be above "maxBuffer"', () => testAboveMaxBuffer(true));
30test('"lines: true" can be above "maxBuffer", fd-specific', () => testAboveMaxBuffer({stdout: true}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 31why, one step back
31

TweaksSindre Sorhusbefore adoption698a1b8

lines 32–36why, one step back
32const testMaxBufferUnit = async lines => {
33 const {isMaxBuffer, shortMessage, stdout} = await assertRejects(execa('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer}));34 assert.equal(isMaxBuffer, true);35 assertErrorMessage(shortMessage, {length: maxBuffer, unit: 'lines'});36 assert.deepEqual(stdout, ['...', '...']);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 37–38why, one step back
37};
38

TweaksSindre Sorhusbefore adoption698a1b8

lines 39–40why, one step back
39test('"maxBuffer" is measured in lines with "lines: true"', () => testMaxBufferUnit(true));
40test('"maxBuffer" is measured in lines with "lines: true", fd-specific', () => testMaxBufferUnit({stdout: true}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 41why, one step back
41

TweaksSindre Sorhusbefore adoption698a1b8

lines 42–43why, one step back
42const testMaxBufferUnitSync = lines => {
43 const {isMaxBuffer, shortMessage, stdout} = assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 44–45why, one step back
44 execaSync('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer});
45 }, {code: 'ENOBUFS'});

TweaksSindre Sorhusbefore adoption698a1b8

lines 46–48why, one step back
46 assert.equal(isMaxBuffer, true);
47 assertErrorMessage(shortMessage, {execaMethod: execaSync, length: maxBuffer});48 assert.deepEqual(stdout, ['..']);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 49–50why, one step back
49};
50

TweaksSindre Sorhusbefore adoption698a1b8

lines 51–52why, one step back
51test('"maxBuffer" is measured in bytes with "lines: true", sync', () => testMaxBufferUnitSync(true));
52test('"maxBuffer" is measured in bytes with "lines: true", fd-specific, sync', () => testMaxBufferUnitSync({stdout: true}));