-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
52 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Validation that cannot be handled by `jest-validate` | ||
export const validateCustom = function({ opts }) { | ||
Object.entries(ENUM_OPTS).forEach(([attrName, allowed]) => { | ||
validateEnum({ attrName, allowed, opts }) | ||
}) | ||
} | ||
|
||
const ENUM_OPTS = { | ||
result: ['save', 'replace'], | ||
from: ['stdout', 'stderr', 'all'], | ||
} | ||
|
||
// Validate an enum option | ||
const validateEnum = function({ | ||
attrName, | ||
allowed, | ||
opts: { [attrName]: value }, | ||
}) { | ||
if (value === undefined || allowed.includes(value)) { | ||
return | ||
} | ||
|
||
throw new Error( | ||
`option '${attrName}' '${value}' must be one of: ${allowed.join(', ')}`, | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Examples for the core `child_process.spawn()` options | ||
export const CHILD_PROCESS_OPTS = { | ||
windowsHide: true, | ||
} | ||
|
||
// Examples for the `execa` options | ||
export const EXECA_OPTS = { | ||
|
||
} |
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,14 @@ | ||
// Translate `verbose` option into `stdout|stderr|echo` options | ||
export const addVerbose = function({ opts: { verbose, ...opts }, opts: { stdio } }) { | ||
if (!verbose) { | ||
// The default value for `echo` must be added here, not in `DEFAULT_OPTS` | ||
return { echo: false, ...opts } | ||
} | ||
|
||
// `execa` does not allow mixing `stdio` and `stdout|stderr` options | ||
if (stdio !== undefined) { | ||
return { echo: true, ...opts } | ||
} | ||
|
||
return { stdout: 'inherit', stderr: 'inherit', echo: true, ...opts } | ||
} |