fix(cli): refactor test config loading and mock debugLogger in test-setup (#24389)

This commit is contained in:
matt korwel
2026-03-31 20:11:02 -07:00
committed by GitHub
parent 8ae5b56b5b
commit c9ed5e41b1
2 changed files with 27 additions and 9 deletions
+21 -2
View File
@@ -6,7 +6,7 @@
import { vi, beforeEach, afterEach } from 'vitest';
import { format } from 'node:util';
import { coreEvents } from '@google/gemini-cli-core';
import { coreEvents, debugLogger } from '@google/gemini-cli-core';
import { themeManager } from './src/ui/themes/theme-manager.js';
import { mockInkSpinner } from './src/test-utils/mockSpinner.js';
@@ -42,10 +42,25 @@ import './src/test-utils/customMatchers.js';
let consoleErrorSpy: vi.SpyInstance;
let actWarnings: Array<{ message: string; stack: string }> = [];
let logSpy: vi.SpyInstance;
let warnSpy: vi.SpyInstance;
let errorSpy: vi.SpyInstance;
let debugSpy: vi.SpyInstance;
beforeEach(() => {
// Reset themeManager state to ensure test isolation
themeManager.resetForTesting();
// Mock debugLogger to avoid test output noise
logSpy = vi.spyOn(debugLogger, 'log').mockImplementation(() => {});
warnSpy = vi.spyOn(debugLogger, 'warn').mockImplementation((...args) => {
console.warn(...args);
});
errorSpy = vi.spyOn(debugLogger, 'error').mockImplementation((...args) => {
console.error(...args);
});
debugSpy = vi.spyOn(debugLogger, 'debug').mockImplementation(() => {});
actWarnings = [];
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation((...args) => {
const firstArg = args[0];
@@ -88,8 +103,12 @@ beforeEach(() => {
afterEach(() => {
consoleErrorSpy.mockRestore();
vi.unstubAllEnvs();
logSpy?.mockRestore();
warnSpy?.mockRestore();
errorSpy?.mockRestore();
debugSpy?.mockRestore();
vi.unstubAllEnvs();
if (actWarnings.length > 0) {
const messages = actWarnings
.map(({ message, stack }) => `${message}\n${stack}`)