web-stream.js
This file
Path
test/stdio/web-stream.js
111 lines · 4.7 KiB · JavaScript
Last changed by
Fix CISindre Sorhusbefore adoptioncfac59f
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 {Readable} from 'node:stream';3import {setImmediate} from 'node:timers/promises';TweaksSindre Sorhusbefore adoption698a1b8
lines 4–5why, one step back4import test from 'node:test';5import {assertThrows, assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 6–11why, one step back6import {execa, execaSync} from '../../index.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {getStdio} from '../helpers/stdio.js';910setFixtureDirectory();11TweaksSindre Sorhusbefore adoption698a1b8
line 12why, one step back12const testReadableStream = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 13–14why, one step back13 const readableStream = Readable.toWeb(Readable.from('foobar'));14 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream));TweaksSindre Sorhusbefore adoption698a1b8
line 15why, one step back15 assert.equal(stdout, 'foobar');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 16–17why, one step back16};17TweaksSindre Sorhusbefore adoption698a1b8
lines 18–19why, one step back18test('stdin can be a ReadableStream', () => testReadableStream(0));19test('stdio[*] can be a ReadableStream', () => testReadableStream(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 20why, one step back20TweaksSindre Sorhusbefore adoption698a1b8
line 21why, one step back21const testWritableStream = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 22–28why, one step back22 const result = [];23 const writableStream = new WritableStream({24 write(chunk) {25 result.push(chunk);26 },27 });28 await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, writableStream));TweaksSindre Sorhusbefore adoption698a1b8
line 29why, one step back29 assert.equal(result.join(''), 'foobar');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 30–31why, one step back30};31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–34why, one step back32test('stdout can be a WritableStream', () => testWritableStream(1));33test('stderr can be a WritableStream', () => testWritableStream(2));34test('stdio[*] can be a WritableStream', () => testWritableStream(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 35why, one step back35TweaksSindre Sorhusbefore adoption698a1b8
lines 36–37why, one step back36const testWebStreamSync = (StreamClass, fdNumber, optionName) => {37 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 38–41why, one step back38 execaSync('empty.js', getStdio(fdNumber, new StreamClass()));39 }, {message: `The \`${optionName}\` option cannot be a web stream with synchronous methods.`});40};41TweaksSindre Sorhusbefore adoption698a1b8
lines 42–46why, one step back42test('stdin cannot be a ReadableStream - sync', () => testWebStreamSync(ReadableStream, 0, 'stdin'));43test('stdio[*] cannot be a ReadableStream - sync', () => testWebStreamSync(ReadableStream, 3, 'stdio[3]'));44test('stdout cannot be a WritableStream - sync', () => testWebStreamSync(WritableStream, 1, 'stdout'));45test('stderr cannot be a WritableStream - sync', () => testWebStreamSync(WritableStream, 2, 'stderr'));46test('stdio[*] cannot be a WritableStream - sync', () => testWebStreamSync(WritableStream, 3, 'stdio[3]'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 47why, one step back47TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48const testLongWritableStream = async fdNumber => {Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 49why, one step back49 let isResult = false;100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 50–52why, one step back50 const writableStream = new WritableStream({51 async close() {52 await setImmediate();Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 53why, one step back53 isResult = true;100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 54–56why, one step back54 },55 });56 await execa('empty.js', getStdio(fdNumber, writableStream));TweaksSindre Sorhusbefore adoption698a1b8
line 57why, one step back57 assert.equal(isResult, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 58–59why, one step back58};59TweaksSindre Sorhusbefore adoption698a1b8
lines 60–62why, one step back60test('stdout waits for WritableStream completion', () => testLongWritableStream(1));61test('stderr waits for WritableStream completion', () => testLongWritableStream(2));62test('stdio[*] waits for WritableStream completion', () => testLongWritableStream(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 63why, one step back63TweaksSindre Sorhusbefore adoption698a1b8
line 64why, one step back64const testWritableStreamError = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 65–70why, one step back65 const cause = new Error('foobar');66 const writableStream = new WritableStream({67 start(controller) {68 controller.error(cause);69 },70 });TweaksSindre Sorhusbefore adoption698a1b8
lines 71–72why, one step back71 const error = await assertRejects(execa('noop.js', getStdio(fdNumber, writableStream)));72 assert.equal(error.cause, cause);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 73–74why, one step back73};74TweaksSindre Sorhusbefore adoption698a1b8
lines 75–77why, one step back75test('stdout option handles errors in WritableStream', () => testWritableStreamError(1));76test('stderr option handles errors in WritableStream', () => testWritableStreamError(2));77test('stdio[*] option handles errors in WritableStream', () => testWritableStreamError(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 78why, one step back78TweaksSindre Sorhusbefore adoption698a1b8
line 79why, one step back79const testReadableStreamError = async fdNumber => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 80–85why, one step back80 const cause = new Error('foobar');81 const readableStream = new ReadableStream({82 start(controller) {83 controller.error(cause);84 },85 });TweaksSindre Sorhusbefore adoption698a1b8
lines 86–87why, one step back86 const error = await assertRejects(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream)));87 assert.equal(error.cause, cause);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 88–89why, one step back88};89TweaksSindre Sorhusbefore adoption698a1b8
lines 90–91why, one step back90test('stdin option handles errors in ReadableStream', () => testReadableStreamError(0));91test('stdio[*] option handles errors in ReadableStream', () => testReadableStreamError(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 92why, one step back92TweaksSindre Sorhusbefore adoption698a1b8
line 93why, one step back93test('ReadableStream with stdin is canceled on subprocess exit', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 94–97why, one step back94 let readableStream;95 const promise = new Promise(resolve => {96 readableStream = new ReadableStream({cancel: resolve});97 });TweaksSindre Sorhusbefore adoption698a1b8
line 98why, one step back98 await assertRejects(execa('stdin.js', {stdin: readableStream, timeout: 1}), {message: /timed out/});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 99–100why, one step back99 await promise;100});Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 101–103why, one step back101102// A web stream can only be used once, but like Node.js streams, the same instance103// passed to multiple file descriptors should send its data to each of them.TweaksSindre Sorhusbefore adoption698a1b8
line 104why, one step back104const testSharedReadableStream = async (fixtureArguments, stdio) => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
line 105why, one step back105 const readableStream = Readable.toWeb(Readable.from('foobar'));Fix CISindre Sorhusbefore adoptioncfac59f
lines 106–107why, one step back106 const {stdout} = await execa('stdin-fds.js', fixtureArguments, {stdio: stdio.map(value => value === 'shared' ? readableStream : value)});107 assert.equal(stdout, 'foobarfoobar');Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 108–109why, one step back108};109Fix CISindre Sorhusbefore adoptioncfac59f
lines 110–111why, one step back110test('stdin can share a ReadableStream with stdio[*]', () => testSharedReadableStream(['0', '3'], ['shared', 'pipe', 'pipe', 'shared']));111test('stdio[*] can share a ReadableStream with another stdio[*]', () => testSharedReadableStream(['3', '4'], ['pipe', 'pipe', 'pipe', 'shared', 'shared']));