cook-mcp-windy
Version:
HowToCook MCP Server - Intelligent Chinese recipe management and meal planning for AI assistants
122 lines ⢠4 kB
JavaScript
import { toolHandlers } from '../tools/index.js';
/**
* Test runner for HowToCook MCP Server tools
*/
export async function runTests(options = {}) {
console.log('đ§Ş HowToCook MCP Server Test Suite');
console.log('===================================\n');
const tests = options.specificTool
? [options.specificTool]
: Object.keys(toolHandlers);
const results = [];
for (const toolName of tests) {
if (options.verbose) {
console.log(`đ Testing tool: ${toolName}`);
}
const result = await runToolTest(toolName, options.verbose || false);
results.push(result);
if (result.passed) {
console.log(`â
${result.name} - ${result.duration}ms`);
}
else {
console.log(`â ${result.name} - ${result.error}`);
}
// Wait between tests
await new Promise(resolve => setTimeout(resolve, 100));
}
// Print summary
console.log('\nđ Test Summary:');
console.log('================');
const passed = results.filter(r => r.passed).length;
const failed = results.filter(r => !r.passed).length;
const totalTime = results.reduce((sum, r) => sum + r.duration, 0);
console.log(`â
Passed: ${passed}`);
console.log(`â Failed: ${failed}`);
console.log(`âąď¸ Total time: ${totalTime}ms`);
console.log(`đ Success rate: ${Math.round((passed / results.length) * 100)}%`);
if (failed > 0) {
console.log('\nâ Failed tests:');
results.filter(r => !r.passed).forEach(r => {
console.log(` ⢠${r.name}: ${r.error}`);
});
process.exit(1);
}
else {
console.log('\nđ All tests passed!');
}
}
async function runToolTest(toolName, verbose) {
const startTime = Date.now();
try {
const handler = toolHandlers[toolName];
if (!handler) {
throw new Error(`Tool handler not found: ${toolName}`);
}
// Get test data for the tool
const testData = getTestData(toolName);
if (verbose) {
console.log(` Input: ${JSON.stringify(testData, null, 2)}`);
}
// Execute the tool
const result = await handler(testData);
if (verbose) {
console.log(` Output: ${JSON.stringify(result, null, 2).substring(0, 200)}...`);
}
// Validate result
if (!result || typeof result.success !== 'boolean') {
throw new Error('Invalid response format');
}
if (!result.success) {
throw new Error(result.error || 'Tool returned failure');
}
return {
name: toolName,
passed: true,
duration: Date.now() - startTime
};
}
catch (error) {
return {
name: toolName,
passed: false,
error: error instanceof Error ? error.message : 'Unknown error',
duration: Date.now() - startTime
};
}
}
function getTestData(toolName) {
const testCases = {
'get_all_recipes': {
limit: 3,
includeDetails: false
},
'get_recipes_by_category': {
category: 'č¤č',
limit: 2
},
'get_recipe_details': {
identifier: 'recipe_001',
includeNutrition: true
},
'recommend_meal_plan': {
preferences: {
numberOfPeople: 2,
cookingSkillLevel: 'ä¸çş§',
budgetLevel: 'ä¸ç'
},
planDuration: 3,
includeShoppingList: false
},
'recommend_dish_combination': {
preferences: {
numberOfPeople: 4,
occasion: 'ćĽĺ¸¸',
budgetLevel: 'ä¸ç'
},
maxDishes: 3,
includeAnalysis: false
}
};
return testCases[toolName] || {};
}
//# sourceMappingURL=testRunner.js.map