UNPKG

@dhlab/e2e-autogen

Version:

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

121 lines (119 loc) 6.71 kB
'use strict'; var _GoogleSpreadsheets_instances, _GoogleSpreadsheets_sheetsUrl, _GoogleSpreadsheets_v4sheets, _GoogleSpreadsheets_cachedSheets, _GoogleSpreadsheets_googleSheetColumns, _GoogleSpreadsheets_rawSheets, _GoogleSpreadsheets_invalidateCache; Object.defineProperty(exports, "__esModule", { value: true }); exports.authorizedGoogleSpreadsheets = authorizedGoogleSpreadsheets; const tslib_1 = require("tslib"); const sheets_1 = require("@googleapis/sheets"); const coverage_sheet_1 = require("./coverage-sheet"); const spreadsheet_sheet_1 = require("./spreadsheet-sheet"); const test_suite_sheet_1 = require("./test-suite-sheet"); async function authorizedGoogleSpreadsheets(sheetsUrl, credentialsFile, googleSheetColumns) { try { const authClient = new sheets_1.auth.GoogleAuth({ keyFile: credentialsFile, scopes: ["https://www.googleapis.com/auth/spreadsheets"], }); const v4sheets = new sheets_1.sheets_v4.Sheets({ auth: authClient, }); return new GoogleSpreadsheets(sheetsUrl, v4sheets, googleSheetColumns); } catch (error) { throw new Error(`Google Sheets 인증 실패: ${error}`); } } class GoogleSpreadsheets { constructor(sheetsUrl, v4sheets, googleSheetColumns) { _GoogleSpreadsheets_instances.add(this); _GoogleSpreadsheets_sheetsUrl.set(this, void 0); _GoogleSpreadsheets_v4sheets.set(this, void 0); _GoogleSpreadsheets_cachedSheets.set(this, null); _GoogleSpreadsheets_googleSheetColumns.set(this, void 0); tslib_1.__classPrivateFieldSet(this, _GoogleSpreadsheets_sheetsUrl, sheetsUrl, "f"); tslib_1.__classPrivateFieldSet(this, _GoogleSpreadsheets_v4sheets, v4sheets, "f"); tslib_1.__classPrivateFieldSet(this, _GoogleSpreadsheets_googleSheetColumns, googleSheetColumns, "f"); } get id() { const match = tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_sheetsUrl, "f").match(/\/spreadsheets\/d\/([a-zA-Z0-9-_]+)/); if (!match) { throw new Error("유효하지 않은 Google Sheets URL입니다."); } return match[1]; } get fullUrl() { return tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_sheetsUrl, "f"); } async suitesMeta() { const rawSheets = await tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_instances, "m", _GoogleSpreadsheets_rawSheets).call(this); const suitesMeta = new Map(); for (const sheet of rawSheets) { const title = sheet.properties?.title ?? ""; const match = title.match(/^\s*\[(TC-\d+)]/i); if (match) { const prefix = match[1]; // e.g., TC-4 suitesMeta.set(prefix, { gid: String(sheet.properties?.sheetId), title, }); } } return suitesMeta; } sheet(gid) { return new spreadsheet_sheet_1.SpreadsheetSheet(this.id, gid, tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_v4sheets, "f"), () => tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_instances, "m", _GoogleSpreadsheets_rawSheets).call(this)); } testSuiteSheet(gid) { return new test_suite_sheet_1.TestSuiteSheet(this.id, gid, tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_v4sheets, "f"), tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_googleSheetColumns, "f"), () => tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_instances, "m", _GoogleSpreadsheets_rawSheets).call(this)); } async coverageSheet() { const rawSheets = await tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_instances, "m", _GoogleSpreadsheets_rawSheets).call(this); const sheetTitle = "[COVERAGE]"; const existingSheet = rawSheets.find((sheet) => sheet.properties?.title === sheetTitle); let gid = existingSheet?.properties?.sheetId ? String(existingSheet.properties.sheetId) : undefined; if (!gid) { const response = await tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_v4sheets, "f").spreadsheets.batchUpdate({ spreadsheetId: this.id, requestBody: { requests: [ { addSheet: { properties: { title: sheetTitle, index: 0, // 첫 번째 시트에 삽입 }, }, }, ], }, }); const newSheetProperties = response.data.replies?.[0]?.addSheet?.properties; if (newSheetProperties?.sheetId != null) { gid = String(newSheetProperties.sheetId); tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_instances, "m", _GoogleSpreadsheets_invalidateCache).call(this); } } if (!gid) { throw new Error("`[COVERAGE]` 시트를 찾거나 생성하는 데 실패했습니다."); } return new coverage_sheet_1.CoverageSheet(this.id, gid, tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_v4sheets, "f"), () => tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_instances, "m", _GoogleSpreadsheets_rawSheets).call(this)); } } _GoogleSpreadsheets_sheetsUrl = new WeakMap(), _GoogleSpreadsheets_v4sheets = new WeakMap(), _GoogleSpreadsheets_cachedSheets = new WeakMap(), _GoogleSpreadsheets_googleSheetColumns = new WeakMap(), _GoogleSpreadsheets_instances = new WeakSet(), _GoogleSpreadsheets_rawSheets = /** * 시트 정보를 캐싱하여 반복적인 API 호출을 방지합니다. * 첫 번째 호출 시에만 API를 요청하고, 이후에는 캐시된 데이터를 반환합니다. */ async function _GoogleSpreadsheets_rawSheets() { if (tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_cachedSheets, "f")) { return tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_cachedSheets, "f"); } const response = await tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_v4sheets, "f").spreadsheets.get({ spreadsheetId: this.id, }); tslib_1.__classPrivateFieldSet(this, _GoogleSpreadsheets_cachedSheets, response.data.sheets ?? [], "f"); return tslib_1.__classPrivateFieldGet(this, _GoogleSpreadsheets_cachedSheets, "f"); }, _GoogleSpreadsheets_invalidateCache = function _GoogleSpreadsheets_invalidateCache() { tslib_1.__classPrivateFieldSet(this, _GoogleSpreadsheets_cachedSheets, null, "f"); };