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

89 lines
12 KiB
JavaScript
Raw Permalink 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 events_1 = require("events");
const delay_1 = __importDefault(require("../utils/delay"));
const thennable_1 = require("../utils/thennable");
const test_run_1 = require("../errors/test-run");
const re_executable_promise_1 = __importDefault(require("../utils/re-executable-promise"));
const get_fn_1 = __importDefault(require("./get-fn"));
const marker_1 = require("../services/serialization/replicator/transforms/function-marker-transform/marker");
const marker_2 = require("../services/serialization/replicator/transforms/promise-marker-transform/marker");
const ASSERTION_DELAY = 200;
class AssertionExecutor extends events_1.EventEmitter {
constructor(command, timeout, callsite) {
super();
this.command = command;
this.timeout = timeout;
this.callsite = callsite;
this.startTime = null;
this.passed = false;
this.inRetry = false;
const fn = (0, get_fn_1.default)(this.command);
const actualCommand = this.command.actual;
if (actualCommand instanceof re_executable_promise_1.default)
this.fn = this._wrapFunction(fn);
else if (!this.command.options.allowUnawaitedPromise && this._isPromise(actualCommand))
throw new test_run_1.AssertionUnawaitedPromiseError(this.callsite);
else
this.fn = fn;
}
_isPromise(val) {
return (0, thennable_1.isThennable)(val) ||
val === Symbol.for(marker_2.PROMISE_MARKER_DESCRIPTION);
}
_getTimeLeft() {
const executionTime = new Date().getTime() - this.startTime; // eslint-disable-line @typescript-eslint/no-extra-parens
return this.timeout - executionTime;
}
_onExecutionFinished() {
if (this.inRetry)
this.emit('end-assertion-retries', this.passed);
}
_wrapFunction(fn) {
return async () => {
const resultPromise = this.command.actual;
while (!this.passed) {
this.command.actual = await resultPromise._reExecute();
try {
fn();
this.passed = true;
this._onExecutionFinished();
}
catch (err) {
if (this._getTimeLeft() <= 0) {
this._onExecutionFinished();
throw err;
}
await (0, delay_1.default)(ASSERTION_DELAY);
this.inRetry = true;
this.emit('start-assertion-retries', this._getTimeLeft());
}
}
};
}
_onBeforeRun() {
if (this.command.actual !== Symbol.for(marker_1.FUNCTION_MARKER_DESCRIPTION))
return;
this.emit('non-serializable-actual-value', this);
}
async run() {
this._onBeforeRun();
this.startTime = new Date().getTime();
try {
await this.fn();
}
catch (err) {
if (err.name === 'AssertionError' || err.constructor.name === 'AssertionError')
throw new test_run_1.ExternalAssertionLibraryError(err, this.callsite);
if (err.isTestCafeError)
err.callsite = this.callsite;
throw err;
}
}
}
exports.default = AssertionExecutor;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhlY3V0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXNzZXJ0aW9ucy9leGVjdXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1DQUFzQztBQUN0QywyREFBbUM7QUFDbkMsa0RBQWlEO0FBQ2pELGlEQUFtRztBQUNuRywyRkFBaUU7QUFDakUsc0RBQTZCO0FBRzdCLDZHQUErSDtBQUMvSCw0R0FBNkg7QUFFN0gsTUFBTSxlQUFlLEdBQUcsR0FBRyxDQUFDO0FBRTVCLE1BQXFCLGlCQUFrQixTQUFRLHFCQUFZO0lBU3ZELFlBQW9CLE9BQXlCLEVBQUUsT0FBZSxFQUFFLFFBQXdCO1FBQ3BGLEtBQUssRUFBRSxDQUFDO1FBRVIsSUFBSSxDQUFDLE9BQU8sR0FBSSxPQUFPLENBQUM7UUFDeEIsSUFBSSxDQUFDLE9BQU8sR0FBSSxPQUFPLENBQUM7UUFDeEIsSUFBSSxDQUFDLFFBQVEsR0FBRyxRQUFRLENBQUM7UUFFekIsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUM7UUFDdEIsSUFBSSxDQUFDLE1BQU0sR0FBTSxLQUFLLENBQUM7UUFDdkIsSUFBSSxDQUFDLE9BQU8sR0FBSyxLQUFLLENBQUM7UUFFdkIsTUFBTSxFQUFFLE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