file-path.js
This file
Path
test/stdio/file-path.js
394 lines · 23.2 KiB · JavaScript
Last changed by
Add support for `buffer: false` to `execaSync()` (#953)ehmickybefore adoptiond0052ac
History of this fileTake it
The walk stopped after 200 commits: lines older than 7122767 point at it.
Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 1–5why, one step back1import {readFile, writeFile, rm} from 'node:fs/promises';2import {relative, dirname, basename} from 'node:path';3import process from 'node:process';4import {pathToFileURL} from 'node:url';5import test from 'ava';Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
line 6why, one step back6import {pathExists} from 'path-exists';Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 7why, one step back7import tempfile from 'tempfile';Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 8why, one step back8import {execa, execaSync} from '../../index.js';Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 9why, one step back9import {setFixtureDir} from '../helpers/fixtures-dir.js';Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 10–11why, one step back10import {identity, getStdio} from '../helpers/stdio.js';11import {runExeca, runExecaSync, runScript, runScriptSync} from '../helpers/run.js';Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 12–13why, one step back12import {foobarString, foobarUint8Array, foobarUppercase} from '../helpers/input.js';13import {outputObjectGenerator, uppercaseGenerator, serializeGenerator, throwingGenerator} from '../helpers/generator.js';Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 14–18why, one step back1415setFixtureDir();1617const nonFileUrl = new URL('https://example.com');18Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
lines 19–20why, one step back19const getAbsolutePath = file => ({file});20const getRelativePath = filePath => ({file: relative('.', filePath)});Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 21why, one step back21Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 22–23why, one step back22const getStdioInput = (fdNumberOrName, file) => {23 if (fdNumberOrName === 'string') {Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 24why, one step back24 return {input: foobarString};Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 25–26why, one step back25 }26Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 27why, one step back27 if (fdNumberOrName === 'binary') {Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 28why, one step back28 return {input: foobarUint8Array};Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 29–30why, one step back29 }30Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 31why, one step back31 return getStdioInputFile(fdNumberOrName, file);Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 32–33why, one step back32};33Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
lines 34–35why, one step back34const getStdioInputFile = (fdNumberOrName, file) => getStdio(fdNumberOrName, typeof fdNumberOrName === 'string' ? file : {file});35Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 36why, one step back36const testStdinFile = async (t, mapFilePath, fdNumber, execaMethod) => {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 37why, one step back37 const filePath = tempfile();Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 38why, one step back38 await writeFile(filePath, foobarString);Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 39why, one step back39 const {stdout} = await execaMethod('stdin.js', getStdio(fdNumber, mapFilePath(filePath)));Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 40why, one step back40 t.is(stdout, foobarString);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 41–43why, one step back41 await rm(filePath);42};43Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 44–55why, one step back44test('inputFile can be a file URL', testStdinFile, pathToFileURL, 'inputFile', execa);45test('stdin can be a file URL', testStdinFile, pathToFileURL, 0, execa);46test('inputFile can be an absolute file path', testStdinFile, identity, 'inputFile', execa);47test('stdin can be an absolute file path', testStdinFile, getAbsolutePath, 0, execa);48test('inputFile can be a relative file path', testStdinFile, identity, 'inputFile', execa);49test('stdin can be a relative file path', testStdinFile, getRelativePath, 0, execa);50test('inputFile can be a file URL - sync', testStdinFile, pathToFileURL, 'inputFile', execaSync);51test('stdin can be a file URL - sync', testStdinFile, pathToFileURL, 0, execaSync);52test('inputFile can be an absolute file path - sync', testStdinFile, identity, 'inputFile', execaSync);53test('stdin can be an absolute file path - sync', testStdinFile, getAbsolutePath, 0, execaSync);54test('inputFile can be a relative file path - sync', testStdinFile, identity, 'inputFile', execaSync);55test('stdin can be a relative file path - sync', testStdinFile, getRelativePath, 0, execaSync);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 56why, one step back56Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 57why, one step back57const testOutputFile = async (t, mapFile, fdNumber, execaMethod) => {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 58why, one step back58 const filePath = tempfile();Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
lines 59–60why, one step back59 await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, mapFile(filePath)));60 t.is(await readFile(filePath, 'utf8'), foobarString);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 61–63why, one step back61 await rm(filePath);62};63Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 64–81why, one step back64test('stdout can be a file URL', testOutputFile, pathToFileURL, 1, execa);65test('stderr can be a file URL', testOutputFile, pathToFileURL, 2, execa);66test('stdio[*] can be a file URL', testOutputFile, pathToFileURL, 3, execa);67test('stdout can be an absolute file path', testOutputFile, getAbsolutePath, 1, execa);68test('stderr can be an absolute file path', testOutputFile, getAbsolutePath, 2, execa);69test('stdio[*] can be an absolute file path', testOutputFile, getAbsolutePath, 3, execa);70test('stdout can be a relative file path', testOutputFile, getRelativePath, 1, execa);71test('stderr can be a relative file path', testOutputFile, getRelativePath, 2, execa);72test('stdio[*] can be a relative file path', testOutputFile, getRelativePath, 3, execa);73test('stdout can be a file URL - sync', testOutputFile, pathToFileURL, 1, execaSync);74test('stderr can be a file URL - sync', testOutputFile, pathToFileURL, 2, execaSync);75test('stdio[*] can be a file URL - sync', testOutputFile, pathToFileURL, 3, execaSync);76test('stdout can be an absolute file path - sync', testOutputFile, getAbsolutePath, 1, execaSync);77test('stderr can be an absolute file path - sync', testOutputFile, getAbsolutePath, 2, execaSync);78test('stdio[*] can be an absolute file path - sync', testOutputFile, getAbsolutePath, 3, execaSync);79test('stdout can be a relative file path - sync', testOutputFile, getRelativePath, 1, execaSync);80test('stderr can be a relative file path - sync', testOutputFile, getRelativePath, 2, execaSync);81test('stdio[*] can be a relative file path - sync', testOutputFile, getRelativePath, 3, execaSync);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 82why, one step back82Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 83why, one step back83const testStdioNonFileUrl = (t, fdNumber, execaMethod) => {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 84why, one step back84 t.throws(() => {Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 85why, one step back85 execaMethod('empty.js', getStdio(fdNumber, nonFileUrl));Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 86–88why, one step back86 }, {message: /pathToFileURL/});87};88Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 89–98why, one step back89test('inputFile cannot be a non-file URL', testStdioNonFileUrl, 'inputFile', execa);90test('stdin cannot be a non-file URL', testStdioNonFileUrl, 0, execa);91test('stdout cannot be a non-file URL', testStdioNonFileUrl, 1, execa);92test('stderr cannot be a non-file URL', testStdioNonFileUrl, 2, execa);93test('stdio[*] cannot be a non-file URL', testStdioNonFileUrl, 3, execa);94test('inputFile cannot be a non-file URL - sync', testStdioNonFileUrl, 'inputFile', execaSync);95test('stdin cannot be a non-file URL - sync', testStdioNonFileUrl, 0, execaSync);96test('stdout cannot be a non-file URL - sync', testStdioNonFileUrl, 1, execaSync);97test('stderr cannot be a non-file URL - sync', testStdioNonFileUrl, 2, execaSync);98test('stdio[*] cannot be a non-file URL - sync', testStdioNonFileUrl, 3, execaSync);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 99why, one step back99Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
lines 100–101why, one step back100const testInvalidInputFile = (t, execaMethod) => {101 t.throws(() => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 102why, one step back102 execaMethod('empty.js', getStdio('inputFile', false));Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
lines 103–108why, one step back103 }, {message: /a file path string or a file URL/});104};105106test('inputFile must be a file URL or string', testInvalidInputFile, execa);107test('inputFile must be a file URL or string - sync', testInvalidInputFile, execaSync);108Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 109why, one step back109const testInputFileValidUrl = async (t, fdNumber, execaMethod) => {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 110why, one step back110 const filePath = tempfile();Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 111why, one step back111 await writeFile(filePath, foobarString);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 112–115why, one step back112 const currentCwd = process.cwd();113 process.chdir(dirname(filePath));114115 try {Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
lines 116–117why, one step back116 const {stdout} = await execaMethod('stdin.js', getStdioInputFile(fdNumber, basename(filePath)));117 t.is(stdout, foobarString);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 118–123why, one step back118 } finally {119 process.chdir(currentCwd);120 await rm(filePath);121 }122};123Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 124–127why, one step back124test.serial('inputFile does not need to start with . when being a relative file path', testInputFileValidUrl, 'inputFile', execa);125test.serial('stdin does not need to start with . when being a relative file path', testInputFileValidUrl, 0, execa);126test.serial('inputFile does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 'inputFile', execaSync);127test.serial('stdin does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 0, execaSync);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 128why, one step back128Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 129why, one step back129const testFilePathObject = (t, fdNumber, execaMethod) => {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 130why, one step back130 t.throws(() => {Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 131why, one step back131 execaMethod('empty.js', getStdio(fdNumber, foobarString));Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 132why, one step back132 }, {message: /must be used/});Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 133–134why, one step back133};134Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 135–142why, one step back135test('stdin must be an object when it is a file path string', testFilePathObject, 0, execa);136test('stdout must be an object when it is a file path string', testFilePathObject, 1, execa);137test('stderr must be an object when it is a file path string', testFilePathObject, 2, execa);138test('stdio[*] must be an object when it is a file path string', testFilePathObject, 3, execa);139test('stdin be an object when it is a file path string - sync', testFilePathObject, 0, execaSync);140test('stdout be an object when it is a file path string - sync', testFilePathObject, 1, execaSync);141test('stderr be an object when it is a file path string - sync', testFilePathObject, 2, execaSync);142test('stdio[*] must be an object when it is a file path string - sync', testFilePathObject, 3, execaSync);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 143why, one step back143Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 144why, one step back144const testFileError = async (t, fixtureName, mapFile, fdNumber) => {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 145why, one step back145 await t.throwsAsync(Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 146why, one step back146 execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, mapFile('./unknown/file'))),Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 147–150why, one step back147 {code: 'ENOENT'},148 );149};150Do not prevent process normal exit (#809)ehmickybefore adoption7ddf0a0
lines 151–160why, one step back151test.serial('inputFile file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 'inputFile');152test.serial('stdin file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 0);153test.serial('stdout file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 1);154test.serial('stderr file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 2);155test.serial('stdio[*] file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 3);156test.serial('inputFile file path errors should be handled', testFileError, 'stdin-fd.js', identity, 'inputFile');157test.serial('stdin file path errors should be handled', testFileError, 'stdin-fd.js', getAbsolutePath, 0);158test.serial('stdout file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 1);159test.serial('stderr file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 2);160test.serial('stdio[*] file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 3);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 161why, one step back161Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 162why, one step back162const testFileErrorSync = (t, mapFile, fdNumber) => {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 163why, one step back163 t.throws(() => {Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 164why, one step back164 execaSync('empty.js', getStdio(fdNumber, mapFile('./unknown/file')));Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
lines 165–167why, one step back165 }, {code: 'ENOENT'});166};167Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 168–177why, one step back168test('inputFile file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 'inputFile');169test('stdin file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 0);170test('stdout file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 1);171test('stderr file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 2);172test('stdio[*] file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 3);173test('inputFile file path errors should be handled - sync', testFileErrorSync, identity, 'inputFile');174test('stdin file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 0);175test('stdout file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 1);176test('stderr file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 2);177test('stdio[*] file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 3);Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 178why, one step back178Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 179why, one step back179const testMultipleInputs = async (t, indices, execaMethod) => {Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
line 180why, one step back180 const filePath = tempfile();Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 181why, one step back181 await writeFile(filePath, foobarString);Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 182why, one step back182 const options = Object.assign({}, ...indices.map(fdNumber => getStdioInput(fdNumber, filePath)));Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
line 183why, one step back183 const {stdout} = await execaMethod('stdin.js', options);Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 184why, one step back184 t.is(stdout, foobarString.repeat(indices.length));Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
lines 185–187why, one step back185 await rm(filePath);186};187Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 188–205why, one step back188test('inputFile can be set', testMultipleInputs, ['inputFile'], runExeca);189test('inputFile can be set - sync', testMultipleInputs, ['inputFile'], runExecaSync);190test('inputFile can be set with $', testMultipleInputs, ['inputFile'], runScript);191test('inputFile can be set with $.sync', testMultipleInputs, ['inputFile'], runScriptSync);192test('input String and inputFile can be both set', testMultipleInputs, ['inputFile', 'string'], execa);193test('input String and stdin can be both set', testMultipleInputs, [0, 'string'], execa);194test('input Uint8Array and inputFile can be both set', testMultipleInputs, ['inputFile', 'binary'], execa);195test('input Uint8Array and stdin can be both set', testMultipleInputs, [0, 'binary'], execa);196test('stdin and inputFile can be both set', testMultipleInputs, [0, 'inputFile'], execa);197test('input String, stdin and inputFile can be all set', testMultipleInputs, ['inputFile', 0, 'string'], execa);198test('input Uint8Array, stdin and inputFile can be all set', testMultipleInputs, ['inputFile', 0, 'binary'], execa);199test('input String and inputFile can be both set - sync', testMultipleInputs, ['inputFile', 'string'], execaSync);200test('input String and stdin can be both set - sync', testMultipleInputs, [0, 'string'], execaSync);201test('input Uint8Array and inputFile can be both set - sync', testMultipleInputs, ['inputFile', 'binary'], execaSync);202test('input Uint8Array and stdin can be both set - sync', testMultipleInputs, [0, 'binary'], execaSync);203test('stdin and inputFile can be both set - sync', testMultipleInputs, [0, 'inputFile'], execaSync);204test('input String, stdin and inputFile can be all set - sync', testMultipleInputs, ['inputFile', 0, 'string'], execaSync);205test('input Uint8Array, stdin and inputFile can be all set - sync', testMultipleInputs, ['inputFile', 0, 'binary'], execaSync);Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd
line 206why, one step back206Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
lines 207–228why, one step back207const testMultipleOutputs = async (t, mapFile, fdNumber, execaMethod) => {208 const filePath = tempfile();209 const filePathTwo = tempfile();210 await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [mapFile(filePath), mapFile(filePathTwo)]));211 t.is(await readFile(filePath, 'utf8'), foobarString);212 t.is(await readFile(filePathTwo, 'utf8'), foobarString);213 await Promise.all([rm(filePath), rm(filePathTwo)]);214};215216test('stdout can be two file URLs', testMultipleOutputs, pathToFileURL, 1, execa);217test('stdout can be two file paths', testMultipleOutputs, getAbsolutePath, 1, execa);218test('stdout can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 1, execaSync);219test('stdout can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 1, execaSync);220test('stderr can be two file URLs', testMultipleOutputs, pathToFileURL, 2, execa);221test('stderr can be two file paths', testMultipleOutputs, getAbsolutePath, 2, execa);222test('stderr can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 2, execaSync);223test('stderr can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 2, execaSync);224test('stdio[*] can be two file URLs', testMultipleOutputs, pathToFileURL, 3, execa);225test('stdio[*] can be two file paths', testMultipleOutputs, getAbsolutePath, 3, execa);226test('stdio[*] can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 3, execaSync);227test('stdio[*] can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 3, execaSync);228Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd
lines 229–230why, one step back229const testInputFileHanging = async (t, mapFilePath) => {230 const filePath = tempfile();Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 231why, one step back231 await writeFile(filePath, foobarString);Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd
lines 232–235why, one step back232 await t.throwsAsync(execa('stdin.js', {stdin: mapFilePath(filePath), timeout: 1}), {message: /timed out/});233 await rm(filePath);234};235Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 236–237why, one step back236test('Passing an input file path when subprocess exits does not make promise hang', testInputFileHanging, getAbsolutePath);237test('Passing an input file URL when subprocess exits does not make promise hang', testInputFileHanging, pathToFileURL);Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 238–300why, one step back238239const testInputFileTransform = async (t, fdNumber, mapFile, execaMethod) => {240 const filePath = tempfile();241 await writeFile(filePath, foobarString);242 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [243 new Uint8Array(),244 mapFile(filePath),245 uppercaseGenerator(),246 ]));247 t.is(stdout, foobarUppercase);248 await rm(filePath);249};250251test('stdin can use generators together with input file paths', testInputFileTransform, 0, getAbsolutePath, execa);252test('stdin can use generators together with input file URLs', testInputFileTransform, 0, pathToFileURL, execa);253test('stdio[*] can use generators together with input file paths', testInputFileTransform, 3, getAbsolutePath, execa);254test('stdio[*] can use generators together with input file URLs', testInputFileTransform, 3, pathToFileURL, execa);255test('stdin can use generators together with input file paths, sync', testInputFileTransform, 0, getAbsolutePath, execaSync);256test('stdin can use generators together with input file URLs, sync', testInputFileTransform, 0, pathToFileURL, execaSync);257258const testInputFileObject = async (t, fdNumber, mapFile, execaMethod) => {259 const filePath = tempfile();260 await writeFile(filePath, foobarString);261 t.throws(() => {262 execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [263 new Uint8Array(),264 mapFile(filePath),265 serializeGenerator(true),266 ]));267 }, {message: /cannot use both files and transforms in objectMode/});268 await rm(filePath);269};270271test('stdin cannot use objectMode together with input file paths', testInputFileObject, 0, getAbsolutePath, execa);272test('stdin cannot use objectMode together with input file URLs', testInputFileObject, 0, pathToFileURL, execa);273test('stdio[*] cannot use objectMode together with input file paths', testInputFileObject, 3, getAbsolutePath, execa);274test('stdio[*] cannot use objectMode together with input file URLs', testInputFileObject, 3, pathToFileURL, execa);275test('stdin cannot use objectMode together with input file paths, sync', testInputFileObject, 0, getAbsolutePath, execaSync);276test('stdin cannot use objectMode together with input file URLs, sync', testInputFileObject, 0, pathToFileURL, execaSync);277278const testOutputFileTransform = async (t, fdNumber, mapFile, execaMethod) => {279 const filePath = tempfile();280 await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [281 uppercaseGenerator(),282 mapFile(filePath),283 ]));284 t.is(await readFile(filePath, 'utf8'), `${foobarUppercase}\n`);285 await rm(filePath);286};287288test('stdout can use generators together with output file paths', testOutputFileTransform, 1, getAbsolutePath, execa);289test('stdout can use generators together with output file URLs', testOutputFileTransform, 1, pathToFileURL, execa);290test('stderr can use generators together with output file paths', testOutputFileTransform, 2, getAbsolutePath, execa);291test('stderr can use generators together with output file URLs', testOutputFileTransform, 2, pathToFileURL, execa);292test('stdio[*] can use generators together with output file paths', testOutputFileTransform, 3, getAbsolutePath, execa);293test('stdio[*] can use generators together with output file URLs', testOutputFileTransform, 3, pathToFileURL, execa);294test('stdout can use generators together with output file paths, sync', testOutputFileTransform, 1, getAbsolutePath, execaSync);295test('stdout can use generators together with output file URLs, sync', testOutputFileTransform, 1, pathToFileURL, execaSync);296test('stderr can use generators together with output file paths, sync', testOutputFileTransform, 2, getAbsolutePath, execaSync);297test('stderr can use generators together with output file URLs, sync', testOutputFileTransform, 2, pathToFileURL, execaSync);298test('stdio[*] can use generators together with output file paths, sync', testOutputFileTransform, 3, getAbsolutePath, execaSync);299test('stdio[*] can use generators together with output file URLs, sync', testOutputFileTransform, 3, pathToFileURL, execaSync);300Add support for `lines` option with `execaSync()` (#951)ehmickybefore adoption88bff1f
lines 301–324why, one step back301const testOutputFileLines = async (t, fdNumber, mapFile, execaMethod) => {302 const filePath = tempfile();303 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {304 ...getStdio(fdNumber, mapFile(filePath)),305 lines: true,306 });307 t.deepEqual(stdio[fdNumber], [foobarString]);308 t.is(await readFile(filePath, 'utf8'), foobarString);309 await rm(filePath);310};311312test('stdout can use "lines: true" together with output file paths', testOutputFileLines, 1, getAbsolutePath, execa);313test('stdout can use "lines: true" together with output file URLs', testOutputFileLines, 1, pathToFileURL, execa);314test('stderr can use "lines: true" together with output file paths', testOutputFileLines, 2, getAbsolutePath, execa);315test('stderr can use "lines: true" together with output file URLs', testOutputFileLines, 2, pathToFileURL, execa);316test('stdio[*] can use "lines: true" together with output file paths', testOutputFileLines, 3, getAbsolutePath, execa);317test('stdio[*] can use "lines: true" together with output file URLs', testOutputFileLines, 3, pathToFileURL, execa);318test('stdout can use "lines: true" together with output file paths, sync', testOutputFileLines, 1, getAbsolutePath, execaSync);319test('stdout can use "lines: true" together with output file URLs, sync', testOutputFileLines, 1, pathToFileURL, execaSync);320test('stderr can use "lines: true" together with output file paths, sync', testOutputFileLines, 2, getAbsolutePath, execaSync);321test('stderr can use "lines: true" together with output file URLs, sync', testOutputFileLines, 2, pathToFileURL, execaSync);322test('stdio[*] can use "lines: true" together with output file paths, sync', testOutputFileLines, 3, getAbsolutePath, execaSync);323test('stdio[*] can use "lines: true" together with output file URLs, sync', testOutputFileLines, 3, pathToFileURL, execaSync);324Add support for `buffer: false` to `execaSync()` (#953)ehmickybefore adoptiond0052ac
lines 325–338why, one step back325const testOutputFileNoBuffer = async (t, execaMethod) => {326 const filePath = tempfile();327 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {328 stdout: getAbsolutePath(filePath),329 buffer: false,330 });331 t.is(stdout, undefined);332 t.is(await readFile(filePath, 'utf8'), foobarString);333 await rm(filePath);334};335336test('stdout can use "buffer: false" together with output file paths', testOutputFileNoBuffer, execa);337test('stdout can use "buffer: false" together with output file paths, sync', testOutputFileNoBuffer, execaSync);338Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 339–394why, one step back339const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {340 const filePath = tempfile();341 t.throws(() => {342 execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [343 outputObjectGenerator(),344 mapFile(filePath),345 ]));346 }, {message: /cannot use both files and transforms in objectMode/});347 t.false(await pathExists(filePath));348};349350test('stdout cannot use objectMode together with output file paths', testOutputFileObject, 1, getAbsolutePath, execa);351test('stdout cannot use objectMode together with output file URLs', testOutputFileObject, 1, pathToFileURL, execa);352test('stderr cannot use objectMode together with output file paths', testOutputFileObject, 2, getAbsolutePath, execa);353test('stderr cannot use objectMode together with output file URLs', testOutputFileObject, 2, pathToFileURL, execa);354test('stdio[*] cannot use objectMode together with output file paths', testOutputFileObject, 3, getAbsolutePath, execa);355test('stdio[*] cannot use objectMode together with output file URLs', testOutputFileObject, 3, pathToFileURL, execa);356test('stdout cannot use objectMode together with output file paths, sync', testOutputFileObject, 1, getAbsolutePath, execaSync);357test('stdout cannot use objectMode together with output file URLs, sync', testOutputFileObject, 1, pathToFileURL, execaSync);358test('stderr cannot use objectMode together with output file paths, sync', testOutputFileObject, 2, getAbsolutePath, execaSync);359test('stderr cannot use objectMode together with output file URLs, sync', testOutputFileObject, 2, pathToFileURL, execaSync);360test('stdio[*] cannot use objectMode together with output file paths, sync', testOutputFileObject, 3, getAbsolutePath, execaSync);361test('stdio[*] cannot use objectMode together with output file URLs, sync', testOutputFileObject, 3, pathToFileURL, execaSync);362363test('Generator error stops writing to output file', async t => {364 const filePath = tempfile();365 const cause = new Error(foobarString);366 const error = await t.throwsAsync(execa('noop.js', {367 stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],368 }));369 t.is(error.cause, cause);370 t.is(await readFile(filePath, 'utf8'), '');371});372373test('Generator error does not create output file, sync', async t => {374 const filePath = tempfile();375 const cause = new Error(foobarString);376 const error = t.throws(() => {377 execaSync('noop.js', {378 stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],379 });380 });381 t.is(error.cause, cause);382 t.false(await pathExists(filePath));383});384385test('Output file error still returns transformed output, sync', async t => {386 const filePath = tempfile();387 const {stdout} = t.throws(() => {388 execaSync('noop-fd.js', ['1', foobarString], {389 stdout: [uppercaseGenerator(), getAbsolutePath('./unknown/file')],390 });391 }, {code: 'ENOENT'});392 t.false(await pathExists(filePath));393 t.is(stdout, foobarUppercase);394});