Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: snyk --version #971

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/commands/protect/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as _ from 'lodash';
import { exec } from 'child_process';
import { apiTokenExists } from '../../../lib/api-token';
import * as auth from '../auth/is-authed';
import { getVersion } from '../version';
import getVersion = require('../version');
import * as allPrompts from './prompts';
import answersToTasks = require('./tasks');
import * as snyk from '../../../lib/';
Expand Down
4 changes: 3 additions & 1 deletion src/cli/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from '../../lib/version';
import { getVersion } from '../../lib/version';

export = getVersion;
8 changes: 2 additions & 6 deletions src/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function getBranchCommitAndDirty(promises): Promise<string> {
const branchName = res[0];
const commitStr = res[1];
const filesCount = res[2];
const dirtyCount = parseInt(filesCount, 10);
const dirtyCount = parseInt(filesCount, 10) || 0;
let curr = branchName + ': ' + commitStr;
if (dirtyCount !== 0) {
curr += ' (' + dirtyCount + ' dirty files)';
Expand All @@ -41,8 +41,4 @@ async function getBranchCommitAndDirty(promises): Promise<string> {

const commit = () => executeCommand('git rev-parse HEAD', root);
const branch = () => executeCommand('git rev-parse --abbrev-ref HEAD', root);
const dirty = () =>
executeCommand(
'expr $(git status --porcelain 2>/dev/null| ' + 'egrep "^(M| M)" | wc -l)',
root,
);
const dirty = () => executeCommand('git diff --shortstat', root);
23 changes: 23 additions & 0 deletions test/acceptance/cli-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { test } from 'tap';
import { exec } from 'child_process';
import { sep } from 'path';
const osName = require('os-name');

const main = './dist/cli/index.js'.replace(/\//g, sep);
const iswindows =
osName()
.toLowerCase()
.indexOf('windows') === 0;

// TODO(kyegupov): make these work in Windows
test('snyk test command should fail when --file is not specified correctly', (t) => {
Expand All @@ -19,6 +24,24 @@ test('snyk test command should fail when --file is not specified correctly', (t)
});
});

test(
'snyk version command should show cli version or sha',
{ skip: iswindows },
(t) => {
t.plan(1);
exec(`node ${main} --version`, (err, stdout) => {
if (err) {
throw err;
}
t.match(
stdout.trim(),
':', // can't guess branch or sha or dirty files, but we do always add `:`
'version is shown',
);
});
},
);

test('snyk test command should fail when --packageManager is not specified correctly', (t) => {
t.plan(1);
exec(`node ${main} test --packageManager=hello`, (err, stdout) => {
Expand Down