UNPKG

t-comm

Version:

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

102 lines (100 loc) 4.54 kB
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } 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 = {}; var _iterator = _createForOfIteratorHelper(results), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var result = _step.value; 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: [] }; } var _iterator2 = _createForOfIteratorHelper(suites), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var suit = _step2.value; var tests = suit.tests; var _iterator3 = _createForOfIteratorHelper(tests), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var test = _step3.value; map[project].duration += test.duration; map[project].passes += +test.pass; map[project].failures += +test.fail; map[project].pending += +test.pending; map[project].files[moduleName].duration += test.duration; map[project].files[moduleName].passes += +test.pass; map[project].files[moduleName].failures += +test.fail; map[project].files[moduleName].pending += +test.pending; map[project].files[moduleName].testList.push(test); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } Object.keys(map).forEach(function (project) { var _map$project = map[project], passes = _map$project.passes, failures = _map$project.failures, pending = _map$project.pending; map[project].tests = passes + failures + pending; Object.keys(map[project].files).forEach(function (file) { var _map$project$files$fi = map[project].files[file], passes = _map$project$files$fi.passes, failures = _map$project$files$fi.failures, pending = _map$project$files$fi.pending; map[project].files[file].tests = passes + failures + pending; }); }); return map; } export { parseMochaAwesomeResult };