Skip to content
Myr

web-transform.js

This file

Path

test/stdio/web-transform.js

58 lines · 2.8 KiB · JavaScript

Last changed by

Fix `stdin` iterables and input transforms edge casesSindre Sorhusbefore adoption6925cc3

History of this file

Take it

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

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 2–3why, one step back
2import {promisify} from 'node:util';
3import {gunzip} from 'node:zlib';

TweaksSindre Sorhusbefore adoption698a1b8

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

Fix `stdin` iterables and input transforms edge casesSindre Sorhusbefore adoption6925cc3

line 5why, one step back
5import {assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 6–7why, one step back
6import {execa} from '../../index.js';
7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

Fix `stdin` iterables and input transforms edge casesSindre Sorhusbefore adoption6925cc3

lines 8–16why, one step back
8import {
9 foobarString,10 foobarUtf16Uint8Array,11 foobarUint8Array,12 foobarObject,13 foobarObjectString,14} from '../helpers/input.js';15import {outputObjectGenerator} from '../helpers/generator.js';16import {serializeWebTransform, outputObjectWebTransform, noopWebTransform} from '../helpers/web-transform.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 17–19why, one step back
17
18setFixtureDirectory();19

TweaksSindre Sorhusbefore adoption698a1b8

line 20why, one step back
20test('Can use CompressionStream()', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 21–22why, one step back
21 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: new CompressionStream('gzip'), encoding: 'buffer'});
22 const decompressedStdout = await promisify(gunzip)(stdout);

TweaksSindre Sorhusbefore adoption698a1b8

line 23why, one step back
23 assert.equal(decompressedStdout.toString(), foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 24–25why, one step back
24});
25

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26test('Can use TextDecoderStream()', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 27–31why, one step back
27 const {stdout} = await execa('stdin.js', {
28 input: foobarUtf16Uint8Array,29 stdout: new TextDecoderStream('utf-16le'),30 encoding: 'buffer',31 });

TweaksSindre Sorhusbefore adoption698a1b8

line 32why, one step back
32 assert.deepEqual(stdout, foobarUint8Array);

Fix `stdin` iterables and input transforms edge casesSindre Sorhusbefore adoption6925cc3

lines 33–57why, one step back
33});
3435// A `TransformStream` has no `objectMode` of its own, so the `objectMode` option applies to its output, while its input uses the previous transform's36const testWebTransformObjectModeFalse = async (getTransforms, expectedOutput) => {37 const {stdout} = await execa('noop.js', [foobarString], {stdout: getTransforms()});38 assert.deepEqual(stdout, expectedOutput);39};4041test('TransformStream with "objectMode: false" can follow an objectMode transform', () => testWebTransformObjectModeFalse(() => [outputObjectGenerator(), serializeWebTransform(false)], foobarObjectString));42test('TransformStream with "objectMode: false" can follow an objectMode TransformStream', () => testWebTransformObjectModeFalse(() => [outputObjectWebTransform(), serializeWebTransform(false)], foobarObjectString));43test('TransformStream with "objectMode: false" splits lines after an objectMode transform', () => testWebTransformObjectModeFalse(() => [outputObjectGenerator(), {44 transform: new TransformStream({45 transform(object, controller) {46 controller.enqueue(`${JSON.stringify(object)}\n${JSON.stringify(object)}\n`);47 },48 }),49 objectMode: false,50}], `${foobarObjectString}\n${foobarObjectString}`));51test('TransformStream with "objectMode: true" can follow a TransformStream with "objectMode: false"', () => testWebTransformObjectModeFalse(() => [noopWebTransform(false), outputObjectWebTransform()], [foobarObject]));5253test('Destroying subprocess.stdin fails the subprocess when it is a TransformStream', async () => {54 const subprocess = execa('stdin.js', {stdin: new TransformStream()});55 subprocess.stdin.destroy();56 const {cause} = await assertRejects(subprocess);57 assert.equal(cause.code, 'ABORT_ERR');

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 58why, one step back
58});