npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zoroaster/fork

v1.5.0

Published

Test forks.

Readme

@zoroaster/fork

npm version Build status

@zoroaster/fork is used in Zoroaster to test forks. It is part of the @zoroaster/mask package which uses it to compare forks' output against the results written in non-js files. Nevertheless, the package can be used on its own to spawn and test forks — the library allows to fork a process and then asserts on the stderr, stdout and code properties, if they are passed, and returns the actual values if the assertions passed.

yarn add @zoroaster/fork

Table Of Contents

API

The package is available by importing its default function:

import fork from '@zoroaster/fork'

async fork(  options: !RunFork,): !ForkResult

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. Returns the result of the work, updated to contain answers in the interactive mode.

  • options* !RunFork: Options for the run method.

RunFork: Options for the run method.

| Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | | forkConfig* | (string | !ForkConfig) | Either the config, or the path to the module to fork. | | input* | string | The input to the test from the mask's result. It will be converted into an array of strings to become arguments to pass to the fork. | | props | * | The properties to pass to the getArgs and getOptions as their this context. These properties will be got from the mask's result. | | contexts | !Array<Context> | The contexts for the test to be passed to getArgs and getOptions. |

ForkResult: The output of the fork method.

| Name | Type | Description | | ----------- | --------------- | --------------------------------------------------------------------------- | | stdout* | string | The output from the stdout stream, possibly with answers fed to stdin. | | stderr* | string | The output from the stderr stream, possibly with answers fed to stdin. | | code* | number | The code with which the process exited. |

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)

@ContextTesting/Fork package can be used:

/* yarn example/ */
import fork from '@zoroaster/fork'

(async () => {
  /** @suppress {checkTypes} */
  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'
}

Types

The following types are used in this software.

ForkConfig: Parameters for forking.

| Name | Type | Description | Default | | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | module* | string | The path to the module to fork. | - | | options | !child_process.ForkOptions | Options for the forked processed, such as ENV and cwd. | - | | inputs | !Array<!Array<(!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, e.g., [[/question/, 'answer'], [/question2/, 'answer2']]. | - | | stderrInputs | !Array<!Array<(!RegExp | string)>> | Inputs to push to stdin when stderr writes data (similar to inputs), e.g., [[/question/, 'answer'], [/question2/, 'answer2']]. | - | | log | (boolean | { stderr: !(stream.Writable | NodeJS.WriteStream), stdout: !(stream.Writable | NodeJS.WriteStream) }) | 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 | | normaliseOutputs | boolean | On Windows, updates all \n to \r\n, as console.log only prints \n. | false | | preprocess | (Preprocessor | ForkPreprocessor) | 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. | - | | getArgs | (this: Object, forkArgs: !Array<string>, ...contexts: Context[]) => !(Array<string> | Promise<!Array<string>>) | The function to extend arguments to pass the fork based on the parsed mask input and contexts. The this context is set to the passed properties. | - | | getOptions | (this: Object, ...contexts: Context[]) => !child_process.ForkOptions | The function to get options for the fork, such as ENV and cwd, based on contexts. The this context is set to the passed properties. | - |

function(string): string Preprocessor: The function which processes fork's outputs before returning them for asserts.

ForkPreprocessor: An object with stdout and stderr preprocessors.

| Name | Type | Description | | ------ | ----------------------------------- | ------------------------------------------------------------------------------------------------------ | | stdout | (stdout: string) => string | How to process stdout before asserts. | | stderr | (stdout: string) => string | How to process stderr before asserts, for example, you can strip \r symbols with clearr package. |

Context: A context made with a constructor.

| Name | Type | Description | | -------- | --------------------------------- | --------------------------------------- | | _init | () => (!Promise | void) | The function to initialise the context. | | _destroy | () => (!Promise | void) | The function to destroy the context. |

Copyright & License

GNU Affero General Public License v3.0