Constructors

  • Create a new CLI test instance. If you want to measure the code coverage of a JS/TS CLI, you may want to prepend the node command with 'c8' or 'nyc'.

    Parameters

    • command: string

      The command that should be executed to start the CLI process.

    • args: string[] = []

      The arguments that should be passed.

    • options: CLITestOptions = ...

      Additional options.

    Returns CLITest

Properties

args: string[]
childProcess: undefined | ChildProcessWithoutNullStreams
command: string
eventEmitter: EventEmitter<DefaultEventMap>
output: string = ''
running: boolean = false
starting: boolean = false

Methods

  • Get the exit code of the process. Returns null if the process has not exited yet. Throws an error if the process has not been run yet.

    Returns null | number

    The exit code of the process or null.

  • Get the next output chunk of the process (stdout and stderr). This must not be a complete line, it can be a partial line, multiple lines or only one carriage return.

    Returns Promise<string>

    The next chunk of the process as a string.

  • Get the output of the process (stdout and stderr).

    Returns string

    The output of the process as a string.

  • Check if the process is running.

    Returns boolean

    True if the process is running, false otherwise.

  • Kill the process.

    Returns boolean

    True if the process was killed successfully, false otherwise.

  • Register a callback to listen for output (stdout and stderr) from the process.

    Parameters

    • callback: ((data) => void)

      A callback that will be called when the process writes to stdout or stderr with the output as a string.

        • (data): void
        • Parameters

          • data: string

          Returns void

    Returns void

  • Execute the CLI process. Tip: You can call this method multiple times to restart the process, after the process has exited.

    Returns Promise<void>

    A promise that resolves when the process has been started.

    Throws

    If the process is already running or starting or if the command produces an error.

  • Update the options of the CLI test instance. The current options will be merged with the new options.

    Parameters

    Returns void

  • Wait for the process to exit. If the process returns a non-zero exit code, the promise will not be rejected.

    Returns Promise<null | number>

    A promise that resolves when the process exits with the exit code.

    Throws

    If the process is not running or starting.

  • Wait for the process to write the given content to stdout or stderr. If the process exits before the content is found, the promise will be rejected. This method does not check past output, only output that is written after this method is called. For checking past output, use getOutput(). Per default this method is only able to find content that is written in a single chunk by the CLI process. If the content is split into multiple chunks set multipleChunks to true.

    Parameters

    • content: string

      The string to wait for.

    • multipleChunks: boolean = false

      If true, the content can be split into multiple chunks. If false, the content must be written in a single chunk. Defaults to false.

    Returns Promise<void>

    A promise that resolves when the content is found, or rejects if the process exits before the content is found.

  • Write data to stdin of the process.

    Parameters

    • data: string | Buffer

      The data to write.

    Returns Promise<void>

    A promise that resolves when the data has been written.

Generated using TypeDoc