t-comm
Version:
专业、稳定、纯粹的工具库
139 lines (134 loc) • 4.49 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_es6 = require('../tslib.es6-01322ba9.js');
var time_time = require('../time/time.js');
var wecomRobot_message = require('../wecom-robot/message.js');
var e2eTest_config = require('./config.js');
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(_a) {
var passes = _a.passes,
tests = _a.tests,
testList = _a.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, notificationList) {
var _a;
if (notificationList === void 0) {
notificationList = [];
}
var start = data.start,
duration = data.duration,
passes = data.passes,
tests = data.tests,
_b = data.projectLink,
projectLink = _b === void 0 ? '' : _b,
_c = data.checkUrl,
checkUrl = _c === void 0 ? '' : _c,
_d = data.name,
name = _d === void 0 ? '' : _d,
_e = data.comment,
comment = _e === void 0 ? '' : _e,
_f = data.fileList,
fileList = _f === void 0 ? [] : _f;
var hasFailed = passes !== tests;
var time = time_time.timeStampFormat(new Date(start).getTime(), 'MM-dd hh:mm:ss');
var title = ">".concat(hasFailed ? e2eTest_config.EMOJI_MAP.FAIL : e2eTest_config.EMOJI_MAP.PASS, "\u3010\u81EA\u52A8\u5316\u6D4B\u8BD5\u3011");
var errorDetailList = [];
var messageList = [tslib_es6.__spreadArray(tslib_es6.__spreadArray(["".concat(title).concat(wecomRobot_message.parseRobotMessage({
content: "".concat(name, "-").concat(comment),
link: projectLink
})), {
content: "".concat(passes, "/").concat(tests),
label: '成功/全部'
}, {
content: "".concat(Math.ceil(duration / 1000), "s"),
label: '耗时'
}], getStartTypeDesc(data), true), [{
content: time,
link: checkUrl
}], false)];
if (hasFailed) {
(_a = messageList[0]).push.apply(_a, 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 = wecomRobot_message.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, fileMessageList);
messageList.push.apply(messageList, ['\n', '\n']);
messageList.push.apply(messageList, errorDetailList);
return {
message: wecomRobot_message.genRobotMessage(messageList),
start: start,
hasFailed: hasFailed
};
}
exports.TRIGGER_MAP = TRIGGER_MAP;
exports.getE2ETestRobotMessage = getE2ETestRobotMessage;