export interface Prompt {
name: string;
description: string;
arguments?: Array<{
name: string;
description: string;
required?: boolean;
}>;
}
export interface PromptMessage {
role: "user" | "assistant";
content: {
type: "text";
text: string;
};
}
/**
* List all available prompts
*/
export function listPrompts(): Prompt[] {
return [
{
name: "detox-test",
description: "Run Detox tests with smart defaults and formatted results",
arguments: [
{
name: "configuration",
description: "Device configuration to use (e.g., ios.sim.debug)",
required: false,
},
{
name: "testFile",
description: "Specific test file to run",
required: false,
},
],
},
{
name: "detox-generate",
description: "Generate Detox test code from a natural language description",
arguments: [
{
name: "scenario",
description: "Description of the test scenario to generate",
required: true,
},
{
name: "outputFile",
description: "File path to write the generated test",
required: false,
},
],
},
{
name: "detox-setup",
description: "Initialize and configure Detox in a React Native project",
arguments: [
{
name: "projectPath",
description: "Path to the React Native project",
required: false,
},
{
name: "platforms",
description: "Platforms to configure (ios, android, or both)",
required: false,
},
],
},
{
name: "detox-debug",
description: "Debug a failing Detox test with screenshots and view hierarchy",
arguments: [
{
name: "testFile",
description: "Path to the failing test file",
required: true,
},
{
name: "testName",
description: "Specific test name to debug",
required: false,
},
],
},
];
}
/**
* Get prompt messages for a specific prompt
*/
export function getPrompt(
name: string,
args: Record<string, string>
): PromptMessage[] {
switch (name) {
case "detox-test":
return getTestPrompt(args);
case "detox-generate":
return getGeneratePrompt(args);
case "detox-setup":
return getSetupPrompt(args);
case "detox-debug":
return getDebugPrompt(args);
default:
throw new Error(`Unknown prompt: ${name}`);
}
}
function getTestPrompt(args: Record<string, string>): PromptMessage[] {
const config = args.configuration || "auto-detect";
const testFile = args.testFile || "all tests";
return [
{
role: "user",
content: {
type: "text",
text: `Run Detox tests with the following settings:
- Configuration: ${config}
- Test file: ${testFile}
Please:
1. First check if the app needs to be built (use detox_build if necessary)
2. Run the tests with appropriate settings (use detox_test)
3. Provide a summary of the test results
4. If there are failures, analyze them and suggest fixes
Use the available Detox MCP tools to complete this task.`,
},
},
];
}
function getGeneratePrompt(args: Record<string, string>): PromptMessage[] {
const scenario = args.scenario || "a basic test";
const outputFile = args.outputFile ? `Save it to: ${args.outputFile}` : "Display the generated code";
return [
{
role: "user",
content: {
type: "text",
text: `Generate a Detox E2E test for the following scenario:
"${scenario}"
Requirements:
1. Use proper Detox matchers (by.id, by.text, etc.)
2. Include appropriate waitFor statements for async operations
3. Add meaningful assertions
4. Follow Detox best practices
5. ${outputFile}
Use the detox_generate_test, detox_generate_matcher, detox_generate_action, and detox_generate_expectation tools as needed.`,
},
},
];
}
function getSetupPrompt(args: Record<string, string>): PromptMessage[] {
const projectPath = args.projectPath || "current directory";
const platforms = args.platforms || "both iOS and Android";
return [
{
role: "user",
content: {
type: "text",
text: `Set up Detox in my React Native project:
- Project path: ${projectPath}
- Platforms: ${platforms}
Please:
1. Initialize Detox in the project (use detox_init)
2. Create appropriate configuration for the specified platforms (use detox_create_config)
3. Validate the configuration (use detox_validate_config)
4. List available devices (use detox_list_devices)
5. Provide next steps for running the first test
Use the available Detox MCP tools to complete the setup.`,
},
},
];
}
function getDebugPrompt(args: Record<string, string>): PromptMessage[] {
const testFile = args.testFile || "the test file";
const testName = args.testName ? `Specific test: ${args.testName}` : "Run all tests in the file";
return [
{
role: "user",
content: {
type: "text",
text: `Debug a failing Detox test:
- Test file: ${testFile}
- ${testName}
Please:
1. Read the test file to understand the test structure
2. Run the test with verbose logging and screenshots on failure
3. Analyze the failure output
4. Check the view hierarchy if needed
5. Suggest fixes for the failing test
Use the available Detox MCP tools with --take-screenshots failing and --record-logs all options.`,
},
},
];
}