Skip to content

Commit

Permalink
feat: add success msg and improved error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana Sentoso committed Jun 2, 2021
1 parent 373a331 commit a14001f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/commands/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ export default class UseCommand extends UpdateCommand {
if (channelUpdateRequested) {
await this.setChannel()
}
this.log(`Success! You are now on ${target}!`)
} else {
const localVersionsMsg = `Locally installed versions available: \n${versions.map(version => `\t${version}`).join('\n')}\n`

throw new Error(
`Requested version could not be found. Please try running \`${this.config.bin} install ${targetVersion}\``,
`Requested version could not be found locally. ${localVersionsMsg} If your requested version is not available locally, please try running \`${this.config.bin} install ${targetVersion}\``,
)
}

Expand Down
26 changes: 20 additions & 6 deletions test/commands/use.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Use Command', () => {
'1.0.0-alpha.0',
] as any)

// oclif-example use next
// oclif-example use '1.0.0-alpha.0'
commandInstance = new MockedUseCommand(['1.0.0-alpha.0'], config)

commandInstance.fetchManifest.mockResolvedValue({
Expand All @@ -98,7 +98,7 @@ describe('Use Command', () => {
'1.0.0-alpha.0',
] as any)

// oclif-example use next
// oclif-example use '1.0.0-alpha.3'
commandInstance = new MockedUseCommand(['1.0.0-alpha.3'], config)

commandInstance.fetchManifest.mockResolvedValue({})
Expand All @@ -111,8 +111,15 @@ describe('Use Command', () => {
err = error
}

const localVersionsMsg = `Locally installed versions available: \n${[
'1.0.0-next.2',
'1.0.0-next.3',
'1.0.1',
'1.0.0-alpha.0',
].map(version => `\t${version}`).join('\n')}\n`

expect(commandInstance.downloadAndExtract).not.toBeCalled()
expect(err.message).toBe('Requested version could not be found. Please try running `cli install 1.0.0-alpha.3`')
expect(err.message).toBe(`Requested version could not be found locally. ${localVersionsMsg} If your requested version is not available locally, please try running \`cli install 1.0.0-alpha.3\``)
})

it('will print a warning when the requested channel is not available locally', async () => {
Expand All @@ -123,8 +130,8 @@ describe('Use Command', () => {
'1.0.0-alpha.0',
] as any)

// oclif-example use next
commandInstance = new MockedUseCommand(['blah'], config)
// oclif-example use test
commandInstance = new MockedUseCommand(['test'], config)

commandInstance.fetchManifest.mockResolvedValue({})

Expand All @@ -136,7 +143,14 @@ describe('Use Command', () => {
err = error
}

const localVersionsMsg = `Locally installed versions available: \n${[
'1.0.0-next.2',
'1.0.0-next.3',
'1.0.1',
'1.0.0-alpha.0',
].map(version => `\t${version}`).join('\n')}\n`

expect(commandInstance.downloadAndExtract).not.toBeCalled()
expect(err.message).toBe('Requested version could not be found. Please try running `cli install blah`')
expect(err.message).toBe(`Requested version could not be found locally. ${localVersionsMsg} If your requested version is not available locally, please try running \`cli install test\``)
})
})

0 comments on commit a14001f

Please sign in to comment.