UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

132 lines (129 loc) 4.55 kB
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import { timeStampFormat } from '../time/time.mjs'; import { parseRobotMessage, genRobotMessage } from '../wecom-robot/message.mjs'; import { EMOJI_MAP } from './config.mjs'; var TRIGGER_MAP = { MANUAL: '手动', TIME_TRIGGER: '定时', WEB_HOOK: 'WebHook', SERVICE: '内部服务', PIPELINE: '子流水线', REMOTE: '远程' }; function getStartTypeDesc(data) { var bkStartType = data.bkStartType; var content = ''; if (bkStartType && TRIGGER_MAP[bkStartType]) { content = TRIGGER_MAP[bkStartType]; } else if (bkStartType) { content = bkStartType; } if (content) { return [{ content: content, label: '触发方式' }]; } return []; } function getFailedTestUnits(_ref) { var passes = _ref.passes, tests = _ref.tests, testList = _ref.testList; if (passes == tests) return {}; if (!(testList === null || testList === void 0 ? void 0 : testList.length)) return {}; var failedTests = testList.filter(function (item) { return !!item.fail; }); var failTestTitles = failedTests.map(function (item) { return item.title; }); if (!(failTestTitles === null || failTestTitles === void 0 ? void 0 : failTestTitles.length)) return {}; return { errorTitle: "\u5931\u8D25\uFF1A".concat(failTestTitles.join('、')), errorDetail: getFailedDetail(failedTests) }; } function getFailedDetail(failedTests) { return failedTests.map(function (item) { var errMsg = (item.err.estack || '').replace(/[\n]+/g, '; '); return "".concat(item.title, ": ").concat(errMsg); }).filter(function (item) { return item; }); } function getE2ETestRobotMessage(data) { var notificationList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var start = data.start, duration = data.duration, passes = data.passes, tests = data.tests, _data$projectLink = data.projectLink, projectLink = _data$projectLink === void 0 ? '' : _data$projectLink, _data$checkUrl = data.checkUrl, checkUrl = _data$checkUrl === void 0 ? '' : _data$checkUrl, _data$name = data.name, name = _data$name === void 0 ? '' : _data$name, _data$comment = data.comment, comment = _data$comment === void 0 ? '' : _data$comment, _data$fileList = data.fileList, fileList = _data$fileList === void 0 ? [] : _data$fileList; var hasFailed = passes !== tests; var time = timeStampFormat(new Date(start).getTime(), 'MM-dd hh:mm:ss'); var title = ">".concat(hasFailed ? EMOJI_MAP.FAIL : EMOJI_MAP.PASS, "\u3010\u81EA\u52A8\u5316\u6D4B\u8BD5\u3011"); var errorDetailList = []; var messageList = [["".concat(title).concat(parseRobotMessage({ content: "".concat(name, "-").concat(comment), link: projectLink })), { content: "".concat(passes, "/").concat(tests), label: '成功/全部' }, { content: "".concat(Math.ceil(duration / 1000), "s"), label: '耗时' }].concat(_toConsumableArray(getStartTypeDesc(data)), [{ content: time, link: checkUrl }])]; if (hasFailed) { var _messageList$; (_messageList$ = messageList[0]).push.apply(_messageList$, _toConsumableArray(notificationList.map(function (item) { return "<@".concat(item, ">"); }))); } var fileMessageList = (fileList || []).filter(function (fileInfo) { var tests = fileInfo.tests, passes = fileInfo.passes; return tests !== passes; }).map(function (fileInfo) { var _a; var file = fileInfo.file, tests = fileInfo.tests, passes = fileInfo.passes, link = fileInfo.link, testList = fileInfo.testList; var fileName = parseRobotMessage({ content: file, link: link }); var failedInfo = getFailedTestUnits({ testList: testList, passes: passes, tests: tests }); if ((_a = failedInfo.errorDetail) === null || _a === void 0 ? void 0 : _a.length) { errorDetailList.push(['\n']); errorDetailList.push(failedInfo.errorDetail); } return ["- ".concat(fileName), "".concat(passes, "/").concat(tests), (failedInfo === null || failedInfo === void 0 ? void 0 : failedInfo.errorTitle) || '']; }); messageList.push.apply(messageList, _toConsumableArray(fileMessageList)); messageList.push.apply(messageList, ['\n', '\n']); messageList.push.apply(messageList, errorDetailList); return { message: genRobotMessage(messageList), start: start, hasFailed: hasFailed }; } export { TRIGGER_MAP, getE2ETestRobotMessage };