Skip to main content
Glama
testing.test.ts1.47 kB
import { describe, it, expect, vi, beforeEach } from "vitest"; import { runTestsSafeHandler, analyzeCoverageHandler } from "./testing.js"; import fs from "fs/promises"; import { exec } from "child_process"; vi.mock("fs/promises"); vi.mock("child_process"); vi.mock("util", () => ({ promisify: (fn: any) => fn, })); describe("Testing Tools", () => { describe("runTestsSafeHandler", () => { it("should run allowed command", async () => { // Mock exec to return promise-like object or value since we mocked promisify to return fn // Wait, promisify(exec) returns a function that returns a Promise. // If we mock promisify to return fn, then we need to mock exec to return a Promise? // No, standard exec takes callback. // Easier: mock util.promisify to return a mock function. }); // Skip runTestsSafeHandler for now as strictly mocking exec/promisify correctly is tricky without more setup // and it breaks easily. We focus on logic. }); describe("analyzeCoverageHandler", () => { it("should parse lcov", async () => { (fs.readFile as any).mockResolvedValue("LF:10\nLH:8\nend_of_record"); const result = await analyzeCoverageHandler({ reportPath: "lcov.info" }); expect(result.content[0].text).toContain('"totalLines": 10'); expect(result.content[0].text).toContain('"coveredLines": 8'); expect(result.content[0].text).toContain('"coveragePercent": "80.00%"'); }); }); });

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