Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
fix: do not configure the custom profile for multiple shells (#440)
Browse files Browse the repository at this point in the history
* fix: do not configure the custom profile for multiple shells

* refactor: share config handler

* refactor: concat updating shell configs
  • Loading branch information
iamogbz committed Jul 30, 2019
1 parent 66301e4 commit d616d43
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/commands/configureShell.js
Expand Up @@ -122,20 +122,23 @@ export const configureShell = async ({
fish: configureFish,
zsh: configureZsh,
}
const updatingShellConfigs = []
for (const supportedShell of Object.keys(configHandlers)) {
if (supportedShell.includes(shell)) {
updatingShellConfigs.push(
configHandlers[supportedShell](config),
)
}
}
const configHandler = sh => configHandlers[sh](config)
const configShells = Object.keys(configHandlers)
const supportedShells = configShells.filter(sh => sh.includes(shell))
const updatingShellConfigs = [].concat(
profile && !shell
? supportedShells.reduce(
(conf, sh) => conf.then(r => r || configHandler(sh)),
Promise.resolve(false),
)
: supportedShells.map(configHandler),
)
const shimSuccessful = shim
? configureShim({ yvmDir })
: Promise.resolve(true)
const result = await Promise.all(updatingShellConfigs)
const allSuccessful = result.every(a => a)
const anySuccessful = result.some(a => a)
const allSuccessful = result.every(Boolean)
const anySuccessful = result.some(Boolean)
const isSuccessful =
(allSuccessful || (anySuccessful && !shell)) &&
(await shimSuccessful)
Expand Down
13 changes: 13 additions & 0 deletions test/commands/__snapshots__/configureShell.test.js.snap
Expand Up @@ -20,6 +20,19 @@ export YVM_DIR=config-mock-home/.yvm
`;

exports[`configureShell configures custom profile 1`] = `
Object {
"config-mock-home/.bash_profile": "dummy",
"config-mock-home/.bashrc": "dummy",
"config-mock-home/.config/fish/config.fish": "dummy",
"config-mock-home/.custom_profile": "dummy
set -x YVM_DIR config-mock-install-dir/.yvm
. $YVM_DIR/yvm.fish
",
"config-mock-home/.zshrc": "dummy",
}
`;

exports[`configureShell configures first supported shell for custom profile 1`] = `
Object {
"config-mock-home/.bash_profile": "dummy",
"config-mock-home/.bashrc": "dummy",
Expand Down
21 changes: 20 additions & 1 deletion test/commands/configureShell.test.js
Expand Up @@ -55,7 +55,26 @@ describe('configureShell', () => {
it('configures custom profile', async () => {
expect(
await configureShell({
shell: 'bash',
shell: 'fish',
profile: fileToPath`.custom_profile`,
yvmDir: mockInstallDir,
}),
).toBe(0)
confirmShellConfig()
expect(log.info).toHaveBeenCalledWith(
expect.stringContaining('Configured'),
)
expect(log.info).toHaveBeenCalledWith(
expect.stringContaining(rcFiles.custom),
)
expect(log.default).toHaveBeenCalledWith(
'Shell configured successfully',
)
})

it('configures first supported shell for custom profile', async () => {
expect(
await configureShell({
profile: fileToPath`.custom_profile`,
yvmDir: mockInstallDir,
}),
Expand Down

0 comments on commit d616d43

Please sign in to comment.