t-comm
Version:
专业、稳定、纯粹的工具库
79 lines (75 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function getProjectName(path) {
var reg = /e2e\/([^/]+)/;
var match = path.match(reg);
return (match === null || match === void 0 ? void 0 : match[1]) || '';
}
function getModuleName(fileName) {
var reg = /([^/]+)\.cy\.(js|ts)/;
var match = fileName.match(reg);
return (match === null || match === void 0 ? void 0 : match[1]) || '';
}
function parseMochaAwesomeResult(report) {
var results = report.results;
var map = {};
for (var _i = 0, results_1 = results; _i < results_1.length; _i++) {
var result = results_1[_i];
var suites = result.suites,
file = result.file;
var project = getProjectName(file);
var moduleName = getModuleName(file);
if (!map[project]) {
map[project] = {
duration: 0,
passes: 0,
failures: 0,
pending: 0,
tests: 0,
files: {}
};
}
if (!map[project].files[moduleName]) {
map[project].files[moduleName] = {
duration: 0,
passes: 0,
failures: 0,
pending: 0,
tests: 0,
testList: []
};
}
for (var _a = 0, suites_1 = suites; _a < suites_1.length; _a++) {
var suit = suites_1[_a];
var tests = suit.tests;
for (var _b = 0, tests_1 = tests; _b < tests_1.length; _b++) {
var test_1 = tests_1[_b];
map[project].duration += test_1.duration;
map[project].passes += +test_1.pass;
map[project].failures += +test_1.fail;
map[project].pending += +test_1.pending;
map[project].files[moduleName].duration += test_1.duration;
map[project].files[moduleName].passes += +test_1.pass;
map[project].files[moduleName].failures += +test_1.fail;
map[project].files[moduleName].pending += +test_1.pending;
map[project].files[moduleName].testList.push(test_1);
}
}
}
Object.keys(map).forEach(function (project) {
var _a = map[project],
passes = _a.passes,
failures = _a.failures,
pending = _a.pending;
map[project].tests = passes + failures + pending;
Object.keys(map[project].files).forEach(function (file) {
var _a = map[project].files[file],
passes = _a.passes,
failures = _a.failures,
pending = _a.pending;
map[project].files[file].tests = passes + failures + pending;
});
});
return map;
}
exports.parseMochaAwesomeResult = parseMochaAwesomeResult;