fix(cli): conditionally suppress console output in headless and non-interactive modes

This commit is contained in:
Cynthia Long
2026-03-16 23:36:20 +00:00
parent 55778583b9
commit 2e466bd4cb
4 changed files with 29 additions and 3 deletions
@@ -43,6 +43,26 @@ describe('ConsolePatcher', () => {
console.error = originalError;
});
it('should NOT suppress console.error even when suppressConsoleOutput is true', () => {
const originalError = console.error;
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
patcher = new ConsolePatcher({
debugMode: false,
suppressConsoleOutput: true,
stderr: true,
});
patcher.patch();
console.error('test error');
expect(errorSpy).toHaveBeenCalled();
patcher.cleanup();
errorSpy.mockRestore();
console.error = originalError;
});
it('should NOT suppress output when suppressConsoleOutput is true but debugMode is true', () => {
const originalError = console.error;
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+5 -1
View File
@@ -50,7 +50,11 @@ export class ConsolePatcher {
private patchConsoleMethod =
(type: 'log' | 'warn' | 'error' | 'debug' | 'info') =>
(...args: unknown[]) => {
if (this.params.suppressConsoleOutput && !this.params.debugMode) {
if (
this.params.suppressConsoleOutput &&
!this.params.debugMode &&
type !== 'error'
) {
return;
}