Skip to content

Commit

Permalink
fix: udpate channel to stable if version request is not a diff channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana Sentoso committed Jun 17, 2021
1 parent d8a1745 commit 5314226
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default class InstallCommand extends UpdateCommand {
if (versionParts && versionParts[1]) {
this.channel = versionParts[1].substr(0, versionParts[1].indexOf('.'));
this.debug(`Flag overriden target channel: ${this.channel}`);
} else if (versionParts.length === 1) {
// If there is only one version part then the channel must be stable
this.channel = 'stable';
}

const versions = fs
Expand Down
25 changes: 24 additions & 1 deletion test/commands/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('Install Command', () => {
version: '2.2.1-next.22',
baseDir: 'test-cli',
channel: 'next',
gz: 'https://test-cli-oclif.s3.amazonaws.com/test-cli-v2.2.1-next.22/test-cli-v2.2.1-next.22.tar.gz',
gz: 'https://test-cli-oclif.s3.amazonaws.com/channels/next/test-cli-v2.2.1-next.22/test-cli-v2.2.1-next.22.tar.gz',
},
});

Expand All @@ -84,6 +84,29 @@ describe('Install Command', () => {
expect(commandInstance.updatedVersion).toBe('2.2.1-next.22');
});

it('when requesting a version from stable, will update channel to stable and return the explicit version with appropriate URL', async () => {
config.pjson.oclif.update.s3.host = 'https://test-cli-oclif.com/';
config.binPath = 'cli';
config.channel = 'next';
mockFs.readdirSync.mockReturnValue([] as any);
commandInstance = new MockedInstallCommand(['2.2.1'], config);

http.get.mockResolvedValue({
body: {
version: '2.2.1',
baseDir: 'test-cli',
channel: 'stable',
gz: 'https://test-cli-oclif.s3.amazonaws.com/test-cli-v2.2.1/test-cli-v2.2.1.tar.gz',
},
});

await commandInstance.run();

expect(commandInstance.downloadAndExtract).toBeCalled();
expect(commandInstance.channel).toBe('stable');
expect(commandInstance.updatedVersion).toBe('2.2.1');
});

it('when requesting a version already available locally, will call updateToExistingVersion', async () => {
mockFs.readdirSync.mockReturnValue([
'1.0.0-next.2',
Expand Down

0 comments on commit 5314226

Please sign in to comment.