UNPKG

@dhlab/e2e-autogen

Version:

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

91 lines (90 loc) 4.99 kB
var _DetoxTemplate_instances, _DetoxTemplate_scenariosPerPrefix, _DetoxTemplate_generateStubFile, _DetoxTemplate_template, _DetoxTemplate_stubCode, _DetoxTemplate_stepCode, _DetoxTemplate_sanitizeText; Object.defineProperty(exports, "__esModule", { value: true }); exports.DetoxTemplate = void 0; const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("node:path")); const fs = tslib_1.__importStar(require("fs-extra")); class DetoxTemplate { constructor(scenariosPerPrefix) { _DetoxTemplate_instances.add(this); _DetoxTemplate_scenariosPerPrefix.set(this, void 0); tslib_1.__classPrivateFieldSet(this, _DetoxTemplate_scenariosPerPrefix, scenariosPerPrefix, "f"); } async write(targetDir) { try { await fs.ensureDir(targetDir); await Promise.all(Array.from(tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_scenariosPerPrefix, "f").entries()).map(([prefix, scenarios]) => tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_generateStubFile).call(this, prefix, scenarios, targetDir))); } catch (error) { throw new Error(`❌ Detox 스텁 코드 file write 실패: ${error}`); } } } exports.DetoxTemplate = DetoxTemplate; _DetoxTemplate_scenariosPerPrefix = new WeakMap(), _DetoxTemplate_instances = new WeakSet(), _DetoxTemplate_generateStubFile = async function _DetoxTemplate_generateStubFile(prefix, scenarios, targetDir) { const fileName = `${prefix}.stub.ts`; const filePath = path.join(targetDir, fileName); const template = tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_template).call(this, scenarios); await fs.writeFile(filePath, template, "utf-8"); console.log(`✅ 생성됨: ${filePath} (${scenarios.length}개 시나리오)`); }, _DetoxTemplate_template = function _DetoxTemplate_template(scenarios) { const scenarioIds = scenarios.map((s) => s.scenarioId).join(", "); const stubCodes = scenarios .map((scenario) => tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_stubCode).call(this, scenario)) .join("\n\n"); return [ "// 📝 Auto-generated by E2E-Autogen", `// 🔧 Generated from: ${scenarioIds}`, "", "// Detox step utility for sequential test execution", "const step = {", " skip: (title: string, fn: () => Promise<void>) => {", " // Skip step implementation - can be enabled later", " console.log(`⏭️ Skipping: ${title}`);", " },", " test: async (title: string, fn: () => Promise<void>) => {", " console.log(`🎬 Step: ${title}`);", " await fn();", " }", "};", "", `describe("${scenarios[0]?.scenarioId || "E2E Test"}", () => {`, " beforeEach(async () => {", " await device.launchApp({ newInstance: true });", " });", "", stubCodes, "});", ].join("\n"); }, _DetoxTemplate_stubCode = function _DetoxTemplate_stubCode(scenario) { const title = tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_sanitizeText).call(this, `[${scenario.scenarioId}] ${scenario.scenarioDescription}`, true); const steps = scenario.steps .map((step) => tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_stepCode).call(this, step)) .join("\n\n"); return [` it.skip("${title}", async () => {`, steps, " });"].join("\n"); }, _DetoxTemplate_stepCode = function _DetoxTemplate_stepCode(step) { const hasUiPath = step.uiPath.trim().length > 0; const hasWhen = step.action.trim().length > 0; const stepTitle = tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_sanitizeText).call(this, hasWhen ? `[${step.testId}] ${step.action} -> ${step.expected}` : `[${step.testId}] ${step.expected}`, true); const uiPathSection = hasUiPath ? `// 📍 UI Path: ${step.uiPath}\n` : ""; const whenSection = hasWhen ? `// 🎬 When: ${tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_sanitizeText).call(this, step.action)}\n` : ""; const thenSection = `// ✅ Then: ${tslib_1.__classPrivateFieldGet(this, _DetoxTemplate_instances, "m", _DetoxTemplate_sanitizeText).call(this, step.expected)}\n`; return ` await step.test("${stepTitle}", async () => { ${uiPathSection} ${whenSection} ${thenSection} });`; }, _DetoxTemplate_sanitizeText = function _DetoxTemplate_sanitizeText(text, escapeQuotes = false) { let result = text .replace(/\n/g, " ") // 개행 문자 제거 .replace(/\s+/g, " ") // 연속된 공백 정리 .trim(); if (escapeQuotes) { result = result.replace(/"/g, '\\"'); // 쌍따옴표 이스케이프 } return result; };