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

124 lines
18 KiB
JavaScript
Raw Normal View History

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 content_types_1 = __importDefault(require("./assets/content-types"));
const option_names_1 = __importDefault(require("./configuration/option-names"));
const INJECTABLES = __importStar(require("./assets/injectables"));
const setup_sourcemap_support_1 = require("./utils/setup-sourcemap-support");
const lazyRequire = require('import-lazy')(require);
const hammerhead = lazyRequire('testcafe-hammerhead');
const loadAssets = lazyRequire('./load-assets');
const errorHandlers = lazyRequire('./utils/handle-errors');
const BrowserConnectionGateway = lazyRequire('./browser/connection/gateway');
const BrowserConnection = lazyRequire('./browser/connection');
const browserProviderPool = lazyRequire('./browser/provider/pool');
const CompilerHost = lazyRequire('./services/compiler/host');
const Runner = lazyRequire('./runner');
const LiveModeRunner = lazyRequire('./live/test-runner');
// NOTE: CoffeeScript can't be loaded lazily, because it will break stack traces
require('coffeescript');
class TestCafe {
constructor(configuration) {
(0, setup_sourcemap_support_1.setupSourceMapSupport)();
errorHandlers.registerErrorHandlers();
const { hostname, port1, port2, options } = configuration.startOptions;
this.closed = false;
this.proxy = new hammerhead.Proxy(hostname, port1, port2, options);
this.runners = [];
this.configuration = configuration;
this.browserConnectionGateway = new BrowserConnectionGateway(this.proxy, {
retryTestPages: configuration.getOption(option_names_1.default.retryTestPages),
proxyless: configuration.getOption(option_names_1.default.experimentalProxyless),
});
if (configuration.getOption(option_names_1.default.experimentalDebug)) {
const developmentMode = configuration.getOption(option_names_1.default.developmentMode);
const v8Flags = configuration.getOption(option_names_1.default.v8Flags);
this.compilerService = new CompilerHost({ developmentMode, v8Flags });
}
this._registerAssets(options.developmentMode);
}
_registerAssets(developmentMode) {
const { favIcon, coreScript, driverScript, uiScript, uiStyle, uiSprite, uiSpriteSvg, automationScript, legacyRunnerScript } = loadAssets(developmentMode);
this.proxy.GET(INJECTABLES.TESTCAFE_CORE, { content: coreScript, contentType: content_types_1.default.javascript });
this.proxy.GET(INJECTABLES.TESTCAFE_DRIVER, { content: driverScript, contentType: content_types_1.default.javascript });
this.proxy.GET(INJECTABLES.TESTCAFE_LEGACY_RUNNER, {
content: legacyRunnerScript,
contentType: content_types_1.default.javascript,
});
this.proxy.GET(INJECTABLES.TESTCAFE_AUTOMATION, { content: automationScript, contentType: content_types_1.default.javascript });
this.proxy.GET(INJECTABLES.TESTCAFE_UI, { content: uiScript, contentType: content_types_1.default.javascript });
this.proxy.GET(INJECTABLES.TESTCAFE_UI_SPRITE, { content: uiSprite, contentType: content_types_1.default.png });
this.proxy.GET(INJECTABLES.TESTCAFE_UI_SPRITE_SVG, { content: uiSpriteSvg, contentType: content_types_1.default.svg });
this.proxy.GET(INJECTABLES.DEFAULT_FAVICON_PATH, { content: favIcon, contentType: content_types_1.default.icon });
this.proxy.GET(INJECTABLES.TESTCAFE_UI_STYLES, {
content: uiStyle,
contentType: content_types_1.default.css,
isShadowUIStylesheet: true,
});
}
_createRunner(isLiveMode) {
const Ctor = isLiveMode ? LiveModeRunner : Runner;
const newRunner = new Ctor({
proxy: this.proxy,
browserConnectionGateway: this.browserConnectionGateway,
configuration: this.configuration.clone(option_names_1.default.hooks),
compilerService: this.compilerService,
});
this.runners.push(newRunner);
return newRunner;
}
// API
async createBrowserConnection() {
const browserInfo = await browserProviderPool.getBrowserInfo('remote');
return new BrowserConnection(this.browserConnectionGateway, browserInfo, true);
}
createRunner() {
return this._createRunner(false);
}
createLiveModeRunner() {
if (this.runners.some(runner => runner instanceof LiveModeRunner))
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.cannotCreateMultipleLiveModeRunners);
return this._createRunner(true);
}
async close() {
if (this.closed)
return;
this.closed = true;
await Promise.all(this.runners.map(runner => runner.stop()));
await browserProviderPool.dispose();
if (this.compilerService)
this.compilerService.stop();
await this.browserConnectionGateway.close();
this.proxy.close();
}
}
exports.default = TestCafe;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGNhZmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdGVzdGNhZmUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDhDQUFnRDtBQUNoRCwwQ0FBZ0Q7QUFDaEQsMkVBQW1EO0FBQ25ELGdGQUF3RDtBQUN4RCxrRUFBb0Q7QUFDcEQsNkVBQXdFO0FBRXhFLE1BQU0sV0FBVyxHQUFnQixPQUFPLENBQUMsYUFBYSxDQUFDLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDakUsTUFBTSxVQUFVLEdBQWlCLFdBQVcsQ0FBQyxxQkFBcUIsQ0FBQyxDQUFDO0FBQ3BFLE1BQU0sVUFBVSxHQUFpQixXQUFXLENBQUMsZUFBZSxDQUFDLENBQUM7QUFDOUQsTUFBTSxhQUFhLEdBQWMsV0FBVy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