From 9494d51ea14087a65fac9166813ccdff009dbc10 Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Thu, 7 Nov 2019 16:56:15 +0700 Subject: [PATCH] feat(install): improved local install ux --- lib/commands/install.js | 2 +- test/unit/commands/install-spec.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/commands/install.js b/lib/commands/install.js index cce8c5704..89b3926a4 100644 --- a/lib/commands/install.js +++ b/lib/commands/install.js @@ -30,7 +30,7 @@ class InstallCommand extends Command { // If command is `ghost install local`, or command is // `ghost install 1.x.x --local`, do a local install - if (version === 'local' || argv.local) { + if (version === 'local' || argv.local || (argv._ && argv._.includes('local'))) { local = true; version = (version === 'local') ? null : version; this.system.setEnvironment(true, true); diff --git a/test/unit/commands/install-spec.js b/test/unit/commands/install-spec.js index 502c19cd8..1999921f2 100644 --- a/test/unit/commands/install-spec.js +++ b/test/unit/commands/install-spec.js @@ -132,6 +132,34 @@ describe('Unit: Commands > Install', function () { }); }); + it('runs local install when command is `ghost install local`', function () { + const dirEmptyStub = sinon.stub().returns(true); + const listrStub = sinon.stub(); + listrStub.onFirstCall().resolves(); + listrStub.onSecondCall().rejects(); + const setEnvironmentStub = sinon.stub(); + + const InstallCommand = proxyquire(modulePath, { + '../utils/dir-is-empty': dirEmptyStub + }); + const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub}); + const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves(); + + return testInstance.run({version: '1.5.0', zip: '', v1: false, _: ['install', 'local']}).then(() => { + expect(false, 'run should have rejected').to.be.true; + }).catch(() => { + expect(dirEmptyStub.calledOnce).to.be.true; + expect(runCommandStub.calledOnce).to.be.true; + expect(listrStub.calledOnce).to.be.true; + expect(listrStub.args[0][1]).to.deep.equal({ + argv: {version: '1.5.0', zip: '', v1: false, _: ['install', 'local']}, + cliVersion: '1.0.0' + }); + expect(setEnvironmentStub.calledOnce).to.be.true; + expect(setEnvironmentStub.calledWithExactly(true, true)).to.be.true; + }); + }); + it('handles case with custom version and export file', function () { const dirEmptyStub = sinon.stub().returns(true); const yarnInstallStub = sinon.stub().resolves();