Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.loadTypeScriptCompiler = exports.validateConfig = exports.detectBackend = exports.isCloudCapability = exports.isCucumberFeatureWithLineNumber = exports.removeLineNumbers = exports.getSauceEndpoint = exports.validObjectOrArray = void 0;
  7. const logger_1 = __importDefault(require("@wdio/logger"));
  8. const log = logger_1.default('@wdio/config:utils');
  9. const DEFAULT_HOSTNAME = '127.0.0.1';
  10. const DEFAULT_PORT = 4444;
  11. const DEFAULT_PROTOCOL = 'http';
  12. const DEFAULT_PATH = '/';
  13. const LEGACY_PATH = '/wd/hub';
  14. const REGION_MAPPING = {
  15. 'us': 'us-west-1.',
  16. 'eu': 'eu-central-1.',
  17. 'eu-central-1': 'eu-central-1.',
  18. 'us-east-1': 'us-east-1.'
  19. };
  20. exports.validObjectOrArray = (object) => (Array.isArray(object) && object.length > 0) ||
  21. (typeof object === 'object' && Object.keys(object).length > 0);
  22. function getSauceEndpoint(region, { isRDC, isVisual } = {}) {
  23. const shortRegion = REGION_MAPPING[region] ? region : 'us';
  24. if (isRDC) {
  25. return `${shortRegion}1.appium.testobject.com`;
  26. }
  27. else if (isVisual) {
  28. return 'hub.screener.io';
  29. }
  30. return `ondemand.${REGION_MAPPING[shortRegion]}saucelabs.com`;
  31. }
  32. exports.getSauceEndpoint = getSauceEndpoint;
  33. function removeLineNumbers(filePath) {
  34. const matcher = filePath.match(/:\d+(:\d+$|$)/);
  35. if (matcher) {
  36. filePath = filePath.substring(0, matcher.index);
  37. }
  38. return filePath;
  39. }
  40. exports.removeLineNumbers = removeLineNumbers;
  41. function isCucumberFeatureWithLineNumber(spec) {
  42. const specs = Array.isArray(spec) ? spec : [spec];
  43. return specs.some((s) => s.match(/:\d+(:\d+$|$)/));
  44. }
  45. exports.isCucumberFeatureWithLineNumber = isCucumberFeatureWithLineNumber;
  46. function isCloudCapability(capabilities) {
  47. const caps = capabilities.capabilities || capabilities;
  48. return Boolean(caps && (caps['bstack:options'] || caps['sauce:options'] || caps['tb:options']));
  49. }
  50. exports.isCloudCapability = isCloudCapability;
  51. function detectBackend(options = {}) {
  52. var _a, _b;
  53. let { port, hostname, user, key, protocol, region, headless, path, capabilities } = options;
  54. if (typeof user === 'string' && typeof key === 'string' && key.length === 20) {
  55. return {
  56. protocol: protocol || 'https',
  57. hostname: hostname || 'hub-cloud.browserstack.com',
  58. port: port || 443,
  59. path: path || LEGACY_PATH
  60. };
  61. }
  62. if (typeof user === 'string' && typeof key === 'string' && key.length === 32) {
  63. return {
  64. protocol: protocol || 'https',
  65. hostname: hostname || 'hub.testingbot.com',
  66. port: port || 443,
  67. path: path || LEGACY_PATH
  68. };
  69. }
  70. const isRDC = Boolean(!Array.isArray(capabilities) && ((_a = capabilities) === null || _a === void 0 ? void 0 : _a.testobject_api_key));
  71. const isVisual = Boolean(!Array.isArray(capabilities) && capabilities && ((_b = capabilities['sauce:visual']) === null || _b === void 0 ? void 0 : _b.apiKey));
  72. if ((typeof user === 'string' && typeof key === 'string' && key.length === 36) ||
  73. (isRDC || isVisual)) {
  74. const sauceRegion = headless ? 'us-east-1' : region;
  75. return {
  76. protocol: protocol || 'https',
  77. hostname: hostname || getSauceEndpoint(sauceRegion, { isRDC, isVisual }),
  78. port: port || 443,
  79. path: path || LEGACY_PATH
  80. };
  81. }
  82. if ((typeof user === 'string' || typeof key === 'string') &&
  83. !hostname) {
  84. throw new Error('A "user" or "key" was provided but could not be connected to a ' +
  85. 'known cloud service (Sauce Labs, Browerstack or Testingbot). ' +
  86. 'Please check if given user and key properties are correct!');
  87. }
  88. if (hostname || port || protocol || path) {
  89. return {
  90. hostname: hostname || DEFAULT_HOSTNAME,
  91. port: port || DEFAULT_PORT,
  92. protocol: protocol || DEFAULT_PROTOCOL,
  93. path: path || DEFAULT_PATH
  94. };
  95. }
  96. return { hostname, port, protocol, path };
  97. }
  98. exports.detectBackend = detectBackend;
  99. function validateConfig(defaults, options, keysToKeep = []) {
  100. const params = {};
  101. for (const [name, expectedOption] of Object.entries(defaults)) {
  102. if (typeof options[name] === 'undefined' && !expectedOption.default && expectedOption.required) {
  103. throw new Error(`Required option "${name}" is missing`);
  104. }
  105. if (typeof options[name] === 'undefined' && expectedOption.default) {
  106. params[name] = expectedOption.default;
  107. }
  108. if (typeof options[name] !== 'undefined') {
  109. const optValue = options[name];
  110. if (typeof optValue !== expectedOption.type) {
  111. throw new Error(`Expected option "${name}" to be type of ${expectedOption.type} but was ${typeof options[name]}`);
  112. }
  113. if (typeof expectedOption.validate === 'function') {
  114. try {
  115. expectedOption.validate(optValue);
  116. }
  117. catch (e) {
  118. throw new Error(`Type check for option "${name}" failed: ${e.message}`);
  119. }
  120. }
  121. if (typeof optValue === 'string' && expectedOption.match && !optValue.match(expectedOption.match)) {
  122. throw new Error(`Option "${name}" doesn't match expected values: ${expectedOption.match}`);
  123. }
  124. params[name] = options[name];
  125. }
  126. }
  127. for (const [name, option] of Object.entries(options)) {
  128. if (keysToKeep.includes(name)) {
  129. params[name] = option;
  130. }
  131. }
  132. return params;
  133. }
  134. exports.validateConfig = validateConfig;
  135. function loadTypeScriptCompiler() {
  136. try {
  137. require.resolve('ts-node');
  138. require('ts-node').register({ transpileOnly: true });
  139. }
  140. catch (e) {
  141. return log.debug('Couldn\'t find ts-node package, no TypeScript compiling');
  142. }
  143. }
  144. exports.loadTypeScriptCompiler = loadTypeScriptCompiler;