UNPKG

@qualitywatcher/codeceptjs-reporter

Version:
94 lines (91 loc) 3.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.humanizeStep = exports.getSuiteAndCaseIds = exports.createTestData = exports.checkForEnvironmentalVariables = exports.getBrowserInfo = exports.msToTime = exports.logger = void 0; const fast_safe_stringify_1 = __importDefault(require("fast-safe-stringify")); const REGEX_SUITE_AND_TEST_ID = /\bS(\d+)C(\d+)\b/g; const logger = (message) => { let messageOut = message instanceof Object ? (0, fast_safe_stringify_1.default)(message, null, 2) : message; console.log(` ${messageOut}`); }; exports.logger = logger; const msToTime = (ms) => { let seconds = Number((ms / 1000).toFixed(1)); let minutes = Number((ms / (1000 * 60)).toFixed(1)); let hours = Number((ms / (1000 * 60 * 60)).toFixed(1)); let days = (ms / (1000 * 60 * 60 * 24)).toFixed(1); if (seconds < 60) return seconds + "s"; else if (minutes < 60) return minutes + "m"; else if (hours < 24) return hours + "h"; else return days + "d"; }; exports.msToTime = msToTime; const getBrowserInfo = (testResults) => { const { browserName, browserVersion, osName, osVersion, cypressVersion } = testResults; return ` **Browser Info:** ----- > ${browserName}(${browserVersion}) on ${osName}(${osVersion}) > Cypress: ${cypressVersion}`; }; exports.getBrowserInfo = getBrowserInfo; const checkForEnvironmentalVariables = () => { const missingEnvVars = []; if (!process.env.QUALITYWATCHER_API_KEY) { missingEnvVars.push("QUALITYWATCHER_API_KEY"); } if ((missingEnvVars === null || missingEnvVars === void 0 ? void 0 : missingEnvVars.length) > 0) { const errorMessage = `Missing environmental variable/s: ${missingEnvVars.join(", ")}`; (0, exports.logger)(errorMessage); throw new Error(errorMessage); } }; exports.checkForEnvironmentalVariables = checkForEnvironmentalVariables; const createTestData = (testResult) => { const testData = { case: (testResult === null || testResult === void 0 ? void 0 : testResult.case) ? testResult.case : undefined, suite_id: testResult.suiteId ? testResult.suiteId : undefined, test_id: testResult.testId ? testResult.testId : undefined, status: testResult.status, time: testResult.duration, comment: testResult.error, }; return testData; }; exports.createTestData = createTestData; const getSuiteAndCaseIds = (title) => { let suiteAndCaseIds; let suiteId; let caseId; while ((suiteAndCaseIds = REGEX_SUITE_AND_TEST_ID.exec(title)) != null) { suiteId = suiteAndCaseIds[1]; caseId = suiteAndCaseIds[2]; } return { suite_id: Number(suiteId), test_id: Number(caseId), }; }; exports.getSuiteAndCaseIds = getSuiteAndCaseIds; const humanizeStep = (steps) => { const humanizedSteps = steps.map((step) => { var _a; let humanizedStep = `${step.prefix} ${step.actor} ${camelToTitle(step.name)} `; if (((_a = step.args) === null || _a === void 0 ? void 0 : _a.length) > 0) { humanizedStep += `"${step.args.join(", ")}"`; } return humanizedStep; }); return humanizedSteps.join('\n'); }; exports.humanizeStep = humanizeStep; const camelToTitle = (camelCase) => camelCase .replace(/([A-Z])/g, (match) => ` ${match.toLowerCase()}`) .replace(/^./, (match) => match.toLowerCase()) .trim();