Comprehensive testing documentation for mgrep.
npm run test # Run all tests (unit + E2E)
npm run test:unit # Run unit tests only (Vitest)
npm run test:coverage # Run tests with coverage report
npm run lint # Check code style (Biome)Located in src/**/*.test.ts. Run with:
npm run test:unit # All unit tests
npm run test:unit -- <pattern> # Filter by pattern
npm run test:unit -- watch_mcp # Run MCP tests onlyLocated in test/*.bats. Run with:
npm run test # All tests including E2Enpm run test:coverage # Generate coverage report
npm run test:coverage -- --reporter=html # HTML report in coverage/The MCP server has comprehensive test coverage across three files:
| File | Tests | Purpose |
|---|---|---|
watch_mcp.test.ts |
142 | Unit tests: schemas, constants, mocked handlers |
watch_mcp.helper.test.ts |
21 | Helper functions: formatters, extractors |
watch_mcp.integration.test.ts |
69 | Integration tests via TestMCPClient |
Run all MCP tests:
npm run test:unit -- watch_mcpTests for vector store operations:
npm run test:unit -- storeTests for AI providers (OpenAI, Anthropic, Google, Ollama):
npm run test:unit -- providersIn-memory store implementation for testing without Qdrant:
import { TestStore } from "../lib/store.js";
// Automatically used when MGREP_IS_TEST=1
const store = new TestStore();
await store.upsert("file.ts", "content", { path: "/file.ts", hash: "abc" });
const results = await store.search("query", { limit: 10 });Client for testing MCP tools programmatically:
import { TestMCPClient } from "../lib/test-mcp-client.js";
const client = new TestMCPClient();
await client.connect();
// Call tools
const result = await client.callTool("mgrep-search", { query: "test" });
// List resources
const resources = await client.listResources();
// Get prompts
const prompts = await client.listPrompts();
const message = await client.getPrompt("codebase-overview", {});
await client.disconnect();import { describe, expect, it, vi } from "vitest";
describe("MyFeature", () => {
it("should do something", () => {
const result = myFunction();
expect(result).toBe(expected);
});
it("should handle errors", () => {
expect(() => myFunction(invalid)).toThrow("error message");
});
});import { describe, expect, it, beforeAll, afterAll } from "vitest";
import { TestMCPClient } from "../lib/test-mcp-client.js";
describe("MCP Integration", () => {
let client: TestMCPClient;
beforeAll(async () => {
client = new TestMCPClient();
await client.connect();
});
afterAll(async () => {
await client.disconnect();
});
it("should search successfully", async () => {
const result = await client.callTool("mgrep-search", {
query: "test query",
});
expect(result.isError).toBe(false);
});
});| Variable | Purpose | Default |
|---|---|---|
MGREP_IS_TEST |
Use TestStore instead of Qdrant | undefined |
MGREP_TEST_STORE_PATH |
Path for TestStore file persistence | undefined |
npm run test:unit -- -t "test name pattern"npx vitest watchnpm run test:unit -- --reporter=verbose| File/Area | Target | Current |
|---|---|---|
src/lib/store.ts |
80% | ~93% |
src/lib/context.ts |
80% | 100% |
src/commands/watch_mcp.ts |
80% | ~17%* |
*MCP server coverage is lower because integration tests exercise TestMCPClient, not the actual server code. All functionality is thoroughly tested.
Tests run automatically on:
- Pull requests
- Pushes to main branch
Coverage thresholds can be configured in vitest.config.ts.