Skip to content
Myr

validate.js

This file

Path

test/stdio/validate.js

95 lines · 8.1 KiB · JavaScript

Last changed by

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

History of this file

Take it

Use `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3

line 1why, one step back
1import {Buffer} from 'node:buffer';

Split files (#837)ehmickybefore adoption672c2d7

line 2why, one step back
2import test from 'ava';

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

line 3why, one step back
3import {execa, execaSync} from '../../index.js';

Split files (#837)ehmickybefore adoption672c2d7

lines 4–5why, one step back
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 back
6import {foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';

Split files (#837)ehmickybefore adoption672c2d7

lines 7–10why, one step back
7import {serializeGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';
89setFixtureDir();10

Use `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3

lines 11–22why, one step back
11const getMessage = input => {
12 if (input === null || input === undefined) {13 return 'not be called at all';14 }1516 if (Buffer.isBuffer(input)) {17 return 'not a buffer';18 }1920 return 'a string or an Uint8Array';21};22

Refactor tests (#934)ehmickybefore adoption52c4bde

lines 23–24why, one step back
23const lastInputGenerator = input => objectMode => [foobarUint8Array, getOutputGenerator(input)(objectMode)];
24const inputGenerator = input => objectMode => [...lastInputGenerator(input)(objectMode), serializeGenerator(true)];

Split files (#837)ehmickybefore adoption672c2d7

line 25why, one step back
25

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 26–32why, one step back
26// eslint-disable-next-line max-params
27const testGeneratorReturn = async (t, fdNumber, generator, input, objectMode, isInput) => {28 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';29 const {message} = await t.throwsAsync(execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input)(objectMode))));30 t.true(message.includes(getMessage(input)));31};32

Use `Uint8Array` instead of `Buffer` (#915)ehmickybefore adoption410bac3

lines 33–54why, one step back
33test('Generators with result.stdin cannot return an object if not in objectMode', testGeneratorReturn, 0, inputGenerator, foobarObject, false, true);
34test('Generators with result.stdio[*] as input cannot return an object if not in objectMode', testGeneratorReturn, 3, inputGenerator, foobarObject, false, true);35test('The last generator with result.stdin cannot return an object even in objectMode', testGeneratorReturn, 0, lastInputGenerator, foobarObject, true, true);36test('The last generator with result.stdio[*] as input cannot return an object even in objectMode', testGeneratorReturn, 3, lastInputGenerator, foobarObject, true, true);37test('Generators with result.stdout cannot return an object if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, foobarObject, false, false);38test('Generators with result.stderr cannot return an object if not in objectMode', testGeneratorReturn, 2, getOutputGenerator, foobarObject, false, false);39test('Generators with result.stdio[*] as output cannot return an object if not in objectMode', testGeneratorReturn, 3, getOutputGenerator, foobarObject, false, false);40test('Generators with result.stdin cannot return a Buffer if not in objectMode', testGeneratorReturn, 0, inputGenerator, foobarBuffer, false, true);41test('Generators with result.stdio[*] as input cannot return a Buffer if not in objectMode', testGeneratorReturn, 3, inputGenerator, foobarBuffer, false, true);42test('The last generator with result.stdin cannot return a Buffer even in objectMode', testGeneratorReturn, 0, lastInputGenerator, foobarBuffer, true, true);43test('The last generator with result.stdio[*] as input cannot return a Buffer even in objectMode', testGeneratorReturn, 3, lastInputGenerator, foobarBuffer, true, true);44test('Generators with result.stdout cannot return a Buffer if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, foobarBuffer, false, false);45test('Generators with result.stderr cannot return a Buffer if not in objectMode', testGeneratorReturn, 2, getOutputGenerator, foobarBuffer, false, false);46test('Generators with result.stdio[*] as output cannot return a Buffer if not in objectMode', testGeneratorReturn, 3, getOutputGenerator, foobarBuffer, false, false);47test('Generators with result.stdin cannot return null if not in objectMode', testGeneratorReturn, 0, inputGenerator, null, false, true);48test('Generators with result.stdin cannot return null if in objectMode', testGeneratorReturn, 0, inputGenerator, null, true, true);49test('Generators with result.stdout cannot return null if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, null, false, false);50test('Generators with result.stdout cannot return null if in objectMode', testGeneratorReturn, 1, getOutputGenerator, null, true, false);51test('Generators with result.stdin cannot return undefined if not in objectMode', testGeneratorReturn, 0, inputGenerator, undefined, false, true);52test('Generators with result.stdin cannot return undefined if in objectMode', testGeneratorReturn, 0, inputGenerator, undefined, true, true);53test('Generators with result.stdout cannot return undefined if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, undefined, false, false);54test('Generators with result.stdout cannot return undefined if in objectMode', testGeneratorReturn, 1, getOutputGenerator, undefined, true, false);

Split files (#837)ehmickybefore adoption672c2d7

line 55why, one step back
55

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 56–83why, one step back
56// eslint-disable-next-line max-params
57const testGeneratorReturnSync = (t, fdNumber, generator, input, objectMode, isInput) => {58 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';59 const {message} = t.throws(() => {60 execaSync(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input)(objectMode)));61 });62 t.true(message.includes(getMessage(input)));63};6465test('Generators with result.stdin cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, foobarObject, false, true);66test('The last generator with result.stdin cannot return an object even in objectMode, sync', testGeneratorReturnSync, 0, lastInputGenerator, foobarObject, true, true);67test('Generators with result.stdout cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, foobarObject, false, false);68test('Generators with result.stderr cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 2, getOutputGenerator, foobarObject, false, false);69test('Generators with result.stdio[*] as output cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 3, getOutputGenerator, foobarObject, false, false);70test('Generators with result.stdin cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, foobarBuffer, false, true);71test('The last generator with result.stdin cannot return a Buffer even in objectMode, sync', testGeneratorReturnSync, 0, lastInputGenerator, foobarBuffer, true, true);72test('Generators with result.stdout cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, foobarBuffer, false, false);73test('Generators with result.stderr cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 2, getOutputGenerator, foobarBuffer, false, false);74test('Generators with result.stdio[*] as output cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 3, getOutputGenerator, foobarBuffer, false, false);75test('Generators with result.stdin cannot return null if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, null, false, true);76test('Generators with result.stdin cannot return null if in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, null, true, true);77test('Generators with result.stdout cannot return null if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, null, false, false);78test('Generators with result.stdout cannot return null if in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, null, true, false);79test('Generators with result.stdin cannot return undefined if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, undefined, false, true);80test('Generators with result.stdin cannot return undefined if in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, undefined, true, true);81test('Generators with result.stdout cannot return undefined if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, undefined, false, false);82test('Generators with result.stdout cannot return undefined if in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, undefined, true, false);83

Split files (#837)ehmickybefore adoption672c2d7

line 84why, one step back
84test('Generators "final" return value is validated', async t => {

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 85–94why, one step back
85 await t.throwsAsync(
86 execa('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null)(true), true)}),87 {message: /not be called at all/},88 );89});9091test('Generators "final" return value is validated, sync', t => {92 t.throws(() => {93 execaSync('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null)(true), true)});94 }, {message: /not be called at all/});

Split files (#837)ehmickybefore adoption672c2d7

line 95why, one step back
95});