UNPKG

perfrunner-core

Version:

Automated UI performance test tool to measure performance changes for the web apps and sites

58 lines (57 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateArguments = exports.validator = void 0; const yup_1 = require("yup"); const logger_1 = require("../logger"); // yup doesn't validate localhost as correct URL // https://github.com/jquense/yup/issues/224 const urlRegex = /^(?:([a-z0-9+.-]+):\/\/)(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/; const optionalString = () => (0, yup_1.string)().optional().strict(true); const requiredString = () => (0, yup_1.string)().required().strict(true); const optionalBool = (defaultValue) => (0, yup_1.boolean)().optional().strict(true).default(!!defaultValue); const optionalPositiveInteger = () => (0, yup_1.number)().optional().strict(true).positive().integer(); const requiredPositiveInteger = () => (0, yup_1.number)().required().strict(true).positive().integer(); const optionsValidationScheme = { url: requiredString().test('url', 'URL isn\'t valid', (v) => v == null || urlRegex.test(v)), runs: requiredPositiveInteger(), network: (0, yup_1.object)() .required() .shape({ downloadThroughput: (0, yup_1.number)().required().strict(true), latency: (0, yup_1.number)().required().strict(true), uploadThroughput: (0, yup_1.number)().required().strict(true), }), throttlingRate: (0, yup_1.number)().required().positive().integer(), testName: optionalString(), comment: optionalString(), output: requiredString(), headless: optionalBool(true), purge: optionalBool(), reportOnly: optionalBool(), ignoreDefaultArgs: optionalBool(), useCache: optionalBool(), chromeArgs: (0, yup_1.array)().of(requiredString()), timeout: requiredPositiveInteger(), waitFor: (0, yup_1.lazy)((value) => { switch (typeof value) { case 'number': return optionalPositiveInteger(); case 'string': return optionalString(); default: return optionalString(); } }), executablePath: optionalString(), }; exports.validator = (0, yup_1.object)().shape(optionsValidationScheme); function validateArguments(params) { try { exports.validator.validateSync(params); } catch (e) { (0, logger_1.error)(e); throw e; } } exports.validateArguments = validateArguments;