
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
@zoroaster/fork
Advanced tools
@zoroaster/fork is used in Zoroaster to test forks.
yarn add -E @zoroaster/fork
async fork(forkConfig: string|ForkConfig, input: string, props?: *, contexts?: Context[]): { stdout, stderr, code }
The package is available by importing its default function:
import fork from '@zoroaster/fork'
async fork(forkConfig: string|ForkConfig,input: string,props?: *,contexts?: Context[],): { stdout, stderr, code }This method will fork a process, and pass the inputs when stdin expects an input. Because includeAnswers is set to true by default, the answers will be included in the resulting stdout and stderr properties.
import('child_process').ForkOptions child_process.ForkOptions
ForkConfig: Parameters for forking.
| Name | Type | Description | Default |
|---|---|---|---|
| module* | string | The path to the module to fork. | - |
| getArgs | (args: string[], ...contexts?: Context[]) => string[]|Promise<string[]> | The function to get arguments to pass the fork based on the parsed mask input and contexts. | - |
| getOptions | (...contexts?: Context[]) => ForkOptions | The function to get options for the fork, such as ENV and cwd, based on contexts. | - |
| options | ForkOptions | Options for the forked processed, such as ENV and cwd. | - |
| inputs | [RegExp, string][] | Inputs to push to stdin when stdout writes data. The inputs are kept on stack, and taken off the stack when the RegExp matches the written data. | - |
| stderrInputs | [RegExp, string][] | Inputs to push to stdin when stderr writes data (similar to inputs). | - |
| log | boolean | {stderr: Writable, stdout: Writable} | Whether to pipe data from stdout, stderr to the process's streams. If an object is passed, the output will be piped to streams specified as its stdout and stderr properties. | false |
| includeAnswers | boolean | Whether to add the answers to the stderr and stdout output. | true |
| stripAnsi | boolean | Remove ANSI escape sequences from the stdout and stderr prior to checking of the result. | true |
| preprocess | (function | {stdout?:function, stderr?:function}) | The function to run on stdout and stderr before comparing it to the output. Pass an object with stdout and stderr properties for individual pre-processors. | - |
For example, to test the fork with the next code:
const [,, ...args] = process.argv
console.log(args)
console.error(process.env.EXAMPLE)
process.exit(5)
The ContextTesting/Fork can be used:
/* yarn example/ */
import fork from '@zoroaster/fork'
(async () => {
const res = await fork({
contexts: ['CONTEXT'],
forkConfig: {
module: 'example/fork',
getArgs(inputs) {
return [...inputs, this.prop1]
},
getOptions(CONTEXT) {
return {
env: {
EXAMPLE: `${CONTEXT} - ${this.input}`,
},
}
},
preprocess(s) {
/* e.g., to remove whitespace at the end of each line
s.split('\n').map(a => a.trimRight()).join('\n')
*/
return `pre-${s}`
},
/* stripAnsi: true */
},
input: 'hello world',
props: {
prop1: '999',
stdout: `pre-[ 'hello', 'world', '999' ]`,
stderr: 'pre-CONTEXT - hello world',
},
})
console.log(res)
})()
{ code: 5,
stdout: '[ \'hello\', \'world\', \'999\' ]\n',
stderr: 'CONTEXT - hello world\n' }
(c) Context Testing 2019
FAQs
Test forks.
The npm package @zoroaster/fork receives a total of 9 weekly downloads. As such, @zoroaster/fork popularity was classified as not popular.
We found that @zoroaster/fork demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.