Innovenergy_trunk/frontend/node_modules/testcafe/lib/browser/provider/pool.js

125 lines
19 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const built_in_1 = __importDefault(require("./built-in"));
const plugin_host_1 = __importDefault(require("./plugin-host"));
const parse_provider_name_1 = __importDefault(require("./parse-provider-name"));
const _1 = __importDefault(require("./"));
const connection_1 = __importDefault(require("../connection"));
const runtime_1 = require("../../errors/runtime");
const types_1 = require("../../errors/types");
const BROWSER_PROVIDER_RE = /^([^:\s]+):?(.*)?$/;
const BROWSER_INFO_PROPERTIES = ['browserName', 'browserOption', 'providerName', 'provider'];
exports.default = {
providersCache: {},
async _handlePathAndCmd(alias) {
const browserName = JSON.stringify(alias);
const providerName = 'path';
const provider = await this.getProvider(providerName);
const browserOption = provider.plugin.getConfig(browserName);
return { provider, providerName, browserName, browserOption };
},
async _parseAliasString(alias) {
const providerRegExpMatch = BROWSER_PROVIDER_RE.exec(alias);
if (!providerRegExpMatch)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.cannotFindBrowser, alias);
let providerName = providerRegExpMatch[1];
let browserName = providerRegExpMatch[2] || '';
let browserOption = {};
let provider = await this.getProvider(providerName);
if (!provider && providerRegExpMatch[2])
provider = await this.getProvider(providerName + ':');
if (!provider) {
providerName = 'locally-installed';
provider = await this.getProvider(providerName);
browserName = providerRegExpMatch[1] || '';
}
browserOption = provider.plugin.getConfig(browserName);
return { provider, providerName, browserName, browserOption };
},
async _parseAlias(alias) {
if (typeof alias === 'object') {
if (BROWSER_INFO_PROPERTIES.every(property => property in alias))
return alias;
if (alias.path)
return this._handlePathAndCmd(alias);
}
if (typeof alias === 'string')
return this._parseAliasString(alias);
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.cannotFindBrowser, alias);
},
async _getInfoForAllBrowserNames(provider, providerName) {
const allBrowserNames = provider.isMultiBrowser ?
await provider.getBrowserList() :
[];
if (!allBrowserNames.length)
return { provider, providerName, browserName: '', browserOption: '' };
return allBrowserNames
.map(browserName => ({ provider, providerName, browserName, browserOption: browserName }));
},
_getProviderModule(providerName, moduleName) {
try {
// First, just check if the module exists
require.resolve(moduleName);
}
catch (e) {
// Module does not exist. Return null, and let the caller handle
return null;
}
// Load the module
const providerObject = require(moduleName);
this.addProvider(providerName, providerObject);
return this._getProviderFromCache(providerName);
},
_getProviderFromCache(providerName) {
return this.providersCache[providerName] || null;
},
_getBuiltinProvider(providerName) {
const providerObject = built_in_1.default[providerName];
if (!providerObject)
return null;
this.addProvider(providerName, providerObject);
return this._getProviderFromCache(providerName);
},
async getBrowserInfo(alias) {
if (alias instanceof connection_1.default)
return alias;
const browserInfo = await this._parseAlias(alias);
const { provider, providerName, browserName } = browserInfo;
if (browserName === 'all')
return await this._getInfoForAllBrowserNames(provider, providerName);
if (!await provider.isValidBrowserName(browserName))
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.cannotFindBrowser, alias);
if (typeof alias === 'object' && alias.alias)
alias = alias.alias;
if (typeof alias !== 'string')
alias = JSON.stringify(alias);
return Object.assign({ alias }, browserInfo);
},
addProvider(providerName, providerObject) {
providerName = (0, parse_provider_name_1.default)(providerName).providerName;
this.providersCache[providerName] = new _1.default(new plugin_host_1.default(providerObject, providerName));
},
removeProvider(providerName) {
providerName = (0, parse_provider_name_1.default)(providerName).providerName;
delete this.providersCache[providerName];
},
async getProvider(providerName) {
const parsedProviderName = (0, parse_provider_name_1.default)(providerName);
const moduleName = parsedProviderName.moduleName;
providerName = parsedProviderName.providerName;
const provider = this._getProviderFromCache(providerName) ||
this._getProviderModule(providerName, moduleName) ||
this._getBuiltinProvider(providerName);
if (provider)
await this.providersCache[providerName].init();
return provider;
},
dispose() {
return Promise.all(Object.values(this.providersCache).map(item => item.dispose()));
},
};
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJma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