Skip to content
Myr

duplex.js

This file

Path

test/stdio/duplex.js

64 lines · 2.8 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

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–4why, one step back
2import {createHash} from 'node:crypto';
3import {promisify} from 'node:util';4import {createGzip, gunzip} from 'node:zlib';

TweaksSindre Sorhusbefore adoption698a1b8

lines 5–6why, one step back
5import test from 'node:test';
6import {assertThrows} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 7–18why, one step back
7import {execa} from '../../index.js';
8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {10 foobarString,11 foobarObject,12 foobarUppercase,13 foobarUppercaseHex,14} from '../helpers/input.js';15import {uppercaseEncodingDuplex, getOutputDuplex} from '../helpers/duplex.js';1617setFixtureDirectory();18

TweaksSindre Sorhusbefore adoption698a1b8

line 19why, one step back
19test('Can use crypto.createHash()', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 20–21why, one step back
20 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform: createHash('sha1')}, encoding: 'hex'});
21 const expectedStdout = createHash('sha1').update(foobarString).digest('hex');

TweaksSindre Sorhusbefore adoption698a1b8

line 22why, one step back
22 assert.equal(stdout, expectedStdout);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 25why, one step back
25test('Can use zlib.createGzip()', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 26–27why, one step back
26 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform: createGzip()}, encoding: 'buffer'});
27 const decompressedStdout = await promisify(gunzip)(stdout);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 29–30why, one step back
29});
30

TweaksSindre Sorhusbefore adoption698a1b8

line 31why, one step back
31test('Can use encoding "hex"', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 32why, one step back
32 const {transform} = uppercaseEncodingDuplex('hex')();

TweaksSindre Sorhusbefore adoption698a1b8

line 33why, one step back
33 assert.equal(transform.readableEncoding, 'hex');

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 34why, one step back
34 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform}});

TweaksSindre Sorhusbefore adoption698a1b8

line 35why, one step back
35 assert.equal(stdout, foobarUppercaseHex);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 36–37why, one step back
36});
37

TweaksSindre Sorhusbefore adoption698a1b8

lines 38–39why, one step back
38test('Cannot use objectMode: true with duplex.readableObjectMode: false', () => {
39 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 40–43why, one step back
40 execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, false)(true)});
41 }, {message: /cannot be `false` if `new Duplex\({objectMode: true}\)`/});42});43

TweaksSindre Sorhusbefore adoption698a1b8

lines 44–45why, one step back
44test('Cannot use objectMode: false with duplex.readableObjectMode: true', () => {
45 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 46–49why, one step back
46 execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, true)(false)});
47 }, {message: /can only be `true` if `new Duplex\({objectMode: true}\)`/});48});49

TweaksSindre Sorhusbefore adoption698a1b8

line 50why, one step back
50const testObjectModeFalse = async objectMode => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 51why, one step back
51 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, objectMode)(false)});

TweaksSindre Sorhusbefore adoption698a1b8

line 52why, one step back
52 assert.equal(stdout, foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 53–54why, one step back
53};
54

TweaksSindre Sorhusbefore adoption698a1b8

lines 55–56why, one step back
55test('Can use objectMode: false with duplex.readableObjectMode: false', () => testObjectModeFalse(false));
56test('Can use objectMode: undefined with duplex.readableObjectMode: false', () => testObjectModeFalse(undefined));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 57why, one step back
57

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58const testObjectModeTrue = async objectMode => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 59why, one step back
59 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: getOutputDuplex(foobarObject, objectMode)(true)});

TweaksSindre Sorhusbefore adoption698a1b8

line 60why, one step back
60 assert.deepEqual(stdout, [foobarObject]);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 61–62why, one step back
61};
62

TweaksSindre Sorhusbefore adoption698a1b8

lines 63–64why, one step back
63test('Can use objectMode: true with duplex.readableObjectMode: true', () => testObjectModeTrue(true));
64test('Can use objectMode: undefined with duplex.readableObjectMode: true', () => testObjectModeTrue(undefined));