Design goal is to have a single test suite, that can detect if CLI is not working properly - before and after it's released. Defects it should catch are e.g. broken pkg builds for a specific platform, misaligned dependencies or issues with a specific installation targets.
CLI is being tested by a series of tests using Shellspec. See them in a test/smoke/spec
folder.
Spec in this folder is used as a
- "Smoke test" step in CircleCI to verify that built CLI can run
- "Smoke Tests" GitHub Action to verify that our distribution channels are working.
Smoke tests should be fast. Ideally tests only things that could break when CLI is being built and packaged into binaries. Functionality should be tested our other tests.
Before you start adding specs, those files are bash scripts, it's recommended to have a ShellCheck installed and running in your IDE. See Shellspec reference for available commands.
It's recommended to have a branch named smoke/_SOMETHING_
, as this branch will run the GitHub Action.
To run these tests locally you may use npm run test:smoke
:
-
Install:
-
Install dependencies for the local fixture
test/fixtures/basic-npm
withnpm install --prefix test/fixtures/basic-npm
-
Run shellspec locally:
Note that you will need shellspec version 0.28.1
or higher.
From the root of the snyk
repo, run:
npm run test:smoke
REGRESSION_TEST=1
enables the extended mode we use for regression testing. For the hourly tests in GitHub Actions we use a limited scope of tested commands.
You may specify an envvar TEST_SNYK_COMMAND
to any executable that will be used by Smoke tests. E.g. a local exuctable SNYK_COMMAND="./snyk-macos"
or an SNYK_COMMAND="npx [email protected]"
or SNYK_COMMAND="node ./dist/cli"
for local execution.
This will meddle with your snyk config
file as Smoke Tests are checking functionality of snyk config
command.
This will open a browser in one instance unless it's disabled with SMOKE_TESTS_SKIP_TEST_THAT_OPENS_BROWSER=1
envvar. Opening of a browser is disabled by default when running Smoke tests with npm command npm run test:smoke
.
- be able to run against PR
- basics: version, help, config
- auth [TOKEN]
- test [--json][npm project]
- test [--json][java-goof]
- policy, ignore
- monitor [--json][npm project]
- monitor [--json][java-goof]
- wizard - possibly impossible? (maybe a basic test that it even loads)
- Alpine binary
- Docker: current images can't output a clear stderr, because of an extraneous --json flag. Also released version is currently lagging behind the latest GitHub tag by a few hours
- yarn installation
- scoop package
- homebrew
- Needs to run in a Docker container because GitHub Actions don't support Alpine as a host OS. Using shellspec container, as it's based on alpine and ready to run the tests.
- Need to skip a test that normally tries to open browser for login, but that fails horribly on Alpine.
To run the Alpine test in Docker locally (you probably don't want to…):
docker build -f ./test/smoke/alpine/Dockerfile -t snyk-cli-alpine ./test/ && docker run --rm -eTEST_SNYK_TOKEN=$SNYK_API_TOKEN snyk-cli-alpine
Note: Alpine image is not copying/mounting everything, so you might need to add anything new to the test/smoke/alpine/Dockerfile