UNPKG

ctrlshiftleft

Version:

AI-powered toolkit for embedding QA and security testing into development workflows

47 lines (40 loc) 1.87 kB
import { Command } from 'commander'; import chalk from 'chalk'; import ora from 'ora'; import path from 'path'; import { TestGenerator } from '../core/testGenerator'; import { isValidSourcePath } from '../utils/fileUtils'; export function genCommand(program: Command): void { program .command('gen') .description('Generate end-to-end tests from source code') .argument('<source>', 'Source file or directory to analyze') .option('-o, --output <directory>', 'Output directory for generated tests', './tests') .option('-f, --format <format>', 'Test format (playwright or selenium)', 'playwright') .option('-t, --timeout <timeout>', 'Timeout for test generation in seconds', '60') .action(async (source: string, options) => { const spinner = ora('Analyzing source code...').start(); try { // Validate source path if (!await isValidSourcePath(source)) { spinner.fail(`Invalid source path: ${source}`); return; } const absoluteSourcePath = path.resolve(process.cwd(), source); const outputDir = path.resolve(process.cwd(), options.output); // Initialize test generator const generator = new TestGenerator({ format: options.format, timeout: parseInt(options.timeout, 10) }); spinner.text = 'Generating tests...'; const result = await generator.generateTests(absoluteSourcePath, outputDir); spinner.succeed(`Successfully generated ${result.testCount} tests in ${outputDir}`); console.log(`\n${chalk.green('✓')} Generated test files: ${result.files.join(', ')}`); } catch (error) { spinner.fail(`Test generation failed: ${(error as Error).message}`); console.error(chalk.red((error as Error).stack)); process.exit(1); } }); }