Skip to content

Commit b0ecf1f

Browse files
nickclaude
andcommitted
fix(test): add missing mocks to chat.commands.execution.test.ts
The test was causing Jest worker crashes in CI due to missing mocks for auth-adapter and config/manager modules. This fix aligns the test with the pattern used in statistics.commands.execution.test.ts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e090199 commit b0ecf1f

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

packages/cli/src/commands/chat.commands.execution.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,54 @@ import { ChatHandler } from '../handlers/chat.handler';
1111
// Mock the ChatHandler class
1212
jest.mock('../handlers/chat.handler');
1313

14+
// Mock auth and config modules
15+
jest.mock('../config/auth-adapter', () => ({
16+
authAdapter: {
17+
tryGetAuthConfig: jest.fn().mockReturnValue({
18+
config: {
19+
appId: 'test-app-id',
20+
appSecret: 'test-app-secret',
21+
userId: 'test-user-id',
22+
},
23+
source: 'test',
24+
accountName: 'test-account',
25+
}),
26+
getStatusMessage: jest.fn().mockReturnValue('Authentication required'),
27+
getDiagnostics: jest.fn().mockReturnValue({
28+
availableSources: [],
29+
errors: [],
30+
}),
31+
},
32+
}));
33+
34+
jest.mock('../config/manager', () => ({
35+
configManager: {
36+
load: jest.fn().mockResolvedValue({
37+
config: {
38+
baseUrl: 'https://api.polyv.net',
39+
timeout: 30000,
40+
debug: false,
41+
},
42+
}),
43+
},
44+
}));
45+
46+
// Mock process.exit
47+
const mockExit = jest.spyOn(process, 'exit').mockImplementation((code) => {
48+
throw new Error(`process.exit:${code}`);
49+
});
50+
51+
// Suppress console output during tests
52+
const mockConsoleLog = jest.spyOn(console, 'log').mockImplementation();
53+
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation();
54+
1455
describe('Chat Commands - Command Execution', () => {
1556
let program: Command;
1657
let mockChatHandler: jest.Mocked<ChatHandler>;
1758

1859
beforeEach(() => {
60+
jest.clearAllMocks();
61+
1962
program = new Command();
2063
program.exitOverride();
2164

@@ -37,6 +80,12 @@ describe('Chat Commands - Command Execution', () => {
3780
registerChatCommands(program);
3881
});
3982

83+
afterAll(() => {
84+
mockExit.mockRestore();
85+
mockConsoleLog.mockRestore();
86+
mockConsoleError.mockRestore();
87+
});
88+
4089
// ========================================
4190
// AC #1: chat send command execution
4291
// ========================================

0 commit comments

Comments
 (0)