Skip to content
Myr

shared.js

This file

Path

test/convert/shared.js

72 lines · 2.7 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than c8a6ed7 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–3why, one step back
1import 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 back
4import {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();16

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17const testSubprocessFail = async methodName => {

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 18–23why, one step back
18 const subprocess = getReadWriteSubprocess();
19 const stream = subprocess[methodName]();2021 const cause = new Error(foobarString);22 subprocess.kill(cause);23

TweaksSindre Sorhusbefore adoption698a1b8

lines 24–27why, one step back
24 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 back
28

TweaksSindre Sorhusbefore adoption698a1b8

line 29why, one step back
29 await assertSubprocessError(subprocess, error);

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 30–31why, one step back
30};
31

TweaksSindre Sorhusbefore adoption698a1b8

lines 32–34why, one step back
32test('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 back
35

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36const testErrorEvent = async methodName => {

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 37–38why, one step back
37 const subprocess = execa('empty.js');
38 const stream = subprocess[methodName]();

TweaksSindre Sorhusbefore adoption698a1b8

line 39why, one step back
39 assert.equal(stream.listenerCount('error'), 0);

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

line 40why, one step back
40 stream.destroy();

TweaksSindre Sorhusbefore adoption698a1b8

line 41why, one step back
41 await assertRejects(finishedStream(stream));

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 42–43why, one step back
42};
43

TweaksSindre Sorhusbefore adoption698a1b8

lines 44–46why, one step back
44test('.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 back
47

TweaksSindre Sorhusbefore adoption698a1b8

line 48why, one step back
48const testSubprocessError = async methodName => {

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 49–52why, one step back
49 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 back
53 await assertStreamError(stream, {cause});

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 54–55why, one step back
54};
55

TweaksSindre Sorhusbefore adoption698a1b8

lines 56–72why, one step back
56test('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'));