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 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
lines 2–3why, one step back2import {once} from 'node:events';3import {setTimeout} from 'node:timers/promises';TweaksSindre Sorhusbefore adoption698a1b8
line 4why, one step back4import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 5–10why, one step back5import {execa} from '../../index.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {fullStdio, getStdio} from '../helpers/stdio.js';89setFixtureDirectory();10TweaksSindre Sorhusbefore adoption698a1b8
lines 11–12why, one step back11const 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 back13};14TweaksSindre Sorhusbefore adoption698a1b8
lines 15–17why, one step back15test('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 back18TweaksSindre Sorhusbefore adoption698a1b8
line 19why, one step back19const testBufferNotRead = async (fdNumber, all) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 20why, one step back20 const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});TweaksSindre Sorhusbefore adoption698a1b8
line 21why, one step back21 await assert.doesNotReject(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 22–23why, one step back22};23TweaksSindre Sorhusbefore adoption698a1b8
lines 24–27why, one step back24test('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 back28TweaksSindre Sorhusbefore adoption698a1b8
line 29why, one step back29const testBufferRead = async (fdNumber, all) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 30–32why, one step back30 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 back33 await assert.doesNotReject(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 34–35why, one step back34};35TweaksSindre Sorhusbefore adoption698a1b8
lines 36–39why, one step back36test('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 back40TweaksSindre Sorhusbefore adoption698a1b8
line 41why, one step back41const testBufferExit = async (fdNumber, fixtureName, reject) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 42–44why, one step back42 const subprocess = execa(fixtureName, [`${fdNumber}`], {...fullStdio, reject});43 await setTimeout(100);44 const {stdio} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 45why, one step back45 assert.equal(stdio[fdNumber], 'foobar');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 46–47why, one step back46};47TweaksSindre Sorhusbefore adoption698a1b8
lines 48–56why, one step back48test('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 back57TweaksSindre Sorhusbefore adoption698a1b8
line 58why, one step back58const testBufferDirect = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 59–60why, one step back59 const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);60 const data = await once(subprocess.stdio[fdNumber], 'data');TweaksSindre Sorhusbefore adoption698a1b8
line 61why, one step back61 assert.equal(data.toString().trim(), 'foobar');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 62why, one step back62 const result = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 63why, one step back63 assert.equal(result.stdio[fdNumber], 'foobar');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 64–65why, one step back64};65TweaksSindre Sorhusbefore adoption698a1b8
lines 66–68why, one step back66test('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 back69TweaksSindre Sorhusbefore adoption698a1b8
line 70why, one step back70const testBufferDestroyOnEnd = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 71–72why, one step back71 const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);72 const result = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
lines 73–74why, one step back73 assert.equal(result.stdio[fdNumber], 'foobar');74 assert.ok(subprocess.stdio[fdNumber].destroyed);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 75–76why, one step back75};76TweaksSindre Sorhusbefore adoption698a1b8
lines 77–79why, one step back77test('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));