#!/usr/bin/env node // parse_testcases.js — парсит markdown тест-кейсы в JSON const fs = require('fs'); const path = require('path'); const filePath = process.argv[2]; if (!filePath) { console.error('Usage: node parse_testcases.js '); process.exit(1); } const content = fs.readFileSync(path.resolve(filePath), 'utf8'); function parseTestCases(md) { const tests = []; // Split by ### headers const sections = md.split(/^### /m).slice(1); for (const section of sections) { const lines = section.split('\n'); // Parse header: TC-XX — Name const headerMatch = lines[0].match(/^(TC-[\w-]+)\s*[—–-]\s*(.+)/); if (!headerMatch) continue; const id = headerMatch[1]; const name = headerMatch[2].trim(); const body = lines.slice(1).join('\n'); // Parse type const typeMatch = body.match(/\*\*Тип:\*\*\s*(.+)/); if (!typeMatch) continue; const type = typeMatch[1].trim().toLowerCase(); // Only process UI tests if (type !== 'ui') continue; // Parse viewport const viewportMatch = body.match(/\*\*Viewport:\*\*\s*(.+)/); const viewport = viewportMatch ? viewportMatch[1].trim().toLowerCase() : 'desktop'; // Parse URL const urlMatch = body.match(/\*\*URL:\*\*\s*(.+)/); const url = urlMatch ? urlMatch[1].trim() : ''; // Parse steps const steps = []; const stepsMatch = body.match(/\*\*Шаги:\*\*\s*\n([\s\S]*?)(?=\n\*\*|$)/); if (stepsMatch) { const stepLines = stepsMatch[1].split('\n').filter(l => l.match(/^\d+\.\s/)); for (const stepLine of stepLines) { const stepMatch = stepLine.match(/^\d+\.\s*([\w-]+):\s*(.+)/); if (stepMatch) { let action = stepMatch[1].trim(); let value = stepMatch[2].trim(); // Remove surrounding quotes value = value.replace(/^["']|["']$/g, ''); // Convert wait value to number if (action === 'wait') { value = parseInt(value, 10); } steps.push({ action, value }); } } } // Parse visual criteria const criteria = []; const criteriaMatch = body.match(/\*\*Визуальные критерии:\*\*\s*\n([\s\S]*?)(?=\n---|\n###|$)/); if (criteriaMatch) { const criteriaLines = criteriaMatch[1].split('\n').filter(l => l.match(/^[-*]\s/)); for (const cl of criteriaLines) { criteria.push(cl.replace(/^[-*]\s+/, '').trim()); } } tests.push({ id, name, type, viewport, url, steps, criteria }); } return tests; } const result = parseTestCases(content); console.log(JSON.stringify(result, null, 2));