mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 18:15:23 +00:00
fix(test): avoid global ui mock leakage in shell completion tests
This commit is contained in:
1 parent
ae83be1590
commit
851f870fa8
1 file changed
+12
-12
@@ -34,13 +34,9 @@ mock.module('../../../src/utils/shell-completion', () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
mock.module('../../../src/utils/ui', () => ({
|
function stripAnsi(value: string): string {
|
||||||
initUI: async () => {},
|
return value.replace(/\u001b\[[0-9;]*m/g, '');
|
||||||
header: (value: string) => value,
|
}
|
||||||
ok: (value: string) => value,
|
|
||||||
fail: (value: string) => value,
|
|
||||||
color: (value: string) => value,
|
|
||||||
}));
|
|
||||||
|
|
||||||
let handleShellCompletionCommand: (args: string[]) => Promise<void>;
|
let handleShellCompletionCommand: (args: string[]) => Promise<void>;
|
||||||
let parseShellCompletionArgs: (args: string[]) => { targetShell: ShellTarget; force: boolean };
|
let parseShellCompletionArgs: (args: string[]) => { targetShell: ShellTarget; force: boolean };
|
||||||
@@ -125,16 +121,20 @@ describe('shell-completion command', () => {
|
|||||||
|
|
||||||
await handleShellCompletionCommand(['--zsh']);
|
await handleShellCompletionCommand(['--zsh']);
|
||||||
|
|
||||||
expect(logLines.some((line) => line.includes('Shell completion already installed'))).toBe(true);
|
const plainLogLines = logLines.map(stripAnsi);
|
||||||
expect(logLines.some((line) => line.includes('Use --force to reinstall'))).toBe(true);
|
expect(plainLogLines.some((line) => line.includes('Shell completion already installed'))).toBe(
|
||||||
expect(logLines.some((line) => line.includes('installed successfully!'))).toBe(false);
|
true
|
||||||
|
);
|
||||||
|
expect(plainLogLines.some((line) => line.includes('Use --force to reinstall'))).toBe(true);
|
||||||
|
expect(plainLogLines.some((line) => line.includes('installed successfully!'))).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prints usage and exits with code 1 on installer error', async () => {
|
it('prints usage and exits with code 1 on installer error', async () => {
|
||||||
installError = new Error('boom');
|
installError = new Error('boom');
|
||||||
|
|
||||||
await expect(handleShellCompletionCommand([])).rejects.toThrow('process.exit(1)');
|
await expect(handleShellCompletionCommand([])).rejects.toThrow('process.exit(1)');
|
||||||
expect(errorLines.some((line) => line.includes('Error: boom'))).toBe(true);
|
const plainErrorLines = errorLines.map(stripAnsi);
|
||||||
expect(errorLines.some((line) => line.includes('ccs --shell-completion --zsh'))).toBe(true);
|
expect(plainErrorLines.some((line) => line.includes('Error: boom'))).toBe(true);
|
||||||
|
expect(plainErrorLines.some((line) => line.includes('ccs --shell-completion --zsh'))).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user