-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add zsh autocomplete setup and file permissions instructions to …
…completion:install (#6882) * fix: fixed bugs in completion Co-authored-by: Dylan Spyer <dylanspyer@gmail.com> * fix: add zsh autocompletion setup and file permissions instructions to completion:install Co-authored-by: Dylan Spyer <dylanspyer@gmail.com> * fix: update completion Co-authored-by: Dylan Spyer <dylanspyer@gmail.com> * fix: remove obselete ts-expect-error in command-helpers Co-authored-by: Dylan Spyer <dylanspyer@gmail.com> * fix: update constant imports in completion:install test file Co-authored-by: Dylan Spyer <dylanspyer@gmail.com> --------- Co-authored-by: Dylan Spyer <dylanspyer@gmail.com>
- Loading branch information
1 parent
89e814d
commit 75c0e7b
Showing
3 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
tests/integration/commands/completion/completion-install.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { describe, expect, test, beforeAll, afterAll } from 'vitest' | ||
import fs from 'fs' | ||
import { rm } from 'fs/promises' | ||
import { temporaryDirectory } from 'tempy' | ||
import { handleQuestions, CONFIRM, DOWN, NO, answerWithValue } from '../../utils/handle-questions.js' | ||
import execa from 'execa' | ||
import { cliPath } from '../../utils/cli-path.js' | ||
import { join } from 'path' | ||
import { TABTAB_CONFIG_LINE, AUTOLOAD_COMPINIT } from '../../../../src/utils/command-helpers.js' | ||
|
||
describe('completion:install command', () => { | ||
let tempDir | ||
let zshConfigPath | ||
let options | ||
|
||
beforeAll(() => { | ||
tempDir = temporaryDirectory() | ||
zshConfigPath = join(tempDir, '.zshrc') | ||
options = { cwd: tempDir, env: { HOME: tempDir } } | ||
}) | ||
|
||
afterAll(async () => { | ||
await rm(tempDir, { force: true, recursive: true }) | ||
}) | ||
|
||
test.skipIf(process.env.SHELL !== '/bin/zsh')( | ||
'should add compinit to .zshrc when user confirms prompt', | ||
async (t) => { | ||
fs.writeFileSync(zshConfigPath, TABTAB_CONFIG_LINE) | ||
const childProcess = execa(cliPath, ['completion:install'], options) | ||
|
||
handleQuestions(childProcess, [ | ||
{ | ||
question: 'Which Shell do you use ?', | ||
answer: answerWithValue(DOWN), | ||
}, | ||
{ | ||
question: 'We will install completion to ~/.zshrc, is it ok ?', | ||
answer: CONFIRM, | ||
}, | ||
{ | ||
question: 'Would you like to add it?', | ||
answer: CONFIRM, | ||
}, | ||
]) | ||
|
||
await childProcess | ||
const content = fs.readFileSync(zshConfigPath, 'utf8') | ||
expect(content).toContain(AUTOLOAD_COMPINIT) | ||
}, | ||
) | ||
|
||
test.skipIf(process.env.SHELL !== '/bin/zsh')( | ||
'should not add compinit to .zshrc when user does not confirm prompt', | ||
async (t) => { | ||
fs.writeFileSync(zshConfigPath, TABTAB_CONFIG_LINE) | ||
const childProcess = execa(cliPath, ['completion:install'], options) | ||
|
||
handleQuestions(childProcess, [ | ||
{ | ||
question: 'Which Shell do you use ?', | ||
answer: answerWithValue(DOWN), | ||
}, | ||
{ | ||
question: 'We will install completion to ~/.zshrc, is it ok ?', | ||
answer: CONFIRM, | ||
}, | ||
{ | ||
question: 'Would you like to add it?', | ||
answer: answerWithValue(NO), | ||
}, | ||
]) | ||
|
||
await childProcess | ||
const content = fs.readFileSync(zshConfigPath, 'utf8') | ||
expect(content).not.toContain(AUTOLOAD_COMPINIT) | ||
}, | ||
) | ||
}) |