From 8ad52a1b379b422dbf3336d4b8093c89afe9e4a2 Mon Sep 17 00:00:00 2001 From: Liliana Kastilio Date: Mon, 8 Oct 2018 10:58:43 +0100 Subject: [PATCH] fix: pass if yarn remove called with no packages --- src/cli/commands/test.js | 4 ++-- src/lib/protect/update.js | 6 ++++-- src/lib/snyk-test/npm/index.js | 2 +- test/wizard-prepare.test.js | 4 ++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/test.js b/src/cli/commands/test.js index a221f9f840..0d05bf71b1 100644 --- a/src/cli/commands/test.js +++ b/src/cli/commands/test.js @@ -455,8 +455,8 @@ function metaForDisplay(res, options) { chalk.bold(rightPadWithSpaces('Organisation: ', padToLength)) + res.org, chalk.bold(rightPadWithSpaces('Package manager: ', padToLength)) + packageManager, ]; - if (options.file) { - meta.push(chalk.bold(rightPadWithSpaces('Target file: ', padToLength)) + options.file); + if (options.file || options.testedFile) { + meta.push(chalk.bold(rightPadWithSpaces('Target file: ', padToLength)) + options.file || options.testedFile); } if (options.docker) { meta.push(chalk.bold(rightPadWithSpaces('Docker image: ', padToLength)) + options.path); diff --git a/src/lib/protect/update.js b/src/lib/protect/update.js index e3c7502bf2..278c82696e 100644 --- a/src/lib/protect/update.js +++ b/src/lib/protect/update.js @@ -67,9 +67,11 @@ function update(packages, live, pkgManager) { var devToUninstall = (upgrade.dev && upgrade.dev.map(stripVersion)) || []; var toUninstall = _.uniq(prodToUninstall.concat(devToUninstall)); - debug('to uninstall', toUninstall); - return uninstall(pkgManager, toUninstall, live); + + if (!_.isEmpty(toUninstall)) { + return uninstall(pkgManager, toUninstall, live); + } }) .then(function () { var prodUpdate = (upgrade.prod ? diff --git a/src/lib/snyk-test/npm/index.js b/src/lib/snyk-test/npm/index.js index 225ce84939..eecaae316a 100644 --- a/src/lib/snyk-test/npm/index.js +++ b/src/lib/snyk-test/npm/index.js @@ -54,7 +54,7 @@ function test(root, options) { let policyLocations = [options['policy-path'] || root]; const targetFile = options.file || detect.detectPackageFile(root); // this is used for Meta - options.file = targetFile; + options.testedFile = targetFile; return Promise.resolve() .then(() => { diff --git a/test/wizard-prepare.test.js b/test/wizard-prepare.test.js index 6b16d00999..e263f42b58 100644 --- a/test/wizard-prepare.test.js +++ b/test/wizard-prepare.test.js @@ -3,6 +3,7 @@ var proxyquire = require('proxyquire'); var sinon = require('sinon'); var spy = sinon.spy(); var _ = require('lodash'); +var dir = __dirname + '/fixtures/protect-via-snyk/'; var fixture = require('./fixtures/protect-via-snyk/package.json'); var wizard = proxyquire('../src/cli/commands/protect/wizard', { @@ -31,6 +32,8 @@ var wizard = proxyquire('../src/cli/commands/protect/wizard', { test('npm - prepare is added and postinstall is removed', function (t) { var expectedResults = _.cloneDeep(fixture); + process.chdir(dir); + return wizard.processAnswers({ // answers 'misc-test-no-monitor': true, @@ -51,6 +54,7 @@ test('npm - prepare is added and postinstall is removed', function (t) { test('yarn - prepare is added and postinstall is removed', function (t) { var expectedResults = _.cloneDeep(fixture); + process.chdir(dir); spy.reset(); return wizard.processAnswers({ // answers