duplex.js
This file
Path
test/stdio/duplex.js
64 lines · 2.8 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
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–4why, one step back2import {createHash} from 'node:crypto';3import {promisify} from 'node:util';4import {createGzip, gunzip} from 'node:zlib';TweaksSindre Sorhusbefore adoption698a1b8
lines 5–6why, one step back5import test from 'node:test';6import {assertThrows} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 7–18why, one step back7import {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();18TweaksSindre Sorhusbefore adoption698a1b8
line 19why, one step back19test('Can use crypto.createHash()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 20–21why, one step back20 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 back22 assert.equal(stdout, expectedStdout);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 23–24why, one step back23});24TweaksSindre Sorhusbefore adoption698a1b8
line 25why, one step back25test('Can use zlib.createGzip()', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 26–27why, one step back26 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 back28 assert.equal(decompressedStdout.toString(), foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 29–30why, one step back29});30TweaksSindre Sorhusbefore adoption698a1b8
line 31why, one step back31test('Can use encoding "hex"', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 32why, one step back32 const {transform} = uppercaseEncodingDuplex('hex')();TweaksSindre Sorhusbefore adoption698a1b8
line 33why, one step back33 assert.equal(transform.readableEncoding, 'hex');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 34why, one step back34 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform}});TweaksSindre Sorhusbefore adoption698a1b8
line 35why, one step back35 assert.equal(stdout, foobarUppercaseHex);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 36–37why, one step back36});37TweaksSindre Sorhusbefore adoption698a1b8
lines 38–39why, one step back38test('Cannot use objectMode: true with duplex.readableObjectMode: false', () => {39 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 40–43why, one step back40 execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, false)(true)});41 }, {message: /cannot be `false` if `new Duplex\({objectMode: true}\)`/});42});43TweaksSindre Sorhusbefore adoption698a1b8
lines 44–45why, one step back44test('Cannot use objectMode: false with duplex.readableObjectMode: true', () => {45 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 46–49why, one step back46 execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, true)(false)});47 }, {message: /can only be `true` if `new Duplex\({objectMode: true}\)`/});48});49TweaksSindre Sorhusbefore adoption698a1b8
line 50why, one step back50const testObjectModeFalse = async objectMode => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 51why, one step back51 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, objectMode)(false)});TweaksSindre Sorhusbefore adoption698a1b8
line 52why, one step back52 assert.equal(stdout, foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 53–54why, one step back53};54TweaksSindre Sorhusbefore adoption698a1b8
lines 55–56why, one step back55test('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 back57TweaksSindre Sorhusbefore adoption698a1b8
line 58why, one step back58const testObjectModeTrue = async objectMode => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 59why, one step back59 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: getOutputDuplex(foobarObject, objectMode)(true)});TweaksSindre Sorhusbefore adoption698a1b8
line 60why, one step back60 assert.deepEqual(stdout, [foobarObject]);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 61–62why, one step back61};62TweaksSindre Sorhusbefore adoption698a1b8
lines 63–64why, one step back63test('Can use objectMode: true with duplex.readableObjectMode: true', () => testObjectModeTrue(true));64test('Can use objectMode: undefined with duplex.readableObjectMode: true', () => testObjectModeTrue(undefined));