Skip to content

Commit

Permalink
fix(ux): add warning when custom version and --zip are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Nov 8, 2019
1 parent 46f4da5 commit c7875c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 23 additions & 1 deletion test/unit/commands/install-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,38 @@ 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;
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.calledOnce).to.be.true;
});
});

Expand Down

0 comments on commit c7875c9

Please sign in to comment.