shellshot v0.2.2
shellshot
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 theexit codeof the application - By integrating into
jestall of the well known testing API can be used withshellshot - Checking content of files and streams
- Using snapshot testing of
jest
Getting started
Install shellshot in your current directory
$ npm install shellshotThis 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.jsYou 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.