UNPKG

@dhlab/e2e-autogen

Version:

Google 스프레드시트 기반 시나리오를 Playwright 테스트 스텁 코드로 자동 생성하고, 테스트 실행 결과를 다시 시트에 업데이트하는 CLI 도구

77 lines (75 loc) 4.58 kB
'use strict'; var _PlaywrightTemplate_instances, _PlaywrightTemplate_scenariosPerPrefix, _PlaywrightTemplate_generateStubFile, _PlaywrightTemplate_template, _PlaywrightTemplate_stubCode, _PlaywrightTemplate_stepCode, _PlaywrightTemplate_sanitizeText; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightTemplate = void 0; const tslib_1 = require("tslib"); const fs = tslib_1.__importStar(require("fs-extra")); const path = tslib_1.__importStar(require("path")); class PlaywrightTemplate { constructor(scenariosPerPrefix) { _PlaywrightTemplate_instances.add(this); _PlaywrightTemplate_scenariosPerPrefix.set(this, void 0); tslib_1.__classPrivateFieldSet(this, _PlaywrightTemplate_scenariosPerPrefix, scenariosPerPrefix, "f"); } async write(targetDir) { try { await fs.ensureDir(targetDir); await Promise.all(Array.from(tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_scenariosPerPrefix, "f").entries()).map(([prefix, scenarios]) => tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_generateStubFile).call(this, prefix, scenarios, targetDir))); } catch (error) { throw new Error(`❌ Playwright 스텁 코드 file write 실패: ${error}`); } } } exports.PlaywrightTemplate = PlaywrightTemplate; _PlaywrightTemplate_scenariosPerPrefix = new WeakMap(), _PlaywrightTemplate_instances = new WeakSet(), _PlaywrightTemplate_generateStubFile = async function _PlaywrightTemplate_generateStubFile(prefix, scenarios, targetDir) { const fileName = `${prefix}.stub.ts`; const filePath = path.join(targetDir, fileName); const template = tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_template).call(this, scenarios); await fs.writeFile(filePath, template, "utf-8"); console.log(`✅ 생성됨: ${filePath} (${scenarios.length}개 시나리오)`); }, _PlaywrightTemplate_template = function _PlaywrightTemplate_template(scenarios) { const scenarioIds = scenarios.map((s) => s.scenarioId).join(", "); const stubCodes = scenarios .map((scenario) => tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_stubCode).call(this, scenario)) .join("\n\n"); return [ "// 📝 Auto-generated by E2E-Autogen", `// 🔧 Generated from: ${scenarioIds}`, "", `import { test } from "@playwright/test";`, "", stubCodes, ].join("\n"); }, _PlaywrightTemplate_stubCode = function _PlaywrightTemplate_stubCode(scenario) { const title = tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_sanitizeText).call(this, `[${scenario.scenarioId}] ${scenario.scenarioDescription}`, true); const steps = scenario.steps .map((step) => tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_stepCode).call(this, step)) .join("\n\n"); return [`test.skip("${title}", async ({ page }) => {`, steps, "});"].join("\n"); }, _PlaywrightTemplate_stepCode = function _PlaywrightTemplate_stepCode(step) { const hasUiPath = step.uiPath.trim().length > 0; const hasWhen = step.when.trim().length > 0; const stepTitle = tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_sanitizeText).call(this, hasWhen ? `[${step.testId}] ${step.when} -> ${step.then}` : `[${step.testId}] ${step.then}`, true); const uiPathSection = hasUiPath ? `// 📍 UI Path: ${step.uiPath}\n` : ""; const whenSection = hasWhen ? `// 🎬 When: ${tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_sanitizeText).call(this, step.when)}\n` : ""; const thenSection = `// ✅ Then: ${tslib_1.__classPrivateFieldGet(this, _PlaywrightTemplate_instances, "m", _PlaywrightTemplate_sanitizeText).call(this, step.then)}\n`; return ` await test.step.skip("${stepTitle}", async () => { ${uiPathSection} ${whenSection} ${thenSection} });`; }, _PlaywrightTemplate_sanitizeText = function _PlaywrightTemplate_sanitizeText(text, escapeQuotes = false) { let result = text .replace(/\n/g, " ") // 개행 문자 제거 .replace(/\s+/g, " ") // 연속된 공백 정리 .trim(); if (escapeQuotes) { result = result.replace(/"/g, '\\"'); // 쌍따옴표 이스케이프 } return result; };