0.2.2 • Published 4 years ago

shellshot v0.2.2

Weekly downloads
5
License
BSD-3-Clause-Attr...
Repository
-
Last release
4 years ago

shellshot

build status code coverage maintainability code size npm minified size npm.io gitter donate Built with Spacemacs

A command-line interface testing extension for jest.


What is shellshot?

The main purpose of shellshot is running end2end tests for command-line applications. By providing a speaking API, it is also suited for non-javascript applications and is actually meant to be used for all types of command-line applications.

Features

  • Run any given command and test for stdout, stderr, and the exit code of the application
  • By integrating into jest all of the well known testing API can be used with shellshot
  • Checking content of files and streams
  • Using snapshot testing of jest

Getting started

Install shellshot in your current directory

$ npm install shellshot

This will create a node_modules folder containing all dependencies for shellshot including jest. Make sure to add node_modules to your .gitignore. The package-lock.json file should also be added to your .gitignore.

Creating your first test

To run jest tests in your current folder you need to create a jest configuration:

$ touch jest.config.js

You can leave the config empty for now.

Now create a new file awesome.test.js with the following content:

const { setup } = require('shellshot');

setup();

it(
    'should run my first shellshot test',
    async () => {
        await expect.command('ls -l')
            .forStdout(expectation => expectation.toContain('jest.config.js'))
            .forExitCode(expectation => expectation.toBe(0));
    },
);

Now run lets run your first test:

$ ./node_modules/.bin/jest
 PASS  ./awesome.test.js
  ✓ should run my first shellshot test (12ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.863s
Ran all test suites.

Have a look at the examples folder for more examples.

0.2.2

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago