8000 GitHub - TheSTL/cli-prompts-test: Write e2e tests for CLI apps with ease
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TheSTL/cli-prompts-test

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLI Prompts Test

Write e2e tests for CLI apps with ease.

Installation

$ npm install --save-dev cli-prompts-test

API

runTest(args, answers, options?)

  • args: CLI args to pass in.
  • answers: answers to be passed to stdout (simulate user input).
  • options: Optionally specify the testPath (defaults to process.cwd()) and timeout (defaults to 500ms) between keystrokes.

Usage

// cli.js

const enquirer = require("enquirer");

const choices = ['First option', 'Second option', 'Third option'];

enquirer
  .prompt({
    type: "select",
    name: "option",
    message: "Choose from below",
    choices,
  })
  .then(({ option }) => {
    console.log(`You chose ${option}`);
  });
// test.js

const runTest, { DOWN, ENTER } = require("cli-prompts-test");

const cliPath = `${__dirname}/cli.js`;

describe("cli-prompts-test", () => {
  it("picks first option", async () => {
    const { stdout } = await runTest(
      [cliPath],
      [ENTER]
    );
    expect(stdout).toContain("You chose First option");
  });

  it("picks second option", async () => {
    const { stdout } = await runTest(
      [cliPath],
      [`${DOWN}${ENTER}`]
    );
    expect(stdout).toContain("You chose Second option");
  });

  it("picks third option", async () => {
    const { stdout } = await runTest(
      [cliPath],
      [`${DOWN}${DOWN}${ENTER}`]
    );
    expect(stdout).toContain("You chose Third option");
  });
});

Find an example here.

About

Write e2e tests for CLI apps with ease

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%
0