validate.js
This file
Path
test/stdio/validate.js
60 lines · 4.8 KiB · JavaScript
Last changed by
Strip newlines in transforms (#919)ehmickybefore adoption26e9150
History of this fileTake it
Use `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3
line 1why, one step back1import {Buffer} from 'node:buffer';Split files (#837)ehmickybefore adoption672c2d7
lines 2–5why, one step back2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {getStdio} from '../helpers/stdio.js';Use `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3
line 6why, one step back6import {foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';Split files (#837)ehmickybefore adoption672c2d7
lines 7–11why, one step back7import {serializeGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';89setFixtureDir();1011// eslint-disable-next-line max-paramsUse `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3
lines 12–16why, one step back12const testGeneratorReturn = async (t, fdNumber, generator, input, objectMode, isInput) => {13 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';14 const subprocess = execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input, objectMode)));15 const {message} = await t.throwsAsync(subprocess);16 t.true(message.includes(getMessage(input)));Split files (#837)ehmickybefore adoption672c2d7
lines 17–18why, one step back17};18Use `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3
lines 19–30why, one step back19const getMessage = input => {20 if (input === null || input === undefined) {21 return 'not be called at all';22 }2324 if (Buffer.isBuffer(input)) {25 return 'not a buffer';26 }2728 return 'a string or an Uint8Array';29};30Split files (#837)ehmickybefore adoption672c2d7
line 31why, one step back31const lastInputGenerator = (input, objectMode) => [foobarUint8Array, getOutputGenerator(input, objectMode)];Strip newlines in transforms (#919)ehmickybefore adoption26e9150
line 32why, one step back32const inputGenerator = (input, objectMode) => [...lastInputGenerator(input, objectMode), serializeGenerator(true)];Split files (#837)ehmickybefore adoption672c2d7
line 33why, one step back33Use `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3
lines 34–55why, one step back34test('Generators with result.stdin cannot return an object if not in objectMode', testGeneratorReturn, 0, inputGenerator, foobarObject, false, true);35test('Generators with result.stdio[*] as input cannot return an object if not in objectMode', testGeneratorReturn, 3, inputGenerator, foobarObject, false, true);36test('The last generator with result.stdin cannot return an object even in objectMode', testGeneratorReturn, 0, lastInputGenerator, foobarObject, true, true);37test('The last generator with result.stdio[*] as input cannot return an object even in objectMode', testGeneratorReturn, 3, lastInputGenerator, foobarObject, true, true);38test('Generators with result.stdout cannot return an object if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, foobarObject, false, false);39test('Generators with result.stderr cannot return an object if not in objectMode', testGeneratorReturn, 2, getOutputGenerator, foobarObject, false, false);40test('Generators with result.stdio[*] as output cannot return an object if not in objectMode', testGeneratorReturn, 3, getOutputGenerator, foobarObject, false, false);41test('Generators with result.stdin cannot return a Buffer if not in objectMode', testGeneratorReturn, 0, inputGenerator, foobarBuffer, false, true);42test('Generators with result.stdio[*] as input cannot return a Buffer if not in objectMode', testGeneratorReturn, 3, inputGenerator, foobarBuffer, false, true);43test('The last generator with result.stdin cannot return a Buffer even in objectMode', testGeneratorReturn, 0, lastInputGenerator, foobarBuffer, true, true);44test('The last generator with result.stdio[*] as input cannot return a Buffer even in objectMode', testGeneratorReturn, 3, lastInputGenerator, foobarBuffer, true, true);45test('Generators with result.stdout cannot return a Buffer if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, foobarBuffer, false, false);46test('Generators with result.stderr cannot return a Buffer if not in objectMode', testGeneratorReturn, 2, getOutputGenerator, foobarBuffer, false, false);47test('Generators with result.stdio[*] as output cannot return a Buffer if not in objectMode', testGeneratorReturn, 3, getOutputGenerator, foobarBuffer, false, false);48test('Generators with result.stdin cannot return null if not in objectMode', testGeneratorReturn, 0, inputGenerator, null, false, true);49test('Generators with result.stdin cannot return null if in objectMode', testGeneratorReturn, 0, inputGenerator, null, true, true);50test('Generators with result.stdout cannot return null if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, null, false, false);51test('Generators with result.stdout cannot return null if in objectMode', testGeneratorReturn, 1, getOutputGenerator, null, true, false);52test('Generators with result.stdin cannot return undefined if not in objectMode', testGeneratorReturn, 0, inputGenerator, undefined, false, true);53test('Generators with result.stdin cannot return undefined if in objectMode', testGeneratorReturn, 0, inputGenerator, undefined, true, true);54test('Generators with result.stdout cannot return undefined if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, undefined, false, false);55test('Generators with result.stdout cannot return undefined if in objectMode', testGeneratorReturn, 1, getOutputGenerator, undefined, true, false);Split files (#837)ehmickybefore adoption672c2d7
lines 56–57why, one step back5657test('Generators "final" return value is validated', async t => {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 58–59why, one step back58 const subprocess = execa('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null, true), true)});59 await t.throwsAsync(subprocess, {message: /not be called at all/});Split files (#837)ehmickybefore adoption672c2d7
line 60why, one step back60});