UNPKG

html-reporter

Version:

Html-reporter and GUI for viewing and managing results of a tests run. Currently supports Testplane and Hermione.

91 lines 3.98 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertCustomGui = void 0; const lodash_1 = require("lodash"); const CustomGuiControlTypes = __importStar(require("../gui/constants/custom-gui-control-types")); const SUPPORTED_CONTROL_TYPES = Object.values(CustomGuiControlTypes); const assertSectionGroupType = (context, type) => { if ((0, lodash_1.isUndefined)(type)) { throw new Error(`${context} must contain field "type"`); } if (!(0, lodash_1.isString)(type)) { throw new Error(`${context} must contain string in the field "type"`); } if (!SUPPORTED_CONTROL_TYPES.includes(type)) { throw new Error(`${context} can contain in the field "type" only ${SUPPORTED_CONTROL_TYPES.join(', ')}`); } }; const assertSectionGroupControls = (context, controls) => { if ((0, lodash_1.isUndefined)(controls)) { throw new Error(`${context} must contain field "controls"`); } if (!(0, lodash_1.isArray)(controls)) { throw new Error(`${context} must contain array in the field "controls"`); } if ((0, lodash_1.isEmpty)(controls)) { throw new Error(`${context} must contain non-empty array in the field "controls"`); } controls.forEach((control) => { if (!(0, lodash_1.isPlainObject)(control)) { throw new Error(`${context} must contain objects in the array "controls"`); } }); }; const assertSectionGroupAction = (context, action) => { if ((0, lodash_1.isUndefined)(action)) { throw new Error(`${context} must contain field "action"`); } if (!(0, lodash_1.isFunction)(action)) { throw new Error(`${context} must contain function in the field "action"`); } }; const assertSectionGroup = (sectionName, group, groupIndex) => { const context = `customGui["${sectionName}"][${groupIndex}]`; if (!(0, lodash_1.isPlainObject)(group)) { throw new Error(`${context} must be plain object, but got ${typeof group}`); } const groupObj = group; assertSectionGroupType(context, groupObj.type); assertSectionGroupControls(context, groupObj.controls); assertSectionGroupAction(context, groupObj.action); }; const assertSection = (section, sectionName) => { if (!(0, lodash_1.isArray)(section)) { throw new Error(`customGui["${sectionName}"] must be an array, but got ${typeof section}`); } section.forEach((group, groupIndex) => assertSectionGroup(sectionName, group, groupIndex)); }; const assertCustomGui = (customGui) => { if (!(0, lodash_1.isPlainObject)(customGui)) { throw new Error(`"customGui" option must be plain object, but got ${typeof customGui}`); } const customGuiObj = customGui; for (const sectionName in customGuiObj) { assertSection(customGuiObj[sectionName], sectionName); } }; exports.assertCustomGui = assertCustomGui; //# sourceMappingURL=custom-gui-asserts.js.map