<types namespace="_contextTesting">
  <import name="ForkOptions" from="child_process" />
  <import from="stream" name="Writable" />

  <type record name="ForkConfig" desc="Parameters for forking.">
    <prop string name="module">
      The path to the module to fork.
    </prop>
    <fn opt name="getArgs" return="!(Array<string>|Promise<!Array<string>>)">
      <arg name="this" type="Object">The context of a mask.</arg>
      <arg name="forkArgs" type="!Array<string>">Arguments parsed as array.</arg>
      <arg name="...contexts" type="_contextTesting.Context">Zoroaster contexts.</arg>
      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.
    </fn>
    <fn opt name="getOptions" return="!child_process.ForkOptions">
      <arg name="this" type="Object">The context of a mask.</arg>
      <arg name="...contexts" type="_contextTesting.Context">Zoroaster contexts.</arg>
      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.
    </fn>
    <prop opt name="options" type="!child_process.ForkOptions">
      Options for the forked processed, such as `ENV` and `cwd`.
    </prop>
    <prop opt name="inputs" type="Array<[RegExp, string]>" closure="!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']]`.
    </prop>
    <prop opt name="stderrInputs" type="Array<[RegExp, string]>" closure="!Array<!Array<(!RegExp|string)>>">
      Inputs to push to `stdin` when `stderr` writes data (similar to `inputs`), e.g., `[[/question/, 'answer'], [/question2/, 'answer2']]`.
    </prop>
    <prop name="log" default="false" type="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.
    </prop>
    <prop boolean name="includeAnswers" default="true">
      Whether to add the answers to the `stderr` and `stdout` output.
    </prop>
    <prop boolean name="stripAnsi" default="true">
      Remove ANSI escape sequences from the `stdout` and `stderr` prior to checking of the result.
    </prop>
    <prop boolean name="normaliseOutputs" default="false">
      On Windows, updates all `\n` to `\r\n`, as `console.log` only prints `\n`.
    </prop>
    <prop type="(_contextTesting.Preprocessor|_contextTesting.ForkPreprocessor)" opt name="preprocess">
      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.
    </prop>
  </type>
  <type type="function(string): string" name="Preprocessor" desc="The function which processes fork's outputs before returning them for asserts.">
  </type>
  <record name="ForkPreprocessor" desc="An object with `stdout` and `stderr` preprocessors.">
    <fn opt name="stdout" return="string">
      <arg string name="stdout">The stdout of the fork.</arg>
      How to process `stdout` before asserts.
    </fn>
    <fn opt name="stderr" return="string">
      <arg string name="stdout">The stderr of the fork.</arg>
      How to process `stderr` before asserts, for example, you can strip `\r` symbols with `clearr` package.
    </fn>
  </record>
</types>