shell-tester
A little library to create automated tests for shell setups. When a test is run, it also generates a detailed output of the shell session, which can be used to create screenshots or videos of the test.
I use this library to test my dotfiles and generate example screenshots for my shell setup.
Example
example.js
const { ShellTester } = require('shell-tester')
const tester = new ShellTester({ shellCommand: 'sh' }) (1)
tester.session('example', async (s) => { (2)
await s.expect('$') (3)
await s.send('ls\r')
await s.expect('package.json')
})
tester.run() (4)
1 | Create a ShellTester and specify the shell command to use. |
2 | Register a test session using the session method. |
3 | Automate the shell using the provided ShellSession object. |
4 | Run the registered sessions by calling the run method. |
For more detailed examples, see the test.js file.
Installation
This module is not versioned and is not published on npm. To install it directly from GitHub, run:
$ yarn add "dtinth/shell-tester#main"
To pin the dependency in your package.json file and prevent breaking changes from affecting your project, replace main with the SHA of the latest commit.
|
Output file
This will generate a file called tmp/output/example_end.js
in the current directory
which contains the detailed output of the shell session.
A simple HTML viewer can be used to view the output:
$ echo "file://$PWD/node_modules/shell-tester/preview.html?data=../../tmp/output/example_end.js"
(Open the URL in your browser to see the output.)