Skip to content
Myr

validate.js

This file

Path

test/transform/validate.js

76 lines · 6.4 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 08eb743 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–3why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';3import {assertThrows, assertRejects} from '../helpers/assert.js';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 4–6why, one step back
4import {execa, execaSync} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {getStdio} from '../helpers/stdio.js';

Allow passing `Buffer` to the `input` option (#1029)ehmickybefore adoption40fdc75

line 7why, one step back
7import {foobarUint8Array, foobarObject} from '../helpers/input.js';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 8–11why, one step back
8import {serializeGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';
910setFixtureDirectory();11

Allow passing `Buffer` to the `input` option (#1029)ehmickybefore adoption40fdc75

lines 12–14why, one step back
12const getMessage = input => input === null || input === undefined
13 ? 'not be called at all'14 : 'a string or an Uint8Array';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 15–19why, one step back
15
16const lastInputGenerator = input => objectMode => [foobarUint8Array, getOutputGenerator(input)(objectMode)];17const inputGenerator = input => objectMode => [...lastInputGenerator(input)(objectMode), serializeGenerator(true)];1819// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 20why, one step back
20const testGeneratorReturn = async (fdNumber, generator, input, objectMode, isInput) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 21why, one step back
21 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';

TweaksSindre Sorhusbefore adoption698a1b8

lines 22–23why, one step back
22 const {message} = await assertRejects(execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input)(objectMode))));
23 assert.ok(message.includes(getMessage(input)));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 24–25why, one step back
24};
25

TweaksSindre Sorhusbefore adoption698a1b8

lines 26–40why, one step back
26test('Generators with result.stdin cannot return an object if not in objectMode', () => testGeneratorReturn(0, inputGenerator, foobarObject, false, true));
27test('Generators with result.stdio[*] as input cannot return an object if not in objectMode', () => testGeneratorReturn(3, inputGenerator, foobarObject, false, true));28test('The last generator with result.stdin cannot return an object even in objectMode', () => testGeneratorReturn(0, lastInputGenerator, foobarObject, true, true));29test('The last generator with result.stdio[*] as input cannot return an object even in objectMode', () => testGeneratorReturn(3, lastInputGenerator, foobarObject, true, true));30test('Generators with result.stdout cannot return an object if not in objectMode', () => testGeneratorReturn(1, getOutputGenerator, foobarObject, false, false));31test('Generators with result.stderr cannot return an object if not in objectMode', () => testGeneratorReturn(2, getOutputGenerator, foobarObject, false, false));32test('Generators with result.stdio[*] as output cannot return an object if not in objectMode', () => testGeneratorReturn(3, getOutputGenerator, foobarObject, false, false));33test('Generators with result.stdin cannot return null if not in objectMode', () => testGeneratorReturn(0, inputGenerator, null, false, true));34test('Generators with result.stdin cannot return null if in objectMode', () => testGeneratorReturn(0, inputGenerator, null, true, true));35test('Generators with result.stdout cannot return null if not in objectMode', () => testGeneratorReturn(1, getOutputGenerator, null, false, false));36test('Generators with result.stdout cannot return null if in objectMode', () => testGeneratorReturn(1, getOutputGenerator, null, true, false));37test('Generators with result.stdin cannot return undefined if not in objectMode', () => testGeneratorReturn(0, inputGenerator, undefined, false, true));38test('Generators with result.stdin cannot return undefined if in objectMode', () => testGeneratorReturn(0, inputGenerator, undefined, true, true));39test('Generators with result.stdout cannot return undefined if not in objectMode', () => testGeneratorReturn(1, getOutputGenerator, undefined, false, false));40test('Generators with result.stdout cannot return undefined if in objectMode', () => testGeneratorReturn(1, getOutputGenerator, undefined, true, false));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 41–42why, one step back
41
42// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43const testGeneratorReturnSync = (fdNumber, generator, input, objectMode, isInput) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 44why, one step back
44 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';

TweaksSindre Sorhusbefore adoption698a1b8

line 45why, one step back
45 const {message} = assertThrows(() => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 46–47why, one step back
46 execaSync(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input)(objectMode)));
47 });

TweaksSindre Sorhusbefore adoption698a1b8

line 48why, one step back
48 assert.ok(message.includes(getMessage(input)));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 49–50why, one step back
49};
50

TweaksSindre Sorhusbefore adoption698a1b8

lines 51–63why, one step back
51test('Generators with result.stdin cannot return an object if not in objectMode, sync', () => testGeneratorReturnSync(0, inputGenerator, foobarObject, false, true));
52test('The last generator with result.stdin cannot return an object even in objectMode, sync', () => testGeneratorReturnSync(0, lastInputGenerator, foobarObject, true, true));53test('Generators with result.stdout cannot return an object if not in objectMode, sync', () => testGeneratorReturnSync(1, getOutputGenerator, foobarObject, false, false));54test('Generators with result.stderr cannot return an object if not in objectMode, sync', () => testGeneratorReturnSync(2, getOutputGenerator, foobarObject, false, false));55test('Generators with result.stdio[*] as output cannot return an object if not in objectMode, sync', () => testGeneratorReturnSync(3, getOutputGenerator, foobarObject, false, false));56test('Generators with result.stdin cannot return null if not in objectMode, sync', () => testGeneratorReturnSync(0, inputGenerator, null, false, true));57test('Generators with result.stdin cannot return null if in objectMode, sync', () => testGeneratorReturnSync(0, inputGenerator, null, true, true));58test('Generators with result.stdout cannot return null if not in objectMode, sync', () => testGeneratorReturnSync(1, getOutputGenerator, null, false, false));59test('Generators with result.stdout cannot return null if in objectMode, sync', () => testGeneratorReturnSync(1, getOutputGenerator, null, true, false));60test('Generators with result.stdin cannot return undefined if not in objectMode, sync', () => testGeneratorReturnSync(0, inputGenerator, undefined, false, true));61test('Generators with result.stdin cannot return undefined if in objectMode, sync', () => testGeneratorReturnSync(0, inputGenerator, undefined, true, true));62test('Generators with result.stdout cannot return undefined if not in objectMode, sync', () => testGeneratorReturnSync(1, getOutputGenerator, undefined, false, false));63test('Generators with result.stdout cannot return undefined if in objectMode, sync', () => testGeneratorReturnSync(1, getOutputGenerator, undefined, true, false));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 64why, one step back
64

TweaksSindre Sorhusbefore adoption698a1b8

lines 65–66why, one step back
65test('Generators "final" return value is validated', async () => {
66 await assertRejects(

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 67–71why, one step back
67 execa('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null)(true), true)}),
68 {message: /not be called at all/},69 );70});71

TweaksSindre Sorhusbefore adoption698a1b8

lines 72–73why, one step back
72test('Generators "final" return value is validated, sync', () => {
73 assertThrows(() => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 74–76why, one step back
74 execaSync('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null)(true), true)});
75 }, {message: /not be called at all/});76});