web-stream.js
This file
Path
test/stdio/web-stream.js
74 lines · 2.9 KiB · JavaScript
Last changed by
Prefer `setImmediate()` over `setTimeout()` (#733)ehmickybefore adoption66d12bf
History of this fileTake it
Refactor tests (#628)ehmickybefore adoption30ecc81
line 1why, one step back1import {Readable} from 'node:stream';Prefer `setImmediate()` over `setTimeout()` (#733)ehmickybefore adoption66d12bf
line 2why, one step back2import {setImmediate} from 'node:timers/promises';Refactor tests (#628)ehmickybefore adoption30ecc81
lines 3–5why, one step back3import test from 'ava';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 6why, one step back6import {getStdio} from '../helpers/stdio.js';Refactor tests (#628)ehmickybefore adoption30ecc81
lines 7–9why, one step back78setFixtureDir();9Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 10why, one step back10const testReadableStream = async (t, index) => {Refactor tests (#628)ehmickybefore adoption30ecc81
line 11why, one step back11 const readableStream = Readable.toWeb(Readable.from('foobar'));Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 12why, one step back12 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, readableStream));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 13–15why, one step back13 t.is(stdout, 'foobar');14};15Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 16–17why, one step back16test('stdin can be a ReadableStream', testReadableStream, 0);17test('stdio[*] can be a ReadableStream', testReadableStream, 3);Refactor tests (#628)ehmickybefore adoption30ecc81
line 18why, one step back18Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 19why, one step back19const testWritableStream = async (t, index) => {Refactor tests (#628)ehmickybefore adoption30ecc81
lines 20–25why, one step back20 const result = [];21 const writableStream = new WritableStream({22 write(chunk) {23 result.push(chunk);24 },25 });Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 26–27why, one step back26 await execa('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, writableStream));27 t.is(result.join(''), 'foobar');Refactor tests (#628)ehmickybefore adoption30ecc81
lines 28–29why, one step back28};29Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 30–32why, one step back30test('stdout can be a WritableStream', testWritableStream, 1);31test('stderr can be a WritableStream', testWritableStream, 2);32test('stdio[*] can be a WritableStream', testWritableStream, 3);Refactor tests (#628)ehmickybefore adoption30ecc81
line 33why, one step back33Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 34why, one step back34const testWebStreamSync = (t, StreamClass, index, optionName) => {Refactor tests (#628)ehmickybefore adoption30ecc81
line 35why, one step back35 t.throws(() => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 36why, one step back36 execaSync('empty.js', getStdio(index, new StreamClass()));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 37–39why, one step back37 }, {message: `The \`${optionName}\` option cannot be a web stream in sync mode.`});38};39Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 40–44why, one step back40test('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]');Wait for `WritableStream` completion (#645)ehmickybefore adoptionfb73bd1
line 45why, one step back45Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 46why, one step back46const testLongWritableStream = async (t, index) => {Wait for `WritableStream` completion (#645)ehmickybefore adoptionfb73bd1
lines 47–49why, one step back47 let result = false;48 const writableStream = new WritableStream({49 async close() {Prefer `setImmediate()` over `setTimeout()` (#733)ehmickybefore adoption66d12bf
line 50why, one step back50 await setImmediate();Wait for `WritableStream` completion (#645)ehmickybefore adoptionfb73bd1
lines 51–53why, one step back51 result = true;52 },53 });Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 54why, one step back54 await execa('empty.js', getStdio(index, writableStream));Wait for `WritableStream` completion (#645)ehmickybefore adoptionfb73bd1
lines 55–57why, one step back55 t.true(result);56};57Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 58–60why, one step back58test('stdout waits for WritableStream completion', testLongWritableStream, 1);59test('stderr waits for WritableStream completion', testLongWritableStream, 2);60test('stdio[*] waits for WritableStream completion', testLongWritableStream, 3);Refactor tests (#628)ehmickybefore adoption30ecc81
line 61why, one step back61Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 62why, one step back62const testWritableStreamError = async (t, index) => {Refactor tests (#628)ehmickybefore adoption30ecc81
lines 63–67why, one step back63 const writableStream = new WritableStream({64 start(controller) {65 controller.error(new Error('foobar'));66 },67 });Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 68why, one step back68 const {originalMessage} = await t.throwsAsync(execa('noop.js', getStdio(index, writableStream)));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 69–71why, one step back69 t.is(originalMessage, 'foobar');70};71Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 72–74why, one step back72test('stdout option handles errors in WritableStream', testWritableStreamError, 1);73test('stderr option handles errors in WritableStream', testWritableStreamError, 2);74test('stdio[*] option handles errors in WritableStream', testWritableStreamError, 3);