Skip to content
Myr

buffer-end.js

This file

Path

test/resolve/buffer-end.js

79 lines · 4.6 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–3why, one step back
2import {once} from 'node:events';
3import {setTimeout} from 'node:timers/promises';

TweaksSindre Sorhusbefore adoption698a1b8

line 4why, one step back
4import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 5–10why, one step back
5import {execa} from '../../index.js';
6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {fullStdio, getStdio} from '../helpers/stdio.js';89setFixtureDirectory();10

TweaksSindre Sorhusbefore adoption698a1b8

lines 11–12why, one step back
11const testBufferIgnore = async (fdNumber, all) => {
12 await assert.doesNotReject(execa('max-buffer.js', [`${fdNumber}`], {...getStdio(fdNumber, 'ignore'), buffer: false, all}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 13–14why, one step back
13};
14

TweaksSindre Sorhusbefore adoption698a1b8

lines 15–17why, one step back
15test('Subprocess buffers stdout, which does not prevent exit if ignored', () => testBufferIgnore(1, false));
16test('Subprocess buffers stderr, which does not prevent exit if ignored', () => testBufferIgnore(2, false));17test('Subprocess buffers all, which does not prevent exit if ignored', () => testBufferIgnore(1, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 18why, one step back
18

TweaksSindre Sorhusbefore adoption698a1b8

line 19why, one step back
19const testBufferNotRead = async (fdNumber, all) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 20why, one step back
20 const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});

TweaksSindre Sorhusbefore adoption698a1b8

line 21why, one step back
21 await assert.doesNotReject(subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 22–23why, one step back
22};
23

TweaksSindre Sorhusbefore adoption698a1b8

lines 24–27why, one step back
24test('Subprocess buffers stdout, which does not prevent exit if not read and buffer is false', () => testBufferNotRead(1, false));
25test('Subprocess buffers stderr, which does not prevent exit if not read and buffer is false', () => testBufferNotRead(2, false));26test('Subprocess buffers stdio[*], which does not prevent exit if not read and buffer is false', () => testBufferNotRead(3, false));27test('Subprocess buffers all, which does not prevent exit if not read and buffer is false', () => testBufferNotRead(1, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 28why, one step back
28

TweaksSindre Sorhusbefore adoption698a1b8

line 29why, one step back
29const testBufferRead = async (fdNumber, all) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 30–32why, one step back
30 const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});
31 const stream = all ? subprocess.all : subprocess.stdio[fdNumber];32 stream.resume();

TweaksSindre Sorhusbefore adoption698a1b8

line 33why, one step back
33 await assert.doesNotReject(subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 34–35why, one step back
34};
35

TweaksSindre Sorhusbefore adoption698a1b8

lines 36–39why, one step back
36test('Subprocess buffers stdout, which does not prevent exit if read and buffer is false', () => testBufferRead(1, false));
37test('Subprocess buffers stderr, which does not prevent exit if read and buffer is false', () => testBufferRead(2, false));38test('Subprocess buffers stdio[*], which does not prevent exit if read and buffer is false', () => testBufferRead(3, false));39test('Subprocess buffers all, which does not prevent exit if read and buffer is false', () => testBufferRead(1, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 40why, one step back
40

TweaksSindre Sorhusbefore adoption698a1b8

line 41why, one step back
41const testBufferExit = async (fdNumber, fixtureName, reject) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 42–44why, one step back
42 const subprocess = execa(fixtureName, [`${fdNumber}`], {...fullStdio, reject});
43 await setTimeout(100);44 const {stdio} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 45why, one step back
45 assert.equal(stdio[fdNumber], 'foobar');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 46–47why, one step back
46};
47

TweaksSindre Sorhusbefore adoption698a1b8

lines 48–56why, one step back
48test('Subprocess buffers stdout before it is read', () => testBufferExit(1, 'noop-delay.js', true));
49test('Subprocess buffers stderr before it is read', () => testBufferExit(2, 'noop-delay.js', true));50test('Subprocess buffers stdio[*] before it is read', () => testBufferExit(3, 'noop-delay.js', true));51test('Subprocess buffers stdout right away, on successfully exit', () => testBufferExit(1, 'noop-fd.js', true));52test('Subprocess buffers stderr right away, on successfully exit', () => testBufferExit(2, 'noop-fd.js', true));53test('Subprocess buffers stdio[*] right away, on successfully exit', () => testBufferExit(3, 'noop-fd.js', true));54test('Subprocess buffers stdout right away, on failure', () => testBufferExit(1, 'noop-fail.js', false));55test('Subprocess buffers stderr right away, on failure', () => testBufferExit(2, 'noop-fail.js', false));56test('Subprocess buffers stdio[*] right away, on failure', () => testBufferExit(3, 'noop-fail.js', false));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 57why, one step back
57

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58const testBufferDirect = async fdNumber => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 59–60why, one step back
59 const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);
60 const data = await once(subprocess.stdio[fdNumber], 'data');

TweaksSindre Sorhusbefore adoption698a1b8

line 61why, one step back
61 assert.equal(data.toString().trim(), 'foobar');

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 62why, one step back
62 const result = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 63why, one step back
63 assert.equal(result.stdio[fdNumber], 'foobar');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 64–65why, one step back
64};
65

TweaksSindre Sorhusbefore adoption698a1b8

lines 66–68why, one step back
66test('Subprocess buffers stdout right away, even if directly read', () => testBufferDirect(1));
67test('Subprocess buffers stderr right away, even if directly read', () => testBufferDirect(2));68test('Subprocess buffers stdio[*] right away, even if directly read', () => testBufferDirect(3));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 69why, one step back
69

TweaksSindre Sorhusbefore adoption698a1b8

line 70why, one step back
70const testBufferDestroyOnEnd = async fdNumber => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 71–72why, one step back
71 const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);
72 const result = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 73–74why, one step back
73 assert.equal(result.stdio[fdNumber], 'foobar');
74 assert.ok(subprocess.stdio[fdNumber].destroyed);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 75–76why, one step back
75};
76

TweaksSindre Sorhusbefore adoption698a1b8

lines 77–79why, one step back
77test('subprocess.stdout must be read right away', () => testBufferDestroyOnEnd(1));
78test('subprocess.stderr must be read right away', () => testBufferDestroyOnEnd(2));79test('subprocess.stdio[*] must be read right away', () => testBufferDestroyOnEnd(3));