Skip to content

Commit

Permalink
test: move help tests out to acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Feb 19, 2024
1 parent 04df43f commit ec5609d
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 86 deletions.
112 changes: 112 additions & 0 deletions test/jest/acceptance/help.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { runSnykCLI } from '../util/runSnykCLI';

describe('help', () => {
it('prints help info', async () => {
const { stdout, code, stderr } = await runSnykCLI('help');

expect(stdout).toContain(
'Snyk CLI scans and monitors your projects for security vulnerabilities',
);
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

describe('extensive snyk help', () => {
it('prints help info when called with unknown argument', async () => {
const { stdout, code, stderr } = await runSnykCLI('help hello');

expect(stdout).toContain(
'Snyk CLI scans and monitors your projects for security vulnerabilities',
);
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

it('prints help info when called with flag and unknown argument', async () => {
const { stdout, code, stderr } = await runSnykCLI('--help hello');

expect(stdout).toContain(
'Snyk CLI scans and monitors your projects for security vulnerabilities',
);
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

it('prints specific help info for container', async () => {
const { stdout, code, stderr } = await runSnykCLI('-h container');

expect(stdout).toContain(
'test and continuously monitor container images for vulnerabilities',
);
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

it('prints specific help info for iac', async () => {
const { stdout, code, stderr } = await runSnykCLI('iac -help');

expect(stdout).toContain('Infrastructure as Code');
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

it('prints specific help info when called with flag and equals sign', async () => {
const { stdout, code, stderr } = await runSnykCLI('--help=iac');

expect(stdout).toContain('Infrastructure as Code');
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

it('prints help info for argument with mode', async () => {
const { stdout, code, stderr } = await runSnykCLI(
'--help container test',
);

expect(stdout).toContain(
'tests container images for any known vulnerabilities',
);
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

describe('prints help info without ascii escape sequences', () => {
it('has NO_COLOR set', async () => {
const { stdout, code, stderr } = await runSnykCLI('help', {
env: {
...process.env,
NO_COLOR: '',
},
});

expect(stdout).not.toContain('[1mN');
expect(stdout).not.toContain('[0m');
expect(stdout).not.toContain('[4mC');
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});

it('is not tty', async () => {
// Assuming `runSnykCLI` can pipe output
const { stdout, code, stderr } = await runSnykCLI('help', {
stdio: 'pipe',
});

expect(stdout).not.toContain('[1mN');
expect(stdout).not.toContain('[0m');
expect(stdout).not.toContain('[4mC');
expect(code).toBe(0);
// TODO: Test for stderr when docker issues are resolved
expect(stderr).toBe('');
});
});
});
});
86 changes: 0 additions & 86 deletions test/smoke/spec/snyk_basic_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,92 +19,6 @@ Describe "Snyk CLI basics"
End
End

Describe "snyk help"
It "prints help info"
When run snyk help
The output should include "Snyk CLI scans and monitors your projects for security vulnerabilities"
The status should be success
# TODO: unusable with our current docker issues
The stderr should equal ""
End
End

Describe "extensive snyk help"
Skip if "execute only in regression test" check_if_regression_test

It "prints help info when called with unknown argument"
When run snyk help hello
The output should include " Snyk CLI scans and monitors your projects for security vulnerabilities"
The status should be success
# TODO: unusable with our current docker issues
The stderr should equal ""
End

It "prints help info when called with flag and unknown argument"
When run snyk --help hello
The output should include " Snyk CLI scans and monitors your projects for security vulnerabilities"
The status should be success
# TODO: unusable with our current docker issues
The stderr should equal ""
End

It "prints specific help info for container"
When run snyk -h container
The output should include "test and continuously monitor container images for vulnerabilities"
The status should be success
# TODO: unusable with our current docker issues
The stderr should equal ""
End

It "prints specific help info for iac"
When run snyk iac -help
The output should include "Infrastructure as Code"
The status should be success
# TODO: unusable with our current docker issues
The stderr should equal ""
End

It "prints specific help info when called with flag and equals sign"
When run snyk --help=iac
The output should include "Infrastructure as Code"
The status should be success
# TODO: unusable with our current docker issues
The stderr should equal ""
End

It "prints help info for argument with mode"
When run snyk --help container test
The output should include "tests container images for any known vulnerabilities"
The status should be success
# TODO: unusable with our current docker issues
The stderr should equal ""
End

Describe "prints help info without ascii escape sequences"
It "has NO_COLOR set"
snyk_help_no_color() {
NO_COLOR='' snyk help
}

When run snyk_help_no_color
The output should not include "[1mN"
The output should not include "[0m"
The output should not include "[4mC"
End

It "is not tty"
snyk_help_no_tty() {
snyk help | cat
}

When run snyk_help_no_tty
The output should not include "[1mN"
The output should not include "[0m"
The output should not include "[4mC"
End
End
End

Describe "snyk config"
It "prints config"
When run snyk config
Expand Down

0 comments on commit ec5609d

Please sign in to comment.