Skip to content

Commit 6185d9d

Browse files
committed
test: Improve Server mock and Homedir handling in tests
1 parent f14f6a5 commit 6185d9d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/__tests__/server.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ vi.mock('@modelcontextprotocol/sdk/types.js', () => ({
2424
return error;
2525
})
2626
}));
27-
vi.mock('@modelcontextprotocol/sdk/server/index.js', () => ({
28-
Server: vi.fn().mockImplementation(function() {
29-
return {
30-
setRequestHandler: vi.fn(),
31-
connect: vi.fn(),
32-
close: vi.fn(),
33-
onerror: undefined,
34-
};
35-
}),
36-
}));
27+
vi.mock('@modelcontextprotocol/sdk/server/index.js', () => {
28+
// Create a more robust mock for the Server class
29+
const MockServer = vi.fn().mockImplementation(function(this: any) {
30+
this.setRequestHandler = vi.fn();
31+
this.connect = vi.fn();
32+
this.close = vi.fn();
33+
this.onerror = undefined; // Ensure it's a property that can be set
34+
// Add any other methods or properties expected by the ClaudeCodeServer
35+
});
36+
return { Server: MockServer };
37+
});
3738

3839
// Mock package.json
3940
vi.mock('../../package.json', () => ({
@@ -60,6 +61,7 @@ describe('ClaudeCodeServer Unit Tests', () => {
6061
originalEnv = { ...process.env };
6162
// Reset env
6263
process.env = { ...originalEnv };
64+
mockHomedir.mockReturnValue('/fake/home'); // Ensure homedir is mocked for all tests by default
6365
});
6466

6567
afterEach(() => {

0 commit comments

Comments
 (0)