Skip to content
Myr

web.js

This file

Path

test/convert/web.js

105 lines · 3.1 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

line 2why, one step back
2import {ReadableStream, WritableStream} from 'node:stream/web';

TweaksSindre Sorhusbefore adoption698a1b8

line 3why, one step back
3import test from 'node:test';

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 4–25why, one step back
4import {execa} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {7 assertStreamOutput,8 assertStreamReadError,9 assertSubprocessOutput,10 assertSubprocessError,11 assertPromiseError,12 getReadableSubprocess,13 getWritableSubprocess,14 getReadWriteSubprocess,15} from '../helpers/convert.js';16import {foobarString} from '../helpers/input.js';1718setFixtureDirectory();1920const writeToStream = async (stream, input = foobarString) => {21 const writer = stream.getWriter();22 await writer.write(new TextEncoder().encode(input));23 await writer.close();24};25

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26test('.readableStream() success', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 27–29why, one step back
27 const subprocess = getReadableSubprocess();
28 const stream = subprocess.readableStream();29

TweaksSindre Sorhusbefore adoption698a1b8

line 30why, one step back
30 assert.ok(stream instanceof ReadableStream);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

line 31why, one step back
31

TweaksSindre Sorhusbefore adoption698a1b8

lines 32–33why, one step back
32 await assertStreamOutput(stream);
33 await assertSubprocessOutput(subprocess);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 34–35why, one step back
34});
35

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36test('.readableStream() can use from', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 37–39why, one step back
37 const subprocess = execa('noop-fd.js', ['2', foobarString]);
38 const stream = subprocess.readableStream({from: 'stderr'});39

TweaksSindre Sorhusbefore adoption698a1b8

line 40why, one step back
40 await assertStreamOutput(stream);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 41–42why, one step back
41});
42

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43test('.writableStream() success', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 44–46why, one step back
44 const subprocess = getWritableSubprocess();
45 const stream = subprocess.writableStream();46

TweaksSindre Sorhusbefore adoption698a1b8

line 47why, one step back
47 assert.ok(stream instanceof WritableStream);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 48–49why, one step back
48
49 await writeToStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

line 50why, one step back
50 await assertSubprocessOutput(subprocess, foobarString, 2);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 51–52why, one step back
51});
52

TweaksSindre Sorhusbefore adoption698a1b8

line 53why, one step back
53test('.writableStream() can use to', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 54–57why, one step back
54 const subprocess = execa('stdin-fd.js', ['0']);
55 const stream = subprocess.writableStream({to: 'stdin'});5657 await writeToStream(stream);

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58 await assertSubprocessOutput(subprocess);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 59–60why, one step back
59});
60

TweaksSindre Sorhusbefore adoption698a1b8

line 61why, one step back
61test('.transformStream() success', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 62–64why, one step back
62 const subprocess = getReadWriteSubprocess();
63 const {readable, writable} = subprocess.transformStream();64

TweaksSindre Sorhusbefore adoption698a1b8

lines 65–66why, one step back
65 assert.ok(readable instanceof ReadableStream);
66 assert.ok(writable instanceof WritableStream);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 67–68why, one step back
67
68 await writeToStream(writable);

TweaksSindre Sorhusbefore adoption698a1b8

lines 69–70why, one step back
69 await assertStreamOutput(readable);
70 await assertSubprocessOutput(subprocess);

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 71–72why, one step back
71});
72

TweaksSindre Sorhusbefore adoption698a1b8

line 73why, one step back
73test('subprocess fail -> .readableStream() error', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 74–79why, one step back
74 const subprocess = getReadWriteSubprocess();
75 const stream = subprocess.readableStream();7677 const cause = new Error(foobarString);78 subprocess.kill(cause);79

TweaksSindre Sorhusbefore adoption698a1b8

lines 80–81why, one step back
80 await assertStreamReadError(stream, {cause});
81 await assertSubprocessError(subprocess, {cause});

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

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

TweaksSindre Sorhusbefore adoption698a1b8

line 84why, one step back
84test('subprocess fail -> .writableStream() error', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 85–91why, one step back
85 const subprocess = getReadWriteSubprocess();
86 const stream = subprocess.writableStream();87 const writer = stream.getWriter();8889 const cause = new Error(foobarString);90 subprocess.kill(cause);91

TweaksSindre Sorhusbefore adoption698a1b8

lines 92–93why, one step back
92 await assertPromiseError(writer.closed, {cause});
93 await assertSubprocessError(subprocess, {cause});

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 94–95why, one step back
94});
95

TweaksSindre Sorhusbefore adoption698a1b8

line 96why, one step back
96test('subprocess fail -> .transformStream() error', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 97–102why, one step back
97 const subprocess = getReadWriteSubprocess();
98 const {readable} = subprocess.transformStream();99100 const cause = new Error(foobarString);101 subprocess.kill(cause);102

TweaksSindre Sorhusbefore adoption698a1b8

lines 103–104why, one step back
103 await assertStreamReadError(readable, {cause});
104 await assertSubprocessError(subprocess, {cause});

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

line 105why, one step back
105});