Skip to main content
Glama
research.test.ts1.98 kB
import { describe, it, expect, vi, beforeEach } from "vitest"; import { researchDocumentationHandler } from "./research.js"; // Mock fetch const fetchMock = vi.fn(); global.fetch = fetchMock; describe("researchDocumentationHandler", () => { beforeEach(() => { vi.clearAllMocks(); }); it("should fetch and convert HTML to Markdown", async () => { fetchMock.mockResolvedValue({ ok: true, text: async () => ` <html> <body> <h1>Documentation</h1> <p>This is a test.</p> </body> </html> `, }); const result = await researchDocumentationHandler({ url: "https://example.com/docs", }); const content = result.content[0].text; expect(content).toContain("# Research Result: https://example.com/docs"); expect(content).toContain("# Documentation"); expect(content).toContain("This is a test."); }); it("should use selector if provided", async () => { fetchMock.mockResolvedValue({ ok: true, text: async () => ` <html> <body> <nav>Menu</nav> <main> <h1>Main Content</h1> </main> <footer>Footer</footer> </body> </html> `, }); const result = await researchDocumentationHandler({ url: "https://example.com/docs", selector: "main", }); const content = result.content[0].text; expect(content).toContain("Main Content"); expect(content).not.toContain("Menu"); expect(content).not.toContain("Footer"); }); it("should handle errors gracefully", async () => { fetchMock.mockResolvedValue({ ok: false, status: 404, statusText: "Not Found", }); const result = await researchDocumentationHandler({ url: "https://example.com/404", }); expect(result.isError).toBe(true); expect(result.content[0].text).toContain("Error fetching documentation"); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/millsydotdev/Code-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server