Skip to main content
Glama

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
NameRequiredDescriptionDefault
descriptionYesNatural language description of the test scenario
testNameYesName for the test/describe block
outputPathNoWhere to write the generated test file
includeSetupNo
platformNocross-platform

Implementation Reference

  • 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, }; }, };
  • 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>;
  • 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} }); `; }
  • 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, ];

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/gayancliyanage/detox-mcp'

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