bind.js
This file
Path
test/methods/bind.js
109 lines · 5.2 KiB · JavaScript
Last changed by
Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
History of this fileTake it
Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 1why, one step back1import path from 'node:path';Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
lines 2–14why, one step back2import test from 'ava';3import {4 execa,5 execaSync,6 execaNode,7 $,8} from '../../index.js';9import {foobarString, foobarUppercase} from '../helpers/input.js';10import {uppercaseGenerator} from '../helpers/generator.js';11import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';1213setFixtureDirectory();14Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
lines 15–16why, one step back15const NOOP_PATH = path.join(FIXTURES_DIRECTORY, 'noop.js');16const PRINT_ENV_PATH = path.join(FIXTURES_DIRECTORY, 'environment.js');Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
lines 17–109why, one step back1718const testBindOptions = async (t, execaMethod) => {19 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);20 t.is(stdout, `${foobarString}\n`);21};2223test('execa() can bind options', testBindOptions, execa);24test('execaNode() can bind options', testBindOptions, execaNode);25test('$ can bind options', testBindOptions, $);2627const testBindOptionsSync = (t, execaMethod) => {28 const {stdout} = execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);29 t.is(stdout, `${foobarString}\n`);30};3132test('execaSync() can bind options', testBindOptionsSync, execaSync);33test('$.sync can bind options', testBindOptionsSync, $.sync);3435const testBindPriority = async (t, execaMethod) => {36 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: true});37 t.is(stdout, foobarString);38};3940test('execa() bound options have lower priority', testBindPriority, execa);41test('execaSync() bound options have lower priority', testBindPriority, execaSync);42test('execaNode() bound options have lower priority', testBindPriority, execaNode);43test('$ bound options have lower priority', testBindPriority, $);44test('$.sync bound options have lower priority', testBindPriority, $.sync);4546const testBindUndefined = async (t, execaMethod) => {47 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: undefined});48 t.is(stdout, foobarString);49};5051test('execa() undefined options use default value', testBindUndefined, execa);52test('execaSync() undefined options use default value', testBindUndefined, execaSync);53test('execaNode() undefined options use default value', testBindUndefined, execaNode);54test('$ undefined options use default value', testBindUndefined, $);55test('$.sync undefined options use default value', testBindUndefined, $.sync);5657const testMergeEnv = async (t, execaMethod) => {58 const {stdout} = await execaMethod({env: {FOO: 'foo'}})(PRINT_ENV_PATH, {env: {BAR: 'bar'}});59 t.is(stdout, 'foo\nbar');60};6162test('execa() bound options are merged', testMergeEnv, execa);63test('execaSync() bound options are merged', testMergeEnv, execaSync);64test('execaNode() bound options are merged', testMergeEnv, execaNode);65test('$ bound options are merged', testMergeEnv, $);66test('$.sync bound options are merged', testMergeEnv, $.sync);6768const testMergeMultiple = async (t, execaMethod) => {69 const {stdout} = await execaMethod({env: {FOO: 'baz'}})({env: {BAR: 'bar'}})(PRINT_ENV_PATH, {env: {FOO: 'foo'}});70 t.is(stdout, 'foo\nbar');71};7273test('execa() bound options are merged multiple times', testMergeMultiple, execa);74test('execaSync() bound options are merged multiple times', testMergeMultiple, execaSync);75test('execaNode() bound options are merged multiple times', testMergeMultiple, execaNode);76test('$ bound options are merged multiple times', testMergeMultiple, $);77test('$.sync bound options are merged multiple times', testMergeMultiple, $.sync);7879const testMergeFdSpecific = async (t, execaMethod) => {80 const {isMaxBuffer, shortMessage} = await t.throwsAsync(execaMethod({maxBuffer: {stdout: 1}})(NOOP_PATH, [foobarString], {maxBuffer: {stderr: 100}}));81 t.true(isMaxBuffer);82 t.true(shortMessage.includes('Command\'s stdout was larger than 1'));83};8485test('execa() bound options merge fd-specific ones', testMergeFdSpecific, execa);86test('execaNode() bound options merge fd-specific ones', testMergeFdSpecific, execaNode);87test('$ bound options merge fd-specific ones', testMergeFdSpecific, $);8889const testMergeEnvUndefined = async (t, execaMethod) => {90 const {stdout} = await execaMethod({env: {FOO: 'foo'}})(PRINT_ENV_PATH, {env: {BAR: undefined}});91 t.is(stdout, 'foo\nundefined');92};9394test('execa() bound options are merged even if undefined', testMergeEnvUndefined, execa);95test('execaSync() bound options are merged even if undefined', testMergeEnvUndefined, execaSync);96test('execaNode() bound options are merged even if undefined', testMergeEnvUndefined, execaNode);97test('$ bound options are merged even if undefined', testMergeEnvUndefined, $);98test('$.sync bound options are merged even if undefined', testMergeEnvUndefined, $.sync);99100const testMergeSpecific = async (t, execaMethod) => {101 const {stdout} = await execaMethod({stdout: {transform: uppercaseGenerator().transform, objectMode: true}})(NOOP_PATH, {stdout: {transform: uppercaseGenerator().transform}});102 t.is(stdout, foobarUppercase);103};104105test('execa() bound options only merge specific ones', testMergeSpecific, execa);106test('execaSync() bound options only merge specific ones', testMergeSpecific, execaSync);107test('execaNode() bound options only merge specific ones', testMergeSpecific, execaNode);108test('$ bound options only merge specific ones', testMergeSpecific, $);109test('$.sync bound options only merge specific ones', testMergeSpecific, $.sync);