-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor test helpers for the
verbose
option (#1128)
- Loading branch information
Showing
41 changed files
with
720 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import {execa} from '../../index.js'; | ||
import {execa, getOneMessage} from '../../index.js'; | ||
|
||
const [options, file, ...commandArguments] = process.argv.slice(2); | ||
const {file, commandArguments, options} = await getOneMessage(); | ||
const firstArguments = commandArguments.slice(0, -1); | ||
const lastArgument = commandArguments.at(-1); | ||
await Promise.all([ | ||
execa(file, [...firstArguments, lastArgument], JSON.parse(options)), | ||
execa(file, [...firstArguments, lastArgument.toUpperCase()], JSON.parse(options)), | ||
execa(file, [...firstArguments, lastArgument], options), | ||
execa(file, [...firstArguments, lastArgument.toUpperCase()], options), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import {execa} from '../../index.js'; | ||
import {execa, getOneMessage} from '../../index.js'; | ||
|
||
const [options, file, ...commandArguments] = process.argv.slice(2); | ||
const subprocess = execa(file, commandArguments, JSON.parse(options)); | ||
const {file, commandArguments, options} = await getOneMessage(); | ||
const subprocess = execa(file, commandArguments, options); | ||
subprocess.kill(new Error(commandArguments[0])); | ||
await subprocess; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import {execa} from '../../index.js'; | ||
import {execa, getOneMessage} from '../../index.js'; | ||
|
||
const [ | ||
sourceOptions, | ||
sourceFile, | ||
sourceArgument, | ||
destinationOptions, | ||
destinationFile, | ||
destinationArgument, | ||
] = process.argv.slice(2); | ||
await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions)) | ||
.pipe(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions)); | ||
const { | ||
file, | ||
commandArguments = [], | ||
options: { | ||
sourceOptions = {}, | ||
destinationFile, | ||
destinationArguments = [], | ||
destinationOptions = {}, | ||
}, | ||
} = await getOneMessage(); | ||
await execa(file, commandArguments, sourceOptions) | ||
.pipe(destinationFile, destinationArguments, destinationOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import {$} from '../../index.js'; | ||
import {$, getOneMessage} from '../../index.js'; | ||
|
||
const [ | ||
sourceOptions, | ||
sourceFile, | ||
sourceArgument, | ||
destinationOptions, | ||
destinationFile, | ||
destinationArgument, | ||
] = process.argv.slice(2); | ||
await $(JSON.parse(sourceOptions))`${sourceFile} ${sourceArgument}` | ||
.pipe(JSON.parse(destinationOptions))`${destinationFile} ${destinationArgument === undefined ? [] : [destinationArgument]}`; | ||
const { | ||
file, | ||
commandArguments = [], | ||
options: { | ||
sourceOptions = {}, | ||
destinationFile, | ||
destinationArguments = [], | ||
destinationOptions = {}, | ||
}, | ||
} = await getOneMessage(); | ||
await $(sourceOptions)`${file} ${commandArguments}` | ||
.pipe(destinationOptions)`${destinationFile} ${destinationArguments}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import {execa} from '../../index.js'; | ||
import {execa, getOneMessage} from '../../index.js'; | ||
|
||
const [options, file, commandArgument, unpipe] = process.argv.slice(2); | ||
const source = execa(file, [commandArgument], JSON.parse(options)); | ||
const {file, commandArguments, options: {unpipe, ...options}} = await getOneMessage(); | ||
const source = execa(file, commandArguments, options); | ||
const destination = execa('stdin.js'); | ||
const controller = new AbortController(); | ||
const pipePromise = source.pipe(destination, {unpipeSignal: controller.signal}); | ||
if (unpipe === 'true') { | ||
const subprocess = source.pipe(destination, {unpipeSignal: controller.signal}); | ||
if (unpipe) { | ||
controller.abort(); | ||
destination.stdin.end(); | ||
} | ||
|
||
await Promise.allSettled([source, destination, pipePromise]); | ||
try { | ||
await subprocess; | ||
} catch {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import {execa} from '../../index.js'; | ||
import {execa, getOneMessage} from '../../index.js'; | ||
|
||
const [ | ||
sourceOptions, | ||
sourceFile, | ||
sourceArgument, | ||
destinationOptions, | ||
destinationFile, | ||
destinationArgument, | ||
] = process.argv.slice(2); | ||
await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions)) | ||
.pipe(execa(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions))); | ||
const { | ||
file, | ||
commandArguments = [], | ||
options: { | ||
sourceOptions = {}, | ||
destinationFile, | ||
destinationArguments = [], | ||
destinationOptions = {}, | ||
}, | ||
} = await getOneMessage(); | ||
await execa(file, commandArguments, sourceOptions) | ||
.pipe(execa(destinationFile, destinationArguments, destinationOptions)); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import {execa, sendMessage} from '../../index.js'; | ||
import { | ||
execa, | ||
execaSync, | ||
getOneMessage, | ||
sendMessage, | ||
} from '../../index.js'; | ||
|
||
const { | ||
isSync, | ||
file, | ||
commandArguments, | ||
options, | ||
optionsFixture, | ||
optionsInput, | ||
} = await getOneMessage(); | ||
|
||
let commandOptions = options; | ||
|
||
// Some subprocess options cannot be serialized between processes. | ||
// For those, we pass a fixture filename instead, which dynamically creates the options. | ||
if (optionsFixture !== undefined) { | ||
const {getOptions} = await import(`./nested/${optionsFixture}`); | ||
commandOptions = {...commandOptions, ...getOptions({...commandOptions, ...optionsInput})}; | ||
} | ||
|
||
const [options, file, ...commandArguments] = process.argv.slice(2); | ||
try { | ||
const result = await execa(file, commandArguments, JSON.parse(options)); | ||
await sendMessage({result}); | ||
const result = isSync | ||
? execaSync(file, commandArguments, commandOptions) | ||
: await execa(file, commandArguments, commandOptions); | ||
await sendMessage(result); | ||
} catch (error) { | ||
await sendMessage({error}); | ||
await sendMessage(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {pathToFileURL} from 'node:url'; | ||
|
||
export const getOptions = ({stdout: {file}}) => ({stdout: pathToFileURL(file)}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {getOutputGenerator} from '../../helpers/generator.js'; | ||
|
||
const bigArray = Array.from({length: 100}, (_, index) => index); | ||
export const getOptions = () => ({stdout: getOutputGenerator(bigArray)(true)}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {uppercaseBufferDuplex} from '../../helpers/duplex.js'; | ||
|
||
export const getOptions = () => ({stdout: uppercaseBufferDuplex()}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {outputObjectGenerator} from '../../helpers/generator.js'; | ||
|
||
export const getOptions = () => ({stdout: outputObjectGenerator()}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {getOutputGenerator} from '../../helpers/generator.js'; | ||
import {simpleFull} from '../../helpers/lines.js'; | ||
|
||
export const getOptions = () => ({stdout: getOutputGenerator(simpleFull)(true)}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {uppercaseGenerator} from '../../helpers/generator.js'; | ||
|
||
export const getOptions = () => ({stdout: uppercaseGenerator()}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const getOptions = () => ({stdout: new WritableStream()}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import process from 'node:process'; | ||
|
||
export const getOptions = () => ({stdout: process.stdout}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
#!/usr/bin/env node | ||
import {workerData, parentPort} from 'node:worker_threads'; | ||
import {execa} from '../../index.js'; | ||
import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; | ||
import {spawnParentProcess} from '../helpers/nested.js'; | ||
|
||
setFixtureDirectory(); | ||
|
||
const {nodeFile, commandArguments, options} = workerData; | ||
try { | ||
const subprocess = execa(nodeFile, commandArguments, options); | ||
const [parentResult, {result, error}] = await Promise.all([subprocess, subprocess.getOneMessage()]); | ||
parentPort.postMessage({parentResult, result, error}); | ||
} catch (parentError) { | ||
parentPort.postMessage({parentError}); | ||
const result = await spawnParentProcess(workerData); | ||
parentPort.postMessage(result); | ||
} catch (error) { | ||
parentPort.postMessage(error); | ||
} |
Oops, something went wrong.