Skip to content
Myr

exit.js

This file

Path

test/stream/exit.js

78 lines · 4.3 KiB · JavaScript

Last changed by

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–9why, one step back
1import {once} from 'node:events';
2import {setTimeout} from 'node:timers/promises';3import test from 'ava';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {fullStdio, getStdio} from '../helpers/stdio.js';78setFixtureDir();9

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

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

Split files (#837)ehmickybefore adoption672c2d7

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

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Split files (#837)ehmickybefore adoption672c2d7

line 17why, one step back
17

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

lines 18–19why, one step back
18const testBufferNotRead = async (t, fdNumber, all) => {
19 const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});

Split files (#837)ehmickybefore adoption672c2d7

lines 20–22why, one step back
20 await t.notThrowsAsync(subprocess);
21};22

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Split files (#837)ehmickybefore adoption672c2d7

line 27why, one step back
27

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

lines 28–30why, one step back
28const testBufferRead = async (t, fdNumber, all) => {
29 const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});30 const stream = all ? subprocess.all : subprocess.stdio[fdNumber];

Split files (#837)ehmickybefore adoption672c2d7

lines 31–34why, one step back
31 stream.resume();
32 await t.notThrowsAsync(subprocess);33};34

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Split files (#837)ehmickybefore adoption672c2d7

line 39why, one step back
39

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

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

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 41why, one step back
41 const subprocess = execa(fixtureName, [`${fdNumber}`], {...fullStdio, reject});

Split files (#837)ehmickybefore adoption672c2d7

line 42why, one step back
42 await setTimeout(100);

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 43why, one step back
43 const {stdio} = await subprocess;

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 44why, one step back
44 t.is(stdio[fdNumber], 'foobar');

Split files (#837)ehmickybefore adoption672c2d7

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

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Split files (#837)ehmickybefore adoption672c2d7

line 56why, one step back
56

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 57why, one step back
57const testBufferDirect = async (t, fdNumber) => {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Split files (#837)ehmickybefore adoption672c2d7

line 60why, one step back
60 t.is(data.toString().trim(), 'foobar');

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 62why, one step back
62 t.is(result.stdio[fdNumber], 'foobar');

Split files (#837)ehmickybefore adoption672c2d7

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

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Split files (#837)ehmickybefore adoption672c2d7

line 68why, one step back
68

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 69why, one step back
69const testBufferDestroyOnEnd = async (t, fdNumber) => {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 72why, one step back
72 t.is(result.stdio[fdNumber], 'foobar');

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 73why, one step back
73 t.true(subprocess.stdio[fdNumber].destroyed);

Split files (#837)ehmickybefore adoption672c2d7

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

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

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