encoding-multibyte.js
This file
Path
test/transform/encoding-multibyte.js
81 lines · 3.9 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
lines 1–2why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 3–17why, one step back3import {execa, execaSync} from '../../index.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {noopGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';6import {7 multibyteChar,8 multibyteString,9 multibyteUint8Array,10 breakingLength,11 brokenSymbol,12} from '../helpers/encoding.js';1314setFixtureDirectory();1516const foobarArray = ['fo', 'ob', 'ar', '..'];17TweaksSindre Sorhusbefore adoption698a1b8
line 18why, one step back18const testMultibyteCharacters = async (objectMode, addNoopTransform, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 19–23why, one step back19 const {stdout} = await execaMethod('noop.js', {20 stdout: addNoopGenerator(getOutputsGenerator(foobarArray)(objectMode, true), addNoopTransform, objectMode),21 encoding: 'base64',22 });23 if (objectMode) {TweaksSindre Sorhusbefore adoption698a1b8
line 24why, one step back24 assert.deepEqual(stdout, foobarArray);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 25why, one step back25 } else {Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 26why, one step back26 // eslint-disable-next-line n/prefer-global/buffer -- `Uint8Array#toBase64()` is not available on the minimum supported Node.js versionTweaksSindre Sorhusbefore adoption698a1b8
line 27why, one step back27 assert.equal(stdout, Buffer.from(foobarArray.join('')).toString('base64'));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 28–30why, one step back28 }29};30TweaksSindre Sorhusbefore adoption698a1b8
lines 31–38why, one step back31test('Handle multibyte characters', () => testMultibyteCharacters(false, false, execa));32test('Handle multibyte characters, noop transform', () => testMultibyteCharacters(false, true, execa));33test('Handle multibyte characters, with objectMode', () => testMultibyteCharacters(true, false, execa));34test('Handle multibyte characters, with objectMode, noop transform', () => testMultibyteCharacters(true, true, execa));35test('Handle multibyte characters, sync', () => testMultibyteCharacters(false, false, execaSync));36test('Handle multibyte characters, noop transform, sync', () => testMultibyteCharacters(false, true, execaSync));37test('Handle multibyte characters, with objectMode, sync', () => testMultibyteCharacters(true, false, execaSync));38test('Handle multibyte characters, with objectMode, noop transform, sync', () => testMultibyteCharacters(true, true, execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 39why, one step back39TweaksSindre Sorhusbefore adoption698a1b8
line 40why, one step back40const testMultibyte = async (objectMode, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 41–46why, one step back41 const {stdout} = await execaMethod('stdin.js', {42 stdin: [43 [multibyteUint8Array.slice(0, breakingLength), multibyteUint8Array.slice(breakingLength)],44 noopGenerator(objectMode, true),45 ],46 });TweaksSindre Sorhusbefore adoption698a1b8
line 47why, one step back47 assert.equal(stdout, multibyteString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 48–49why, one step back48};49TweaksSindre Sorhusbefore adoption698a1b8
lines 50–53why, one step back50test('Generator handles multibyte characters with Uint8Array', () => testMultibyte(false, execa));51test('Generator handles multibyte characters with Uint8Array, objectMode', () => testMultibyte(true, execa));52test('Generator handles multibyte characters with Uint8Array, sync', () => testMultibyte(false, execaSync));53test('Generator handles multibyte characters with Uint8Array, objectMode, sync', () => testMultibyte(true, execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 54why, one step back54TweaksSindre Sorhusbefore adoption698a1b8
line 55why, one step back55const testMultibytePartial = async (objectMode, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 56–61why, one step back56 const {stdout} = await execaMethod('stdin.js', {57 stdin: [58 [multibyteUint8Array.slice(0, breakingLength)],59 noopGenerator(objectMode, true),60 ],61 });TweaksSindre Sorhusbefore adoption698a1b8
line 62why, one step back62 assert.equal(stdout, `${multibyteChar}${brokenSymbol}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 63–64why, one step back63};64TweaksSindre Sorhusbefore adoption698a1b8
lines 65–68why, one step back65test('Generator handles partial multibyte characters with Uint8Array', () => testMultibytePartial(false, execa));66test('Generator handles partial multibyte characters with Uint8Array, objectMode', () => testMultibytePartial(true, execa));67test('Generator handles partial multibyte characters with Uint8Array, sync', () => testMultibytePartial(false, execaSync));68test('Generator handles partial multibyte characters with Uint8Array, objectMode, sync', () => testMultibytePartial(true, execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 69why, one step back69TweaksSindre Sorhusbefore adoption698a1b8
line 70why, one step back70const testMultibytePartialOutput = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 71–76why, one step back71 const {stdout} = await execaMethod('noop.js', {72 stdout: getOutputsGenerator([73 multibyteUint8Array.slice(0, breakingLength),74 multibyteUint8Array.slice(breakingLength),75 ])(false, true),76 });TweaksSindre Sorhusbefore adoption698a1b8
line 77why, one step back77 assert.equal(stdout, multibyteString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 78–79why, one step back78};79TweaksSindre Sorhusbefore adoption698a1b8
lines 80–81why, one step back80test('Generator handles output multibyte characters with Uint8Array', () => testMultibytePartialOutput(execa));81test('Generator handles output multibyte characters with Uint8Array, sync', () => testMultibytePartialOutput(execaSync));