Innovenergy_trunk/frontend/node_modules/testcafe/lib/services/compiler/test-run-proxy.js

156 lines
26 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 lodash_1 = require("lodash");
const test_run_tracker_1 = __importDefault(require("../../api/test-run-tracker"));
const test_controller_1 = __importDefault(require("../../api/test-controller"));
const observed_callsites_storage_1 = __importDefault(require("../../test-run/observed-callsites-storage"));
const warning_log_1 = __importDefault(require("../../notifications/warning-log"));
const type_1 = __importDefault(require("../../test-run/commands/type"));
const base_1 = require("../../test-run/commands/base");
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
const re_executable_promise_1 = __importDefault(require("../../utils/re-executable-promise"));
const async_event_emitter_1 = __importDefault(require("../../utils/async-event-emitter"));
const marker_symbol_1 = __importDefault(require("../../test-run/marker-symbol"));
const constants_1 = require("../../test-run/execute-js-expression/constants");
const marker_1 = require("../serialization/replicator/transforms/function-marker-transform/marker");
const get_fn_1 = __importDefault(require("../../assertions/get-fn"));
const thennable_1 = require("../../utils/thennable");
const marker_2 = require("../serialization/replicator/transforms/promise-marker-transform/marker");
const observation_1 = require("../../test-run/commands/observation");
class TestRunProxy extends async_event_emitter_1.default {
constructor({ dispatcher, id, test, options, browser, activeWindowId, messageBus }) {
super();
this.debugging = false;
this[marker_symbol_1.default] = true;
this.dispatcher = dispatcher;
this.id = id;
this.test = test;
this.ctx = Object.create(null);
this.fixtureCtx = Object.create(null);
this._options = options;
this.browser = browser;
this.assertionCommands = new Map();
this.switchToWindowByPredicateCommands = new Map();
this.asyncJsExpressionCallsites = new Map();
this.controller = new test_controller_1.default(this);
this.observedCallsites = new observed_callsites_storage_1.default();
this.warningLog = new warning_log_1.default(null, warning_log_1.default.createAddWarningCallback(messageBus));
this.disableMultipleWindows = options.disableMultipleWindows;
this.activeWindowId = activeWindowId;
test_run_tracker_1.default.addActiveTestRun(this);
this._initializeRequestHooks();
}
_initializeRequestHooks() {
this.test.requestHooks.forEach(this._attachWarningLog, this);
}
_attachWarningLog(hook) {
hook._warningLog = this.warningLog;
}
_detachWarningLog(hook) {
hook._warningLog = null;
}
_storeAssertionCommand(command) {
command.id = (0, testcafe_hammerhead_1.generateUniqueId)();
this.assertionCommands.set(command.id, command);
}
_storeSwitchToWindowByPredicateCommand(command) {
command.id = (0, testcafe_hammerhead_1.generateUniqueId)();
this.switchToWindowByPredicateCommands.set(command.id, command);
}
_handleAssertionCommand(command) {
if ((0, lodash_1.isFunction)(command.actual)) {
command.originActual = command.actual;
command.actual = new marker_1.FunctionMarker();
this._storeAssertionCommand(command);
}
else if (command.actual instanceof re_executable_promise_1.default)
this._storeAssertionCommand(command);
else if ((0, thennable_1.isThennable)(command.actual)) {
command.originActual = command.actual;
command.actual = new marker_2.PromiseMarker();
this._storeAssertionCommand(command);
}
}
_handleExecuteClientFunctionCommandBase(command) {
command.esmRuntime = this.test.esmRuntime;
}
_storeActionCallsitesForExecutedAsyncJsExpression(callsite) {
// @ts-ignore
if ((callsite === null || callsite === void 0 ? void 0 : callsite.filename) !== constants_1.ERROR_FILENAME)
return;
const id = (0, testcafe_hammerhead_1.generateUniqueId)();
// @ts-ignore
callsite.id = id;
this.asyncJsExpressionCallsites.set(id, callsite);
}
async executeCommand(command, callsite) {
if (command instanceof base_1.ActionCommandBase && callsite)
this._storeActionCallsitesForExecutedAsyncJsExpression(callsite);
if (command.type === type_1.default.assertion)
this._handleAssertionCommand(command);
else if (command.type === type_1.default.useRole)
this.dispatcher.onRoleAppeared(command.role);
else if (command.type === type_1.default.switchToWindowByPredicate)
this._storeSwitchToWindowByPredicateCommand(command);
else if (command instanceof observation_1.ExecuteClientFunctionCommandBase)
this._handleExecuteClientFunctionCommandBase(command);
return this.dispatcher.executeCommand({
command,
callsite,
id: this.id,
});
}
executeCommandSync(command, callsite) {
if (command.type === type_1.default.assertion)
this._handleAssertionCommand(command);
else if (command.type === type_1.default.useRole)
this.dispatcher.onRoleAppeared(command.role);
return this.dispatcher.executeCommandSync({
command,
callsite,
id: this.id,
});
}
async addRequestHook(hook) {
if (this.test.requestHooks.includes(hook))
return;
this.test.requestHooks.push(hook);
this._attachWarningLog(hook);
await this.dispatcher.addRequestEventListeners({
hookId: hook.id,
hookClassName: hook._className,
rules: hook._requestFilterRules,
});
}
async removeRequestHook(hook) {
if (!this.test.requestHooks.includes(hook))
return;
(0, lodash_1.pull)(this.test.requestHooks, hook);
this._detachWarningLog(hook);
await this.dispatcher.removeRequestEventListeners({ rules: hook._requestFilterRules });
}
async getAssertionActualValue(commandId) {
const command = this.assertionCommands.get(commandId);
return command.actual._reExecute();
}
async executeAssertionFn(commandId) {
const command = this.assertionCommands.get(commandId);
command.actual = command.originActual;
const fn = (0, get_fn_1.default)(command);
return await fn();
}
restoreOriginCallsiteForError(err) {
err.errCallsite = this.asyncJsExpressionCallsites.get(err.errCallsite.id);
this.asyncJsExpressionCallsites.clear();
}
checkWindow(commandId, { title, url }) {
const command = this.switchToWindowByPredicateCommands.get(commandId);
return command.checkWindow({ title, url });
}
}
exports.default = TestRunProxy;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1ydW4tcHJveHkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc2VydmljZXMvY29tcGlsZXIvdGVzdC1ydW4tcHJveHkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxtQ0FBMEM7QUFDMUMsa0ZBQXdEO0FBRXhELGdGQUF1RDtBQUN2RCwyR0FBaUY7QUFDakYsa0ZBQXlEO0FBR3pELHdFQUF3RDtBQUN4RCx1REFBOEU7QUFJOUUsNkRBQXVEO0FBU3ZELDhGQUFvRTtBQUNwRSwwRkFBZ0U7QUFDaEUsaUZBQXlEO0FBQ3pELDhFQUFnRjtBQUVoRixvR0FBeUc7Q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