shared.js
This file
Path
test/convert/shared.js
72 lines · 2.7 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than c8a6ed7 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–3why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';3import {assertRejects, assertThrows} from '../helpers/assert.js';Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
lines 4–16why, one step back4import {execa} from '../../index.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {7 finishedStream,8 assertWritableAborted,9 assertStreamError,10 assertSubprocessError,11 getReadWriteSubprocess,12} from '../helpers/convert.js';13import {foobarString} from '../helpers/input.js';1415setFixtureDirectory();16TweaksSindre Sorhusbefore adoption698a1b8
line 17why, one step back17const testSubprocessFail = async methodName => {Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
lines 18–23why, one step back18 const subprocess = getReadWriteSubprocess();19 const stream = subprocess[methodName]();2021 const cause = new Error(foobarString);22 subprocess.kill(cause);23TweaksSindre Sorhusbefore adoption698a1b8
lines 24–27why, one step back24 const error = await assertStreamError(stream, {cause});25 assertWritableAborted(subprocess.stdin);26 assert.equal(subprocess.stdout.readableEnded, true);27 assert.equal(subprocess.stderr.readableEnded, true);Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
line 28why, one step back28TweaksSindre Sorhusbefore adoption698a1b8
line 29why, one step back29 await assertSubprocessError(subprocess, error);Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
lines 30–31why, one step back30};31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–34why, one step back32test('subprocess fail -> .readable() error', () => testSubprocessFail('readable'));33test('subprocess fail -> .writable() error', () => testSubprocessFail('writable'));34test('subprocess fail -> .duplex() error', () => testSubprocessFail('duplex'));Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
line 35why, one step back35TweaksSindre Sorhusbefore adoption698a1b8
line 36why, one step back36const testErrorEvent = async methodName => {Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
lines 37–38why, one step back37 const subprocess = execa('empty.js');38 const stream = subprocess[methodName]();TweaksSindre Sorhusbefore adoption698a1b8
line 39why, one step back39 assert.equal(stream.listenerCount('error'), 0);Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
line 40why, one step back40 stream.destroy();TweaksSindre Sorhusbefore adoption698a1b8
line 41why, one step back41 await assertRejects(finishedStream(stream));Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
lines 42–43why, one step back42};43TweaksSindre Sorhusbefore adoption698a1b8
lines 44–46why, one step back44test('.readable() requires listening to "error" event', () => testErrorEvent('readable'));45test('.writable() requires listening to "error" event', () => testErrorEvent('writable'));46test('.duplex() requires listening to "error" event', () => testErrorEvent('duplex'));Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
line 47why, one step back47TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48const testSubprocessError = async methodName => {Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
lines 49–52why, one step back49 const subprocess = getReadWriteSubprocess();50 const stream = subprocess[methodName]();51 const cause = new Error(foobarString);52 subprocess.kill(cause);TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53 await assertStreamError(stream, {cause});Improve documentation (#1003)ehmickybefore adoptionc8a6ed7
lines 54–55why, one step back54};55TweaksSindre Sorhusbefore adoption698a1b8
lines 56–72why, one step back56test('Do not need to await subprocess with .readable()', () => testSubprocessError('readable'));57test('Do not need to await subprocess with .writable()', () => testSubprocessError('writable'));58test('Do not need to await subprocess with .duplex()', () => testSubprocessError('duplex'));5960const testNullOptions = async methodName => {61 const subprocess = getReadWriteSubprocess();62 subprocess.stdin.end();63 assertThrows(() => {64 subprocess[methodName](null);65 }, {message: 'The options must be an object, not `null`.'});66 await subprocess;67};6869test('.readable() cannot use null options', () => testNullOptions('readable'));70test('.writable() cannot use null options', () => testNullOptions('writable'));71test('.duplex() cannot use null options', () => testNullOptions('duplex'));72test('.iterable() cannot use null options', () => testNullOptions('iterable'));