detox_generate_test
Create Detox test files for React Native apps by describing test scenarios in natural language. Generates complete E2E test code from descriptions to automate mobile testing.
Instructions
Generate a complete Detox test file from a description.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | Natural language description of the test scenario | |
| testName | Yes | Name for the test/describe block | |
| outputPath | No | Where to write the generated test file | |
| includeSetup | No | ||
| platform | No | cross-platform |
Implementation Reference
- src/tools/index.ts:328-357 (handler)The main handler function for the 'detox_generate_test' tool. It parses input arguments, generates a test file template using generateTestFileTemplate, optionally writes it to a file, and returns the generated code.export const generateTestTool: Tool = { name: "detox_generate_test", description: "Generate a complete Detox test file from a description.", inputSchema: zodToJsonSchema(GenerateTestArgsSchema), handler: async (args: z.infer<typeof GenerateTestArgsSchema>) => { const parsed = GenerateTestArgsSchema.parse(args); const testCode = generateTestFileTemplate({ testName: parsed.testName, describeName: parsed.testName, includeSetup: parsed.includeSetup, tests: [ { name: parsed.description, code: ` // Test: ${parsed.description}\n // TODO: Implement test based on the description above`, }, ], }); if (parsed.outputPath) { await writeFile(parsed.outputPath, testCode, "utf-8"); } return { success: true, code: testCode, outputPath: parsed.outputPath, }; }, };
- src/utils/validators.ts:87-96 (schema)Zod schema defining the input parameters for the detox_generate_test tool, including test description, name, output path, setup inclusion, and platform.// Generate test schema export const GenerateTestArgsSchema = z.object({ description: z.string().describe("Natural language description of the test scenario"), testName: z.string().describe("Name for the test/describe block"), outputPath: z.string().optional().describe("Where to write the generated test file"), includeSetup: z.boolean().optional().default(true), platform: z.enum(["ios", "android", "cross-platform"]).optional().default("cross-platform"), }); export type GenerateTestArgs = z.infer<typeof GenerateTestArgsSchema>;
- src/templates/test-templates.ts:5-43 (helper)Core helper function that generates the Detox test file template code, including describe block, beforeAll/beforeEach hooks, and it test stubs. Called by the tool handler.export function generateTestFileTemplate(options: { testName: string; describeName?: string; includeSetup?: boolean; tests?: Array<{ name: string; code: string }>; }): string { const describeName = options.describeName || options.testName; const tests = options.tests || [ { name: "should work correctly", code: " // TODO: Add test implementation" }, ]; const testCases = tests .map( (t) => ` it('${t.name}', async () => { ${t.code} });` ) .join("\n"); if (options.includeSetup !== false) { return `describe('${describeName}', () => { beforeAll(async () => { await device.launchApp(); }); beforeEach(async () => { await device.reloadReactNative(); }); ${testCases} }); `; } return `describe('${describeName}', () => { ${testCases} }); `; }
- src/tools/index.ts:429-442 (registration)The allTools array exports the generateTestTool (at index position line 438), registering it for use in the MCP tools system.export const allTools: Tool[] = [ buildTool, testTool, initTool, readConfigTool, listConfigurationsTool, validateConfigTool, createConfigTool, listDevicesTool, generateTestTool, generateMatcherTool, generateActionTool, generateExpectationTool, ];