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(version): ensure custom version is handled as a string #1112

Merged
merged 1 commit into from
Feb 23, 2020
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
4 changes: 3 additions & 1 deletion lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class InstallCommand extends Command {
const dirIsEmpty = require('../utils/dir-is-empty');
const ensureStructure = require('../tasks/ensure-structure');

let version = argv.version;
// if version is a single number (i.e. 2) yargs converts it to a number.
// We convert it back to a string for consistency
let version = argv.version ? `${argv.version}` : null;

// Check if the directory is empty
if (!dirIsEmpty(process.cwd())) {
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class UpdateCommand extends Command {
);
}

const {force, version, zip, v1} = argv;
const {force, zip, v1} = argv;
const version = argv.version ? `${argv.version}` : null;

const context = {
instance,
Expand Down
28 changes: 28 additions & 0 deletions test/unit/commands/install-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ describe('Unit: Commands > Install', function () {
});
});

it('normalizes version to a string', 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: 2, 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: '2', zip: '', v1: false, _: ['install', 'local']},
cliVersion: '1.0.0'
});
expect(setEnvironmentStub.calledOnce).to.be.true;
expect(setEnvironmentStub.calledWithExactly(true, true)).to.be.true;
});
});

it('calls all tasks and returns after tasks run if --no-setup is passed', function () {
const dirEmptyStub = sinon.stub().returns(true);
const yarnInstallStub = sinon.stub().resolves();
Expand Down