@dhlab/e2e-autogen
Version:
Google 스프레드시트 기반 시나리오를 Playwright 테스트 스텁 코드로 자동 생성하고, 테스트 실행 결과를 다시 시트에 업데이트하는 CLI 도구
135 lines (130 loc) • 6.56 kB
JavaScript
'use strict';
var _InitCommand_instances, _InitCommand_configPath, _InitCommand_fileExists, _InitCommand_createConfigFile, _InitCommand_userInputCollection, _InitCommand_getConfigTemplate, _InitCommand_ensureString, _InitCommand_showSuccessMessage;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InitCommand = void 0;
const tslib_1 = require("tslib");
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const prompts = tslib_1.__importStar(require("@clack/prompts"));
const base_command_1 = require("./base-command");
/**
* e2e-autogen.config.ts 설정 파일을 생성하는 명령어를 수행한다.
*/
class InitCommand extends base_command_1.BaseCommand {
constructor(configPath = "e2e-autogen.config.ts") {
super();
_InitCommand_instances.add(this);
_InitCommand_configPath.set(this, void 0);
tslib_1.__classPrivateFieldSet(this, _InitCommand_configPath, (0, node_path_1.resolve)(configPath), "f");
}
async execute() {
if (tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_fileExists).call(this)) {
throw new Error(`설정 파일이 이미 존재합니다: ${tslib_1.__classPrivateFieldGet(this, _InitCommand_configPath, "f")}`);
}
const config = await tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_userInputCollection).call(this);
await tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_createConfigFile).call(this, config);
tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_showSuccessMessage).call(this);
}
}
exports.InitCommand = InitCommand;
_InitCommand_configPath = new WeakMap(), _InitCommand_instances = new WeakSet(), _InitCommand_fileExists = function _InitCommand_fileExists() {
return (0, node_fs_1.existsSync)(tslib_1.__classPrivateFieldGet(this, _InitCommand_configPath, "f"));
}, _InitCommand_createConfigFile = async function _InitCommand_createConfigFile(config) {
const configTemplate = tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_getConfigTemplate).call(this, config);
(0, node_fs_1.writeFileSync)(tslib_1.__classPrivateFieldGet(this, _InitCommand_configPath, "f"), configTemplate, "utf-8");
}, _InitCommand_userInputCollection = async function _InitCommand_userInputCollection() {
prompts.intro("🚀 e2e-autogen 설정을 시작합니다!");
const cancel = () => {
prompts.cancel("설정이 취소되었습니다.");
process.exit(0);
};
const sheetsUrl = await prompts.text({
message: "📊 Google Sheets URL을 입력하세요:",
validate: (value) => {
if (!value || value.length === 0) {
return "URL을 입력해주세요";
}
return undefined;
},
});
if (prompts.isCancel(sheetsUrl))
cancel();
const framework = await prompts.select({
message: "🧪 테스트 프레임워크를 선택하세요:",
options: [
{ label: "Playwright", value: "playwright" },
{ label: "Detox", value: "detox" },
],
});
if (prompts.isCancel(framework))
cancel();
const stubOutputFolder = await prompts.text({
message: "📁 스텁 파일 출력 폴더:",
defaultValue: "./playwright/__generated-stub__",
placeholder: "./playwright/__generated-stub__",
});
if (prompts.isCancel(stubOutputFolder))
cancel();
const jsonReporterFile = await prompts.text({
message: "📄 테스트 결과 JSON 파일 경로:",
defaultValue: "./playwright/e2e-autogen-reporter.json",
placeholder: "./playwright/e2e-autogen-reporter.json",
});
if (prompts.isCancel(jsonReporterFile))
cancel();
const credentialsFile = await prompts.text({
message: "🔐 Google API 인증 파일 경로:",
defaultValue: "./playwright/.auth/credentials.json",
placeholder: "./playwright/.auth/credentials.json",
});
if (prompts.isCancel(credentialsFile))
cancel();
// URL에서 줄바꿈과 공백 제거
const cleanSheetsUrl = tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_ensureString).call(this, sheetsUrl)
.replace(/\s+/g, "")
.trim();
return {
sheetsUrl: cleanSheetsUrl,
framework: tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_ensureString).call(this, framework),
stubOutputFolder: tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_ensureString).call(this, stubOutputFolder) ||
"./playwright/__generated-stub__",
jsonReporterFile: tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_ensureString).call(this, jsonReporterFile) ||
"./playwright/e2e-autogen-reporter.json",
credentialsFile: tslib_1.__classPrivateFieldGet(this, _InitCommand_instances, "m", _InitCommand_ensureString).call(this, credentialsFile) ||
"./playwright/.auth/credentials.json",
};
}, _InitCommand_getConfigTemplate = function _InitCommand_getConfigTemplate(config) {
return `import { defineConfig } from "@dhlab/e2e-autogen";
export default defineConfig({
sheetsUrl: "${config.sheetsUrl}",
framework: "${config.framework}",
stubOutputFolder: "${config.stubOutputFolder}",
jsonReporterFile: "${config.jsonReporterFile}",
credentialsFile: "${config.credentialsFile}",
googleSheetColumns: {
scenarioId: "A",
scenarioDescription: "B",
uiPath: "C",
action: "D",
expected: "E",
testId: "F",
tag: "G",
comment: "H"
}
});
`;
}, _InitCommand_ensureString = function _InitCommand_ensureString(value) {
if (typeof value === "string") {
return value;
}
throw new Error("Expected string value but got symbol");
}, _InitCommand_showSuccessMessage = function _InitCommand_showSuccessMessage() {
prompts.outro(`
✅ e2e-autogen.config.ts 파일이 성공적으로 생성되었습니다!
📋 다음 단계:
1. credentials.json 파일을 생성하고 Google API 인증 정보를 설정하세요
2. Google Sheets의 컬럼 구조가 기본값과 다르다면 설정 파일에서 googleSheetColumns를 수정하세요
3. 'e2e-autogen generate' 명령어로 테스트 스텁을 생성하세요
📚 자세한 설정 방법: https://github.com/dhlab-org/e2e-autogen
`);
};