UNPKG

agentic-qe

Version:

Agentic Quality Engineering Fleet System - AI-driven quality management platform

130 lines • 5.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWatchCommand = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const chokidar_1 = __importDefault(require("chokidar")); function createWatchCommand() { const command = new commander_1.Command('watch'); command .description('Watch mode for continuous testing on file changes') .option('-p, --pattern <pattern>', 'File pattern to watch', '**/*.{ts,tsx,js,jsx}') .option('--changed-only', 'Run only changed tests', false) .option('--related', 'Run tests related to changed files', false) .option('--no-interactive', 'Disable interactive mode', false) .action(async (options) => { console.log(chalk_1.default.bold('Watch Mode Started\n')); console.log(chalk_1.default.gray(`Pattern: ${options.pattern}`)); console.log(chalk_1.default.gray(`Changed only: ${options.changedOnly}`)); console.log(chalk_1.default.gray(`Related tests: ${options.related}`)); console.log(chalk_1.default.gray('Press Ctrl+C to exit\n')); const watcher = chokidar_1.default.watch(options.pattern, { ignored: /(^|[\/\\])\../, // ignore dotfiles persistent: true, ignoreInitial: true }); watcher .on('change', async (path) => { console.log(chalk_1.default.cyan(`\nšŸ“ File changed: ${path}`)); if (options.changedOnly) { await runChangedTests([path]); } else if (options.related) { await runRelatedTests([path]); } else { await runAllTests(); } }) .on('add', (path) => { console.log(chalk_1.default.green(`\nāž• File added: ${path}`)); }) .on('unlink', (path) => { console.log(chalk_1.default.red(`\nāž– File removed: ${path}`)); }); // Keep process alive process.on('SIGINT', () => { console.log(chalk_1.default.yellow('\n\nWatch mode stopped')); watcher.close(); process.exit(0); }); // Interactive commands if (!options.noInteractive) { setupInteractiveMode(watcher); } }); return command; } exports.createWatchCommand = createWatchCommand; async function runChangedTests(files) { console.log(chalk_1.default.bold('Running changed tests...\n')); for (const file of files) { const testFile = file.replace(/\.(ts|tsx|js|jsx)$/, '.test.$1'); console.log(chalk_1.default.cyan(`→ ${testFile}`)); // Mock test execution await new Promise(resolve => setTimeout(resolve, 500)); console.log(chalk_1.default.green(`āœ“ ${testFile} passed\n`)); } } async function runRelatedTests(files) { console.log(chalk_1.default.bold('Running related tests...\n')); for (const file of files) { // Find related test files const related = findRelatedTests(file); for (const testFile of related) { console.log(chalk_1.default.cyan(`→ ${testFile}`)); await new Promise(resolve => setTimeout(resolve, 500)); console.log(chalk_1.default.green(`āœ“ ${testFile} passed\n`)); } } } async function runAllTests() { console.log(chalk_1.default.bold('Running all tests...\n')); const tests = [ 'tests/unit/auth.test.ts', 'tests/unit/validation.test.ts', 'tests/integration/api.test.ts' ]; for (const test of tests) { console.log(chalk_1.default.cyan(`→ ${test}`)); await new Promise(resolve => setTimeout(resolve, 300)); console.log(chalk_1.default.green(`āœ“ ${test} passed\n`)); } } function findRelatedTests(file) { // Mock implementation - in real scenario, analyze imports const baseName = file.replace(/\.(ts|tsx|js|jsx)$/, ''); return [ `${baseName}.test.ts`, `tests/integration/${baseName.split('/').pop()}.test.ts` ]; } function setupInteractiveMode(watcher) { console.log(chalk_1.default.gray('\nInteractive Commands:')); console.log(chalk_1.default.gray(' a - Run all tests')); console.log(chalk_1.default.gray(' f - Run failed tests')); console.log(chalk_1.default.gray(' q - Quit\n')); process.stdin.setRawMode(true); process.stdin.resume(); process.stdin.on('data', async (key) => { const command = key.toString(); switch (command) { case 'a': await runAllTests(); break; case 'f': console.log(chalk_1.default.yellow('Running failed tests...')); break; case 'q': case '\u0003': // Ctrl+C console.log(chalk_1.default.yellow('\n\nWatch mode stopped')); watcher.close(); process.exit(0); break; } }); } //# sourceMappingURL=watch.js.map