Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@infragen/util-send-inputs-to-cli

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@infragen/util-send-inputs-to-cli

This is a generic utility that should be able to send inputs to any CLI/process executed by `child_process.exec`. It's meant to be used in the context of Jest as it exports mock functions that fire when there's data on `stdout` or `stderr`. It is also mea

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@infragen/util-send-inputs-to-cli

This is a generic utility that should be able to send inputs to any CLI/process executed by child_process.exec. It's meant to be used in the context of Jest as it exports mock functions that fire when there's data on stdout or stderr. It is also mean to be used in conjunction with @infragen/utils-test-cli

Supported Features:

  • Send inputs to a CLI
  • Set different timeout for inputs
  • Set a default timeoutBetweenInputs

To see examples of each please see tests under __tests__

Usage

Basic usage

const { output, error, code } = await testSendInputToCLI({
  bashCommand: "ts-node ./mockCLIs/standard.ts",
  inputs: [
    // Check "Option 1"
    SPACE,

    // Move to "Option 2"
    DOWN,

    // Move to "Option 3"
    DOWN,

    // Check "Option 3"
    SPACE,

    // Next Question
    ENTER,

    // Type answer to "What's your name"
    "Anatoliy Zaslavskiy",

    // Submit answer to question
    ENTER
  ]
});

expect(error.mock.calls.length).toBe(0);

expect(code).toBe(0);

expect(output).toBeCalledWith(
  expect.stringMatching(/Which option do you want to choose\?/)
);

expect(output).toBeCalledWith(expect.stringMatching(/◯ Option 1/));

expect(output).toBeCalledWith(expect.stringMatching(/◯ Option 3/));

expect(output).toBeCalledWith(expect.stringMatching(/Option 1 Chosen/));

expect(output).not.toBeCalledWith(expect.stringMatching(/Option 2 Chosen/));

expect(output).toBeCalledWith(expect.stringMatching(/Option 3 Chosen/));

expect(output).toBeCalledWith(expect.stringMatching(/What's your full name\?/));

expect(output).toBeCalledWith(
  expect.stringMatching(/Your name is "Anatoliy Zaslavskiy"/)
);

FAQs

Package last updated on 20 Jan 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc