Skip to content

Commit fd08040

Browse files
committed
update
1 parent ce4aba9 commit fd08040

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
22
import { Server } from "./server.js";
33

4-
async function runServer() {
4+
export async function runServer() {
55
const server = new Server();
66

77
const transport = new StdioServerTransport();

tests/unit/index.test.ts

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
import { jest, describe, it, expect, beforeEach } from "@jest/globals";
2-
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport";
2+
import {runServer} from "../../src/index";
3+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio";
34

4-
// Mock modules with proper typing
5-
jest.mock("@modelcontextprotocol/sdk/server/stdio", () => ({
6-
StdioServerTransport: jest.fn().mockImplementation(() => ({}) as Transport),
7-
}));
85

9-
// Properly type the mock function to return Promise<void>
10-
const mockConnect = jest.fn<() => Promise<void>>().mockResolvedValue();
11-
jest.mock("../../src/server", () => ({
12-
Server: jest.fn().mockImplementation(() => ({
13-
state: undefined,
14-
apiClient: undefined,
15-
initialized: false,
16-
connect: mockConnect,
17-
})),
18-
}));
6+
// mock the StdioServerTransport
7+
jest.mock('@modelcontextprotocol/sdk/server/stdio.js');
8+
// mock Server class and its methods
9+
jest.mock('../../src/server.ts', () => {
10+
return {
11+
Server: jest.fn().mockImplementation(() => {
12+
return {
13+
connect: jest.fn().mockImplementation((transport) => {
14+
return new Promise((resolve) => {
15+
resolve(transport);
16+
});
17+
}),
18+
};
19+
}),
20+
};
21+
});
1922

20-
describe("Server initialization", () => {
21-
beforeEach(() => {
22-
jest.clearAllMocks();
23-
jest.resetModules();
24-
});
2523

24+
describe("Server initialization", () => {
2625
it("should create a server instance", async () => {
27-
const { Server } = await import("../../src/server");
28-
const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio");
29-
30-
// Import the module under test
31-
await import("../../src/index");
32-
33-
expect(Server).toHaveBeenCalledTimes(1);
34-
expect(StdioServerTransport).toHaveBeenCalledTimes(1);
35-
expect(mockConnect).toHaveBeenCalledTimes(1);
26+
const server = await runServer();
27+
expect(StdioServerTransport).toHaveBeenCalled();
3628
});
3729
});

0 commit comments

Comments
 (0)