Skip to main content
Glama
mednabouli

MCP Multi-Context Hook Generator

by mednabouli
componentTests.ts•1.52 kB
import fs from 'fs'; import path from 'path'; import { ComponentInfo } from '../crawler/components'; import { enrichComponentTests } from '../ai/enrichComponentTests'; export interface TestGeneratorOptions { outputDir: string; aiAgent?: 'none' | 'copilot' | 'openai' | 'custom'; dryRun?: boolean; } export async function generateComponentTests( components: ComponentInfo[], options: TestGeneratorOptions, ) { if (!fs.existsSync(options.outputDir)) { fs.mkdirSync(options.outputDir, { recursive: true }); } for (const comp of components) { const testFile = path.join(options.outputDir, `${comp.name}.test.tsx`); const aiExtra = await enrichComponentTests(comp, options.aiAgent || 'none'); const testContent = ` import React from "react"; import { render, screen } from "@testing-library/react"; import ${comp.name} from "${comp.filePath.replace(/\\/g, '/')}"; describe("${comp.name}", () => { it("renders without crashing", () => { render(<${comp.name} />); expect(screen.getByTestId("${comp.name.toLowerCase()}")).toBeInTheDocument(); }); ${ comp.props.length > 0 ? `it("accepts props correctly", () => { render(<${comp.name} ${comp.props.map((p) => `${p}: "test"`).join(' ')} />); });` : '' } ${aiExtra} }); `; if (options.dryRun) { console.log(`📝 [DryRun] Would generate test: ${testFile}`); } else { fs.writeFileSync(testFile, testContent, 'utf-8'); console.log(`✅ Generated test: ${testFile}`); } } }

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/mednabouli/MCPV2'

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