specshell
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Build status

specshell

Write JavaScript specs for shell commands

Installation

For use only within your tests:

npm install --save-dev specshell

More advanced usage may require:

npm install --save specshell

Features

  • Use any test framework (or none)
  • Use JavaScript or TypeScript

Quick start: testing shell commands

Write shell tests using your preferred test framework. Use specshell to run shell commands.

const specshell = require('specshell');

Create a new shell.

const shell = new specshell.Shell();

Send it a command and examine the results. Another process is involved so you must await the results of running any shell command. (Your test framework should support this; most do, including Jest, Mocha and Ava).

const assert = require('assert').strict;
 
async function test() {
  const { out, err } = await shell.run('echo hello, shell');
  assert.equal(out.toString(), 'hello, shell');
  assert.equal(err.toString(), '');
}
test();

Shell.run returns exitCode or signal for each command run. If the shell itself dies it throws specshell.ShellError.

API

Shell

constructor(shellPath, spawnOptions)

Constructs to use a shell found at shellPath (default '/bin/bash') passing spawnOptions. Currently these are the same as for child_process.spawn, but option stdio will be ignored if you pass it.

run(script)

Runs script inside shell: passes every line to the shell and a newline at the end.

Package Sidebar

Install

npm i specshell

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

796 kB

Total Files

13

Last publish

Collaborators

  • lagache
  • ashevat
  • duckranger
  • spacebug
  • almonds