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

gentle-cli

v1.0.4

Published

CLI assertions made easy

Downloads

33

Readme

gentle-cli Build Status

Inspired / Based off both cli-easy and supertest

CLI assertions made easy.

  • Struggling with testing cli tools.
  • cli-easy is super great, but designed for generating vows
  • supertest is super great, but designed to make HTTP assertions via super-agent.

gentle-cli is nothing more than a simple, chainable API to ease the process of testing CLI applications & tools.

Right now, it doesn't do anything fancy and just allow you to easily test the exit code and stdout output, and make assertions on top of that.

Documentation

It should work with any test framework, here is an example using any test framework at all.

var cli = require('gentle-cli');

// promise
cli()
  .use('whoami')
  .expect(0, 'A fool')
  .then(function(res) {
    console.log(res.status);
    console.log(res.text);
    console.log(res.err);
  });

// callback
cli()
  .use('uname')
  .expect(0, 'Linux\n')
  .end(function(err, stdout, stderr) {
    if(err) throw err;
  });

ava

Check gentle cli tests, they're using ava:

import test from 'ava';
import cli from '..';
import constants from 'constants';

test('Testing on uname', t => {
  t.plan(0);
  return cli()
    .use('uname')
    .expect(0, process.platform === 'darwin' ? 'Darwin' : 'Linux')
    .end();
});

test('Testing on a wtf thing', t => {
  t.plan(0);
  return cli()
    .use('wtfBinary')
    .expect(constants.ENOENT)
    .throws('ENOENT')
    .end();
});

cli().end() returns a promise you can pass through ava, as well as .then() and .catch().

Tips Make sure to call t.plan(0) if you're doing assertions using gentle-cli and not ava. Otherwise, ava will fail.

mocha

Here's an example with mocha, note how you can pass done straight to any of the .expect() calls (or .end()):

describe('test uname', function() {
  it('respond with Linux', function(done) {
    cli()
      .use('uname')
      .expect('should return Linux', 'Linux\n')
      .expect(0, done)
  });
});

fancier example.

describe('Testing on a wtf thing', function() {
  it('should fail as expected', function(done) {
    cli()
      .use('wtfBinary')
      .expect(127, /command not found/)
      .end(done);
  });
});

promise example

API

module.exports = Runnable;

Main assertion thingy

Thx to @tj, based off supertest's Runnable object: https://github.com/visionmedia/supertest/blob/master/lib/Runnable.js

function Runnable(cmds, options)

Initialize a new Runnable with the given options Hash object.

Runnable#use()

Setup CLI command.

Runnable#expect()

Adds a new expectation to this runnable instance.

.expect(0)
.expect(0, fn)
.expect(0, body)
.expect('Some body')
.expect('Some body', fn)

Runnable#throws()

Adds a new expectation to this runnable instance.

.throws(0)
.throws('ENOENT')
.throws(require('constants').ENOENT)

Runnable#end()

Defer invoking .end() until the command is done running.

it('test thing', function(done) {
  cli()
    .use('thing')
    .expect(/run thing/)
    .end(done);
});

Returns a promise.

Runnable#then()

Automatically invokes end() and register the callback.

Returns a promise.

Runnable#catch()

Automatically invokes end() and register the errback.

Returns a promise.

Changelog

Unreleased

v1.0.4 - 2018-09-30

Fixed

  • Switch to exec instead of spawn #1 #2

Commits

  • es6: update test.js to use most of es6 syntax (thx prettier) cff47b0
  • Rewrite test.js using es6 class syntax 055059d
  • Update test, setup travis ee72e69

v1.0.3 - 2016-04-26

Commits

v1.0.2 - 2016-04-25

Commits

v1.0.1 - 2016-04-25

Commits

v1.0.0 - 2016-04-25

Commits

  • Update code, implement throws and better support of node core errors 6c22c97
  • Document api d7dd12f

v0.0.2 - 2012-09-20

Commits

  • updates, adding prompt api, multiple expecs, adding API docs cecca5f

v0.0.1 - 2012-07-18

Commits