2.2.1 • Published 10 months ago
slack-cli-test-util v2.2.1
slack-cli-test-util
This library is designated to automate Slack Command Line Interface (CLI) methods. It provides a simplified and programmatic way to interact with the CLI and is used primarily for E2E testing.
Quickstart guide
- Install the package
npm install slack-cli-test-util
- Set cli path with environment variable
SLACK_CLI_PATH
- supply a link to a binary on the global path, like
slack-cli
- it will default to using
slack
otherwise - slack cli must be installed separately
- supply a link to a binary on the global path, like
- Import and use SlackCLILib, VerificationHelper or SlackTracerId
import { SlackCLILib } from 'slack-cli-test-util';
...
const actualOutput = await SlackCLILib.runSimpleCommand('slack-cli version');
How to use the package
- SlackCLILib - contains all methods to interact with cli
- methods named after slack cli methods, e.g.
SlackCLILib.deploy()
- methods named after slack cli methods, e.g.
- VerificationHelper - helper methods to verify cli output
- shouldContainString
- shouldContainStrings
- shouldNotContainStrings
- SlackTracerId - trace IDs to verify cli command output
- see available exported IDs on SlackTracerId object
- to enable:
SLACK_TEST_TRACE=true
// Import avialable objects from the package
import { SlackCLILib, SlackTracerId, VerificationHelper } from 'slack-cli-test-util';
describe('CLI - Feedback', () => {
// Create a variable with a link to cli binary installed on your machine
const cli = process.env.SLACK_CLI_PATH;
it('can successfully follow the feedback survey link', async function () {
// Create command
const command = `${cli} feedback`;
// Collect actual output from the command
const actual = await SlackCLILib.runSimpleCommand(command);
// Set expected array of strings
const expected = [
// Expected string
'Feedback survey',
// Available trace
SlackTracerId.SLACK_TRACE_FEEDBACK_MESSAGE
];
// Check results with helper command
await VerificationHelper.shouldContainStrings(actual, expected, command);
});
});
Configuration
EnvVar | Required | Note |
---|---|---|
SLACK_CLI_PATH | yes | path to slack cli binary |
SLACK_CLI_LOG_LEVEL | no | default: 'info'. Logger levels |