flutter_test
Execute Flutter tests in a project directory to verify code functionality, with options to run specific test files and generate coverage reports.
Instructions
Run Flutter tests with optional coverage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | Yes | Working directory (Flutter project root) | |
| testFile | No | Specific test file to run (optional) | |
| coverage | No | Enable test coverage |
Implementation Reference
- src/tools/flutter.ts:732-785 (handler)The main handler function for the 'flutter_test' tool. It validates input using FlutterTestSchema, verifies the Flutter project directory, optionally specifies a test file and enables coverage, executes the 'flutter test' command via processExecutor, and returns structured results including output, errors, duration, and pass status.handler: async (args: any) => { const validation = FlutterTestSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd, testFile, coverage = false } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const flutter_args = ['test']; if (testFile) { // Validate test file path (must be .dart file in test directory) if (!testFile.endsWith('.dart')) { throw new Error(`Test file must be a .dart file. Invalid test file: ${testFile}`); } // Check if test file exists const testFilePath = path.isAbsolute(testFile) ? testFile : path.join(cwd, testFile); try { await fs.access(testFilePath); } catch { throw new Error(`Test file not found. File does not exist: ${testFilePath}`); } flutter_args.push(testFile); } if (coverage) { flutter_args.push('--coverage'); } const result = await processExecutor.execute('flutter', flutter_args, { cwd, timeout: 600000, // 10 minutes timeout for tests }); return { success: true, data: { testFile: testFile || 'all tests', coverage, projectPath: cwd, exitCode: result.exitCode, output: result.stdout, errors: result.stderr, duration: result.duration, passed: result.exitCode === 0, }, }; } });
- src/tools/flutter.ts:97-101 (schema)Zod validation schema (FlutterTestSchema) for the flutter_test tool inputs: cwd (required), testFile (optional), coverage (optional boolean, defaults to false). Used in the handler for input validation.const FlutterTestSchema = z.object({ cwd: z.string().min(1), testFile: z.string().optional(), coverage: z.boolean().default(false), });
- src/tools/flutter.ts:720-786 (registration)Registration of the 'flutter_test' tool within the createFlutterTools factory function. Includes name, description, JSON Schema for inputs (compatible with MCP), and reference to the handler function.tools.set('flutter_test', { name: 'flutter_test', description: 'Run Flutter tests with optional coverage', inputSchema: { type: 'object', properties: { cwd: { type: 'string', minLength: 1, description: 'Working directory (Flutter project root)' }, testFile: { type: 'string', description: 'Specific test file to run (optional)' }, coverage: { type: 'boolean', description: 'Enable test coverage' } }, required: ['cwd'] }, handler: async (args: any) => { const validation = FlutterTestSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd, testFile, coverage = false } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const flutter_args = ['test']; if (testFile) { // Validate test file path (must be .dart file in test directory) if (!testFile.endsWith('.dart')) { throw new Error(`Test file must be a .dart file. Invalid test file: ${testFile}`); } // Check if test file exists const testFilePath = path.isAbsolute(testFile) ? testFile : path.join(cwd, testFile); try { await fs.access(testFilePath); } catch { throw new Error(`Test file not found. File does not exist: ${testFilePath}`); } flutter_args.push(testFile); } if (coverage) { flutter_args.push('--coverage'); } const result = await processExecutor.execute('flutter', flutter_args, { cwd, timeout: 600000, // 10 minutes timeout for tests }); return { success: true, data: { testFile: testFile || 'all tests', coverage, projectPath: cwd, exitCode: result.exitCode, output: result.stdout, errors: result.stderr, duration: result.duration, passed: result.exitCode === 0, }, }; } });
- src/types/index.ts:140-144 (schema)Exported Zod schema for FlutterTest in types module, used potentially for type inference or shared validation.export const FlutterTestSchema = z.object({ cwd: z.string(), testFile: z.string().optional(), coverage: z.boolean().optional(), });
- src/utils/tool-categories.ts:203-211 (helper)Metadata registration in TOOL_REGISTRY for 'flutter_test', defining category, platform, requirements (Flutter), performance expectations, and safety flags.'flutter_test': { name: 'flutter_test', category: ToolCategory.ESSENTIAL, platform: 'flutter', requiredTools: [RequiredTool.FLUTTER], description: 'Run Flutter tests', safeForTesting: false, performance: { expectedDuration: 30000, timeout: 120000 } },