UNPKG

askui

Version:

Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on

46 lines (45 loc) 2.21 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { logger } from '../../lib/logger'; export class ProxyImportError extends Error { } function dynmicImportHpagent() { return __awaiter(this, void 0, void 0, function* () { try { // eslint-disable-next-line import/no-extraneous-dependencies return yield import('hpagent'); } catch (err) { throw new ProxyImportError('Can\'t find "hpagent" module to configure proxy!' + ' Please, install hpagent for proxy support with' + ' "npm install --save-dev hpagent" or "npm install --save hpagent".'); } }); } export function envProxyAgents() { return __awaiter(this, void 0, void 0, function* () { const httpProxyUrl = process.env['HTTP_PROXY']; const httpsProxyUrl = process.env['HTTPS_PROXY']; if (httpProxyUrl === undefined && httpsProxyUrl === undefined) { logger.debug('No proxy defined. "HTTPS_PROXY" and "HTTP_PROXY" environment variables are empty.'); return undefined; } const hpagent = yield dynmicImportHpagent(); logger.info('Using proxy! One of following environment variables are defined: "HTTPS_PROXY", "https_proxy", "HTTP_PROXY" and "http_proxy"'); return { http: new hpagent.HttpProxyAgent({ proxy: (httpProxyUrl || httpsProxyUrl), }), https: new hpagent.HttpsProxyAgent({ proxy: (httpsProxyUrl || httpProxyUrl), }), }; }); }