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

122 lines
16 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 events_1 = require("events");
const phase_1 = __importDefault(require("./phase"));
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
const marker_symbol_1 = __importDefault(require("./marker-symbol"));
const nanoid_1 = require("nanoid");
class Role extends events_1.EventEmitter {
constructor(loginUrl, initFn, options = {}) {
super();
this[marker_symbol_1.default] = true;
this.id = (0, nanoid_1.nanoid)(7);
this.phase = loginUrl ? phase_1.default.uninitialized : phase_1.default.initialized;
this.loginUrl = loginUrl;
this._initFn = initFn;
this.opts = options;
this.redirectUrl = null;
this.stateSnapshot = testcafe_hammerhead_1.StateSnapshot.empty();
this.initErr = null;
}
async _storeStateSnapshot(testRun) {
var _a;
if (this.initErr)
return;
this.stateSnapshot = await testRun.getStateSnapshot();
await ((_a = testRun === null || testRun === void 0 ? void 0 : testRun.compilerService) === null || _a === void 0 ? void 0 : _a.updateRoleProperty({
roleId: this.id,
name: 'stateSnapshot',
value: this.stateSnapshot,
}));
}
_wrapTestFn(testRun) {
this._initFn = () => {
var _a;
return (_a = testRun.compilerService) === null || _a === void 0 ? void 0 : _a.executeRoleInitFn({
testRunId: testRun.id,
roleId: this.id,
});
};
}
async _setInitError(err, testRun) {
var _a;
this.initErr = err;
await ((_a = testRun === null || testRun === void 0 ? void 0 : testRun.compilerService) === null || _a === void 0 ? void 0 : _a.updateRoleProperty({
roleId: this.id,
name: 'initErr',
value: this.initErr,
}));
}
async _executeInitFn(testRun) {
if (this.initErr)
return;
try {
if (testRun.compilerService)
this._wrapTestFn(testRun);
let fn = () => this._initFn(testRun);
fn = testRun.decoratePreventEmitActionEvents(fn, { prevent: false });
fn = testRun.decorateDisableDebugBreakpoints(fn, { disable: false });
await fn();
}
catch (err) {
await this._setInitError(err, testRun);
}
}
async _switchToCleanRun(testRun) {
try {
await testRun.switchToCleanRun(this.loginUrl);
}
catch (err) {
await this._setInitError(err, testRun);
}
}
async initialize(testRun) {
var _a;
this.phase = phase_1.default.pendingInitialization;
await this._switchToCleanRun(testRun);
await this._executeInitFn(testRun);
await this._storeStateSnapshot(testRun);
if (this.opts.preserveUrl)
await this.setCurrentUrlAsRedirectUrl(testRun);
this.phase = phase_1.default.initialized;
await ((_a = testRun.compilerService) === null || _a === void 0 ? void 0 : _a.updateRoleProperty({
roleId: this.id,
name: 'phase',
value: this.phase,
}));
this.emit('initialized');
}
async setCurrentUrlAsRedirectUrl(testRun) {
var _a;
const currentUrl = await testRun.getCurrentUrl();
if (this.opts.preserveUrl)
this.redirectUrl = currentUrl;
else {
this.redirectUrl = this.redirectUrl || {};
this.redirectUrl[testRun.test.id] = currentUrl;
}
await ((_a = testRun.compilerService) === null || _a === void 0 ? void 0 : _a.updateRoleProperty({
roleId: this.id,
name: 'redirectUrl',
value: this.redirectUrl,
}));
}
static from(init) {
if (!init)
return null;
const serializedRole = init;
const role = new Role(serializedRole.loginUrl, serializedRole._initFn, serializedRole.opts);
role.id = serializedRole.id;
role.phase = serializedRole.phase;
role.redirectUrl = serializedRole.redirectUrl;
role.stateSnapshot = serializedRole.stateSnapshot;
role.initErr = serializedRole.initErr;
return role;
}
}
exports.default = Role;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm9sZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9yb2xlL3JvbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxtQ0FBc0M7QUFDdEMsb0RBQWdDO0FBQ2hDLDZEQUFvRDtBQUNwRCxvRUFBeUM7QUFDekMsbUNBQWdDO0FBUWhDLE1BQXFCLElBQUssU0FBUSxxQkFBWTtJQVcxQyxZQUFvQixRQUF1QixFQUFFLE1BQXVC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