From c7875c9ba7de463b34778c58f4354d513a1ad855 Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Thu, 7 Nov 2019 17:35:57 +0700 Subject: [PATCH] fix(ux): add warning when custom version and --zip are passed --- lib/commands/install.js | 4 ++++ test/unit/commands/install-spec.js | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/commands/install.js b/lib/commands/install.js index 89b3926a4..d04a0a694 100644 --- a/lib/commands/install.js +++ b/lib/commands/install.js @@ -97,6 +97,10 @@ class InstallCommand extends Command { const {resolveVersion, versionFromZip} = require('../utils/version'); const {version, zip, v1} = ctx.argv; + if (version && zip) { + ctx.ui.log('Warning: you specified both a specific version and a zip file. The version in the zip file will be used.', 'yellow'); + } + let resolvedVersion = null; if (zip) { resolvedVersion = await versionFromZip(zip); diff --git a/test/unit/commands/install-spec.js b/test/unit/commands/install-spec.js index 1999921f2..6d34614a1 100644 --- a/test/unit/commands/install-spec.js +++ b/test/unit/commands/install-spec.js @@ -308,9 +308,30 @@ describe('Unit: Commands > Install', function () { const InstallCommand = proxyquire(modulePath, { '../utils/version': {resolveVersion, versionFromZip} }); + const log = sinon.stub(); + + const testInstance = new InstallCommand({}, {}); + const context = {argv: {zip: '/some/zip/file.zip'}, ui: {log}}; + + await testInstance.version(context); + expect(resolveVersion.called).to.be.false; + expect(versionFromZip.calledOnce).to.be.true; + expect(versionFromZip.calledWith('/some/zip/file.zip')).to.be.true; + expect(context.version).to.equal('1.5.2'); + expect(context.installPath).to.equal(path.join(process.cwd(), 'versions/1.5.2')); + expect(log.called).to.be.false; + }); + + it('logs if both version and zip are passed', async function () { + const resolveVersion = sinon.stub().resolves('1.5.0'); + const versionFromZip = sinon.stub().resolves('1.5.2'); + const InstallCommand = proxyquire(modulePath, { + '../utils/version': {resolveVersion, versionFromZip} + }); + const log = sinon.stub(); const testInstance = new InstallCommand({}, {}); - const context = {argv: {version: '1.0.0', zip: '/some/zip/file.zip'}}; + const context = {argv: {version: '1.0.0', zip: '/some/zip/file.zip'}, ui: {log}}; await testInstance.version(context); expect(resolveVersion.called).to.be.false; @@ -318,6 +339,7 @@ describe('Unit: Commands > Install', function () { expect(versionFromZip.calledWith('/some/zip/file.zip')).to.be.true; expect(context.version).to.equal('1.5.2'); expect(context.installPath).to.equal(path.join(process.cwd(), 'versions/1.5.2')); + expect(log.calledOnce).to.be.true; }); });