@physihan/deepwiki-mcp
Version:
DeepWiki MCP server implementation
45 lines (36 loc) • 1.1 kB
text/typescript
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
// 模拟FastMCP
const mockAddTool = vi.fn();
const mockStart = vi.fn().mockResolvedValue(undefined);
const mockFastMCP = vi.fn(() => ({
addTool: mockAddTool,
start: mockStart,
}));
vi.mock("fastmcp", () => ({
FastMCP: mockFastMCP,
}));
// 模拟服务器入口点,防止它真的启动
vi.mock("../src/server.js", () => {
return {};
});
describe("Server", () => {
beforeEach(() => {
vi.clearAllMocks();
mockFastMCP.mockClear();
mockAddTool.mockClear();
mockStart.mockClear();
});
afterEach(() => {
vi.resetAllMocks();
});
test("服务器配置的基本测试", async () => {
// 手动调用MockFastMCP来验证它
const instance = mockFastMCP();
expect(mockFastMCP).toHaveBeenCalled();
// 测试实例方法
instance.addTool({ name: "test_tool" });
expect(mockAddTool).toHaveBeenCalledWith({ name: "test_tool" });
await instance.start({ transportType: "stdio" });
expect(mockStart).toHaveBeenCalledWith({ transportType: "stdio" });
});
});