Skip to content

Commit

Permalink
fix: snyk policy command execution error and missed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertKogan committed Aug 18, 2019
1 parent 86c411e commit 241d0a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cli/commands/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as policy from 'snyk-policy';
import {display} from '../../lib/display-policy';
import {FailedToLoadPolicyError, PolicyNotFoundError} from '../../lib/errors';

export async function displayPolicy(path) {
async function displayPolicy(path?: string): Promise<string> {
try {
const loadedPolicy = await policy.load(path || process.cwd());
const loadedPolicy = await policy.load(path || process.cwd()) as Promise<string>;
return await display(loadedPolicy);
} catch (error) {
if (error.code === 'ENOENT') {
Expand All @@ -16,3 +16,5 @@ export async function displayPolicy(path) {
throw error;
}
}

export = displayPolicy;
13 changes: 13 additions & 0 deletions test/system/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const server = require('../cli-server')(
// ensure this is required *after* the demo server, since this will
// configure our fake configuration too
import * as cli from '../../src/cli/commands';
import {PolicyNotFoundError} from '../../src/lib/errors';

const before = test;
const after = test;
Expand Down Expand Up @@ -235,6 +236,18 @@ test('auth via github', (t) => {
});
});

test('snyk policy', (t) => {
t.plan(2);

cli.policy().then(() => {
t.pass('policy called');
});

cli.policy('wrong/path').catch((error) => {
t.match(error, PolicyNotFoundError);
});
});

after('teardown', (t) => {
t.plan(4);

Expand Down

0 comments on commit 241d0a3

Please sign in to comment.