Innovenergy_trunk/frontend/node_modules/testcafe/lib/index.js

91 lines
12 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const runtime_1 = require("./errors/runtime");
const types_1 = require("./errors/types");
const embedding_utils_1 = __importDefault(require("./embedding-utils"));
const exportable_lib_1 = __importDefault(require("./api/exportable-lib"));
const testcafe_configuration_1 = __importDefault(require("./configuration/testcafe-configuration"));
const option_names_1 = __importDefault(require("./configuration/option-names"));
const process_title_1 = __importDefault(require("./services/process-title"));
const user_variables_1 = __importDefault(require("./api/user-variables"));
const lazyRequire = require('import-lazy')(require);
const TestCafe = lazyRequire('./testcafe');
const endpointUtils = lazyRequire('endpoint-utils');
const setupExitHook = lazyRequire('async-exit-hook');
// Validations
async function getValidHostname(hostname) {
if (hostname) {
const valid = await endpointUtils.isMyHostname(hostname);
if (!valid)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.invalidHostname, hostname);
}
else
hostname = endpointUtils.getIPAddress();
return hostname;
}
async function getValidPort(port) {
if (port) {
const isFree = await endpointUtils.isFreePort(port);
if (!isFree)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.portIsNotFree, port);
}
else
port = await endpointUtils.getFreePort();
return port;
}
// API
async function getConfiguration(args) {
var _a;
let configuration;
if (args.length === 1 && typeof args[0] === 'object') {
configuration = new testcafe_configuration_1.default((_a = args[0]) === null || _a === void 0 ? void 0 : _a.configFile);
await configuration.init(args[0]);
}
else {
// NOTE: Positional arguments support is left only for backward compatibility.
// It should be removed in future TestCafe versions.
// All new APIs should be enabled trough the configuration object in the upper clause.
// Please do not add new APIs here.
const [hostname, port1, port2, ssl, developmentMode, retryTestPages, cache, configFile] = args;
configuration = new testcafe_configuration_1.default(configFile);
await configuration.init({
hostname,
port1,
port2,
ssl,
developmentMode,
retryTestPages,
cache,
});
}
return configuration;
}
// API
async function createTestCafe(...args) {
process.title = process_title_1.default.main;
const configuration = await getConfiguration(args);
const [hostname, port1, port2] = await Promise.all([
getValidHostname(configuration.getOption(option_names_1.default.hostname)),
getValidPort(configuration.getOption(option_names_1.default.port1)),
getValidPort(configuration.getOption(option_names_1.default.port2)),
]);
const userVariablesOption = configuration.getOption(option_names_1.default.userVariables);
if (userVariablesOption)
user_variables_1.default.value = userVariablesOption;
configuration.mergeOptions({ hostname, port1, port2 });
const testcafe = new TestCafe(configuration);
setupExitHook(cb => testcafe.close().then(cb));
return testcafe;
}
// Embedding utils
createTestCafe.embeddingUtils = embedding_utils_1.default;
// Common API
Object.keys(exportable_lib_1.default).forEach(key => {
Object.defineProperty(createTestCafe, key, { get: () => exportable_lib_1.default[key] });
});
exports.default = createTestCafe;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXguanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw4Q0FBZ0Q7QUFDaEQsMENBQWdEO0FBQ2hELHdFQUErQztBQUMvQywwRUFBaUQ7QUFDakQsb0dBQTJFO0FBQzNFLGdGQUF3RDtBQUN4RCw2RUFBb0Q7QUFDcEQsMEVBQWlEO0FBRWpELE1BQU0sV0FBVyxHQUFLLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FBQyxPQUFPLENBQUMsQ0FBQztBQUN0RCxNQUFNLFFBQVEsR0FBUSxXQUFXLENBQUMsWUFBWSxDQUFDLENBQUM7QUFDaEQsTUFBTSxhQUFhLEdBQUcsV0FBVyxDQUFDLGdCQUFnQixDQUFDLENBQUM7QUFDcEQsTUFBTSxhQUFhLEdBQUcsV0FBVyxDQUFDLGlCQUFpQixDQUFDLENBQUM7QUFFckQsY0FBYztBQUNkLEtBQUssVUFBVSxnQkFBZ0IsQ0FBRSxRQUFRO0lBQ3JDLElBQUks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