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: adjust spacing on 'test' output #197

Merged
merged 1 commit into from
Aug 20, 2018
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
29 changes: 20 additions & 9 deletions cli/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,31 +431,42 @@ function createTruncatedVulnsPathsText(vulnList) {
}
}

function rightPadWithSpaces(s, desiredLength) {
var padLength = desiredLength - s.length;
if (padLength <= 0) {
return s;
}

var padding = Array.from({length: padLength + 1}).join(' ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it would work on Node 4. Alternatively, here's another thing that probably wouldn't work: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darscan You are right - not even on Node 6, based on https://node.green/.

@adrukh Sorry, repeat should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grrr was too fast with the merge button!

Will amend this

return s + padding;
}

function metaForDisplay(res, options) {
var padToLength = 19; // chars to align
var packageManager = options.packageManager || res.packageManager;
var openSource = res.isPrivate ? 'no' : 'yes';
var meta = [
chalk.bold('Organisation: ') + res.org,
chalk.bold('Package manager: ') + packageManager,
chalk.bold(rightPadWithSpaces('Organisation: ', padToLength)) + res.org,
chalk.bold(rightPadWithSpaces('Package manager: ', padToLength)) + packageManager,
];
if (options.file) {
meta.push(chalk.bold('Target file: ') + options.file);
meta.push(chalk.bold(rightPadWithSpaces('Target file: ', padToLength)) + options.file);
}
if (options.docker) {
meta.push(chalk.bold('Docker image: ') + options.path);
meta.push(chalk.bold(rightPadWithSpaces('Docker image: ', padToLength)) + options.path);
} else {
meta.push(chalk.bold('Open source: ') + openSource);
meta.push(chalk.bold('Project path: ') + options.path);
meta.push(chalk.bold(rightPadWithSpaces('Open source: ', padToLength)) + openSource);
meta.push(chalk.bold(rightPadWithSpaces('Project path: ', padToLength)) + options.path);
}

if (res.filesystemPolicy) {
meta.push(chalk.bold('Local Snyk policy: ') + chalk.green('found'));
meta.push(chalk.bold(rightPadWithSpaces('Local Snyk policy: ', padToLength)) + chalk.green('found'));
if (res.ignoreSettings && res.ignoreSettings.disregardFilesystemIgnores) {
meta.push(chalk.bold('Local Snyk policy ignored: ') + chalk.red('yes'));
meta.push(chalk.bold(rightPadWithSpaces('Local Snyk policy ignored: ', padToLength)) + chalk.red('yes'));
}
}
if (res.licensesPolicy) {
meta.push(chalk.bold('Licenses: ') + chalk.green('enabled'));
meta.push(chalk.bold(rightPadWithSpaces('Licenses: ', padToLength)) + chalk.green('enabled'));
}

return meta.join('\n');
Expand Down
50 changes: 25 additions & 25 deletions test/acceptance/cli.acceptance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ test('`test ruby-app` returns correct meta', function (t) {
return cli.test('ruby-app')
.then(function (res) {
var meta = res.slice(res.indexOf('Organisation:')).split('\n');
t.equal(meta[0], 'Organisation: test-org', 'organisation displayed');
t.equal(meta[1], 'Package manager: rubygems',
t.match(meta[0], /Organisation:\s+test-org/, 'organisation displayed');
t.match(meta[1], /Package manager:\s+rubygems/,
'package manager displayed');
t.equal(meta[2], 'Target file: Gemfile', 'target file displayed');
t.equal(meta[3], 'Open source: no', 'open source displayed');
t.equal(meta[4], 'Project path: ruby-app', 'path displayed');
t.notEqual(meta[5], 'Local Snyk policy: found',
t.match(meta[2], /Target file:\s+Gemfile/, 'target file displayed');
t.match(meta[3], /Open source:\s+no/, 'open source displayed');
t.match(meta[4], /Project path:\s+ruby-app/, 'path displayed');
t.notMatch(meta[5], /Local Snyk policy:\s+found/,
'local policy not displayed');
});
});
Expand All @@ -239,13 +239,13 @@ test('`test gradle-app` returns correct meta', function (t) {
return cli.test('gradle-app')
.then(function (res) {
var meta = res.slice(res.indexOf('Organisation:')).split('\n');
t.equal(meta[0], 'Organisation: test-org', 'organisation displayed');
t.equal(meta[1], 'Package manager: gradle',
t.match(meta[0], /Organisation:\s+test-org/, 'organisation displayed');
t.match(meta[1], /Package manager:\s+gradle/,
'package manager displayed');
t.equal(meta[2], 'Target file: build.gradle', 'target file displayed');
t.equal(meta[3], 'Open source: no', 'open source displayed');
t.equal(meta[4], 'Project path: gradle-app', 'path displayed');
t.notEqual(meta[5], 'Local Snyk policy found',
t.match(meta[2], /Target file:\s+build.gradle/, 'target file displayed');
t.match(meta[3], /Open source:\s+no/, 'open source displayed');
t.match(meta[4], /Project path:\s+gradle-app/, 'path displayed');
t.notMatch(meta[5], /Local Snyk policy:\s+found/,
'local policy not displayed');
});
});
Expand All @@ -256,13 +256,13 @@ test('`test` returns correct meta for a vulnerable result', function (t) {
.catch(function (res) {
var meta = res.message.slice(res.message.indexOf('Organisation:'))
.split('\n');
t.equal(meta[0], 'Organisation: test-org', 'organisation displayed');
t.equal(meta[1], 'Package manager: rubygems',
t.match(meta[0], /Organisation:\s+test-org/, 'organisation displayed');
t.match(meta[1], /Package manager:\s+rubygems/,
'package manager displayed');
t.equal(meta[2], 'Target file: Gemfile', 'target file displayed');
t.equal(meta[3], 'Open source: no', 'open source displayed');
t.equal(meta[4], 'Project path: ruby-app', 'path displayed');
t.notEqual(meta[5], 'Local Snyk policy: found',
t.match(meta[2], /Target file:\s+Gemfile/, 'target file displayed');
t.match(meta[3], /Open source:\s+no/, 'open source displayed');
t.match(meta[4], /Project path:\s+ruby-app/, 'path displayed');
t.notMatch(meta[5], /Local Snyk policy:\s+found/,
'local policy not displayed');
});
});
Expand All @@ -272,7 +272,7 @@ test('`test` returns correct meta when target file specified', function (t) {
return cli.test('ruby-app', {file: 'Gemfile.lock'})
.then(function (res) {
var meta = res.slice(res.indexOf('Organisation:')).split('\n');
t.equal(meta[2], 'Target file: Gemfile.lock', 'target file displayed');
t.match(meta[2], /Target file:\s+Gemfile.lock/, 'target file displayed');
});
});

Expand All @@ -281,12 +281,12 @@ test('`test npm-package-policy` returns correct meta', function (t) {
return cli.test('npm-package-policy')
.then(function (res) {
var meta = res.slice(res.indexOf('Organisation:')).split('\n');
t.equal(meta[0], 'Organisation: test-org', 'organisation displayed');
t.equal(meta[1], 'Package manager: npm', 'package manager displayed');
t.equal(meta[2], 'Target file: package.json', 'target file displayed');
t.equal(meta[3], 'Open source: no', 'open source displayed');
t.equal(meta[4], 'Project path: npm-package-policy', 'path displayed');
t.equal(meta[5], 'Local Snyk policy: found', 'local policy displayed');
t.match(meta[0], /Organisation:\s+test-org/, 'organisation displayed');
t.match(meta[1], /Package manager:\s+npm/, 'package manager displayed');
t.match(meta[2], /Target file:\s+package.json/, 'target file displayed');
t.match(meta[3], /Open source:\s+no/, 'open source displayed');
t.match(meta[4], /Project path:\s+npm-package-policy/, 'path displayed');
t.match(meta[5], /Local Snyk policy:\s+found/, 'local policy displayed');
});
});

Expand Down