Skip to content
Myr

web-stream.js

This file

Path

test/stdio/web-stream.js

98 lines · 3.8 KiB · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

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

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 1–4why, one step back
1import {Readable} from 'node:stream';
2import {setImmediate} from 'node:timers/promises';3import test from 'ava';4import {execa, execaSync} from '../../index.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 5why, one step back
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 6–7why, one step back
6import {getStdio} from '../helpers/stdio.js';
7

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 8why, one step back
8setFixtureDirectory();

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

line 9why, one step back
9

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

line 10why, one step back
10const testReadableStream = async (t, fdNumber) => {

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

line 11why, one step back
11 const readableStream = Readable.toWeb(Readable.from('foobar'));

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

line 12why, one step back
12 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream));

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 13–18why, one step back
13 t.is(stdout, 'foobar');
14};1516test('stdin can be a ReadableStream', testReadableStream, 0);17test('stdio[*] can be a ReadableStream', testReadableStream, 3);18

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

line 19why, one step back
19const testWritableStream = async (t, fdNumber) => {

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 20–25why, one step back
20 const result = [];
21 const writableStream = new WritableStream({22 write(chunk) {23 result.push(chunk);24 },25 });

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

line 26why, one step back
26 await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, writableStream));

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 27–33why, one step back
27 t.is(result.join(''), 'foobar');
28};2930test('stdout can be a WritableStream', testWritableStream, 1);31test('stderr can be a WritableStream', testWritableStream, 2);32test('stdio[*] can be a WritableStream', testWritableStream, 3);33

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

line 34why, one step back
34const testWebStreamSync = (t, StreamClass, fdNumber, optionName) => {

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

line 35why, one step back
35 t.throws(() => {

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

line 36why, one step back
36 execaSync('empty.js', getStdio(fdNumber, new StreamClass()));

Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9

line 37why, one step back
37 }, {message: `The \`${optionName}\` option cannot be a web stream with synchronous methods.`});

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 38–45why, one step back
38};
3940test('stdin cannot be a ReadableStream - sync', testWebStreamSync, ReadableStream, 0, 'stdin');41test('stdio[*] cannot be a ReadableStream - sync', testWebStreamSync, ReadableStream, 3, 'stdio[3]');42test('stdout cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 1, 'stdout');43test('stderr cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 2, 'stderr');44test('stdio[*] cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 3, 'stdio[3]');45

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

line 46why, one step back
46const testLongWritableStream = async (t, fdNumber) => {

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 47–53why, one step back
47 let result = false;
48 const writableStream = new WritableStream({49 async close() {50 await setImmediate();51 result = true;52 },53 });

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

line 54why, one step back
54 await execa('empty.js', getStdio(fdNumber, writableStream));

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 55–61why, one step back
55 t.true(result);
56};5758test('stdout waits for WritableStream completion', testLongWritableStream, 1);59test('stderr waits for WritableStream completion', testLongWritableStream, 2);60test('stdio[*] waits for WritableStream completion', testLongWritableStream, 3);61

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

line 62why, one step back
62const testWritableStreamError = async (t, fdNumber) => {

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 63why, one step back
63 const cause = new Error('foobar');

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 64–65why, one step back
64 const writableStream = new WritableStream({
65 start(controller) {

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 66why, one step back
66 controller.error(cause);

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 67–68why, one step back
67 },
68 });

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

lines 69–70why, one step back
69 const error = await t.throwsAsync(execa('noop.js', getStdio(fdNumber, writableStream)));
70 t.is(error.cause, cause);

Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51

lines 71–75why, one step back
71};
7273test('stdout option handles errors in WritableStream', testWritableStreamError, 1);74test('stderr option handles errors in WritableStream', testWritableStreamError, 2);75test('stdio[*] option handles errors in WritableStream', testWritableStreamError, 3);

Add more error handling related tests (#773)ehmickybefore adoption7591905

line 76why, one step back
76

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

line 77why, one step back
77const testReadableStreamError = async (t, fdNumber) => {

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 78why, one step back
78 const cause = new Error('foobar');

Add more error handling related tests (#773)ehmickybefore adoption7591905

lines 79–80why, one step back
79 const readableStream = new ReadableStream({
80 start(controller) {

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 81why, one step back
81 controller.error(cause);

Add more error handling related tests (#773)ehmickybefore adoption7591905

lines 82–83why, one step back
82 },
83 });

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

lines 84–85why, one step back
84 const error = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream)));
85 t.is(error.cause, cause);

Add more error handling related tests (#773)ehmickybefore adoption7591905

lines 86–89why, one step back
86};
8788test('stdin option handles errors in ReadableStream', testReadableStreamError, 0);89test('stdio[*] option handles errors in ReadableStream', testReadableStreamError, 3);

Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd

line 90why, one step back
90

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

line 91why, one step back
91test('ReadableStream with stdin is canceled on subprocess exit', async t => {

Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd

lines 92–98why, one step back
92 let readableStream;
93 const promise = new Promise(resolve => {94 readableStream = new ReadableStream({cancel: resolve});95 });96 await t.throwsAsync(execa('stdin.js', {stdin: readableStream, timeout: 1}), {message: /timed out/});97 await promise;98});