npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

interactive-cli-tester

v0.3.0

Published

A tool for testing interactive command line interfaces

Downloads

50

Readme

Interactive CLI Tester

npm version npm downloads license CodeFactor codecov install size

A tool for testing interactive command line interfaces that require keyboard input.

⚠️ This software is still in development and not ready for production use.

You can find a complete API documentation here.

Features

  • Test every command line interface - no matter in which programming language it is written 🧪
  • Test interactive command line interfaces that require user input ⌨️
  • Independent of the testing framework you want to use 😎
  • Zero dependencies 📦

Getting Started

You can install this package using npm:

npm install --save-dev interactive-cli-tester

The following example shows how to test a simple interactive CLI build with enquirer using Jest. But you can use any Node.js testing framework you want.

import { CLITest, ANSI } from 'interactive-cli-tester';

test('Test example CLI', async () => {
    const cliTest = new CLITest('node', ['examples/readme.mjs']);

    // Start the process, you can re-use the same instance for multiple runs
    await cliTest.run();

    // Wait until the CLI asks for input
    await cliTest.waitForOutput('What do you want to do?');
    // Equivalent to pressing down arrow and enter
    await cliTest.write(ANSI.CURSOR_DOWN + ANSI.CR);

    // Expect the CLI to ask for the name
    await cliTest.waitForOutput('Input your name');
    await cliTest.write('Acme' + ANSI.CR);

    // Wait for the process to exit and check the exit code
    expect(await cliTest.waitForExit()).toBe(0);

    // Check that the output contains the expected text
    expect(cliTest.getOutput().includes('Hello Acme!')).toBe(true);
});

A complete API documentation including all available methods and options can be found here.

Code Coverage

It can be difficult to configure your testing framework to collect code coverage for Node.js child processes. For example, Jest does not support this out of the box (#5274), even though bcoe/c8 and istanbuljs/nyc do. One possible workaround for Jest is described in this comment, but this is not a perfect solution and may not work when using TypeScript.

You can find a complicated and not perfect workaround using two seperate Jest runners and nyc in my repo timokoessler/docker-deploy-api. I am not using c8 because of the issue #462.

If you have a question, have found a better way or successfully used another testing framework, please create an issue or send me a message.

Sources

Contact

If a public GitHub issue or discussion is not the right choice for your concern, you can contact me directly:

License

© Timo Kössler 2024
Released under the MIT license