run_test
Execute test commands in development directories to verify code functionality and identify issues. Supports npm, yarn, and pnpm package managers for comprehensive testing workflows.
Instructions
Run tests in the current directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | No | Test command to run (e.g., "npm test", "yarn test") | npm test |
| directory | No | Directory to run tests in (default: current directory) |
Implementation Reference
- src/index.ts:190-212 (handler)The main handler function for the 'run_test' tool. It executes the test command (default 'npm test') in the specified directory using execSync, captures output, and returns success or throws error with details.private async runTest(args: any) { const command = args?.command || 'npm test'; const directory = args?.directory || process.cwd(); try { const output = execSync(command, { cwd: directory, encoding: 'utf8', timeout: 300000 // 5 minutes }); return { content: [ { type: 'text', text: `Tests passed!\nCommand: ${command}\nDirectory: ${directory}\nOutput:\n${output}` } ] }; } catch (error: any) { throw new Error(`Tests failed: ${error.message}\nStderr: ${error.stderr || 'N/A'}`); } }
- src/index.ts:63-80 (schema)The tool schema definition including name, description, and input schema for parameters 'command' and 'directory'.{ name: 'run_test', description: 'Run tests in the current directory', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Test command to run (e.g., "npm test", "yarn test")', default: 'npm test' }, directory: { type: 'string', description: 'Directory to run tests in (default: current directory)' } } } },
- src/index.ts:141-142 (registration)The dispatch case in the CallToolRequestHandler that routes calls to the 'run_test' tool to the runTest handler method.case 'run_test': return await this.runTest(args);