JSPM

cli-prompts-test

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 61
  • Score
    100M100P100Q63939F
  • License GPL-3.0

Write e2e tests for CLI apps with ease

Package Exports

  • cli-prompts-test

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cli-prompts-test) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 { exitCode, stdout } = await runTest(
      [cliPath],
      [ENTER]
    );

    // Assertions
    expect(exitCode).toBe(0);
    expect(stdout).toContain("You chose First option");
  });

  it("picks second option", async () => {
    const { exitCode, stdout } = await runTest(
      [cliPath],
      [`${DOWN}${ENTER}`]
    );

    // Assertions
    expect(exitCode).toBe(0);
    expect(stdout).toContain("You chose Second option");
  });

  it("picks third option", async () => {
    const { exitCode, stdout } = await runTest(
      [cliPath],
      [`${DOWN}${DOWN}${ENTER}`]
    );

    // Assertions
    expect(exitCode).toBe(0);
    expect(stdout).toContain("You chose Third option");
  });
});

Find an example here.