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

91 lines
12 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 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXguanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw4Q0FBZ0Q7QUFDaEQsMENBQWdEO0FBQ2hELHdFQUErQztBQUMvQywwRUFBaUQ7QUFDakQsb0dBQTJFO0FBQzNFLGdGQUF3RDtBQUN4RCw2RUFBb0Q7QUFDcEQsMEVBQWlEO0FBRWpELE1BQU0sV0FBVyxHQUFLLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FBQyxPQUFPLENBQUMsQ0FBQztBQUN0RCxNQUFNLFFBQVEsR0FBUSxXQUFXLENBQUMsWUFBWSxDQUFDLENBQUM7QUFDaEQsTUFBTSxhQUFhLEdBQUcsV0FBVyxDQUFDLGdCQUFnQixDQUFDLENBQUM7QUFDcEQsTUFBTSxhQUFhLEdBQUcsV0FBVyxDQUFDLGlCQUFpQixDQUFDLENBQUM7QUFFckQsY0FBYztBQUNkLEtBQUssVUFBVSxnQkFBZ0IsQ0FBRSxRQUFRO0lBQ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