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

cli-tester

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-tester

Lean promisified wrapper to test NodeJS CLI scripts

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

cli-tester npm

Discord

CircleCI AppVeyor Travis Coverage Dependencies Dev Dependencies

Lean promisified wrapper to test NodeJS CLI scripts

Plays nicely with blue-tape

Installation

npm install --save-dev cli-tester

Usage

const test = require('blue-tape');
const tester = require('cli-tester');


test('Successful run', t =>
  tester(require.resolve('./cli-that-is-ok'))
    .then(({code, stdout, stderr}) => {
      t.equal(code, 0, 'should exit with code 0');
      t.equal(stdout, 'check expected output');
      t.equal(stderr, '', 'should not have any errors');
    }));


test('CLI throws', t =>
  tester(require.resolve('./cli-that-throws'))
    .then(({code, stdout, stderr}) => {
      t.equal(code, 1, 'should exit with code 1');
      t.equal(stdout, '', 'should not have any output');
      t.ok(stderr.match('some error from CLI'));
    }));

Node 5 and older

const tester = require('cli-tester/es5');

API

tester(cli, env, ...args)

Returns ES6 Promise, that is always successful

cli - string

Resolved path to JS CLI, ideally absolute path

tester(require.resolve('./cli'))

env (optional) - object

Object with ENV vars

tester(require.resolve('./cli'), {OMG: 'OMG!'})

...args (optional) - string

List of command line arguments

// With omitted ENV
tester(require.resolve('./cli'), '--hello', 'world')

// With ENV
tester(require.resolve('./cli'), {OMG: 'OMG!'},'--hello', 'world')

Development and testing

Currently is being developed and tested with the latest stable Node 7 under OSX and Windows.

git clone git@github.com:nkbt/cli-tester.git
cd cli-tester
npm install

Tests

# to run tests
npm test

# to generate test coverage (./coverage)
npm run cov

License

MIT

Keywords

FAQs

Package last updated on 07 Nov 2016

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