Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/get-options/quarantine.js

101 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 });
exports.Quarantine = exports.getQuarantineOptions = exports.validateQuarantineOptions = void 0;
const base_1 = __importDefault(require("./base"));
const quarantine_option_names_1 = __importDefault(require("../../configuration/quarantine-option-names"));
const types_1 = require("../../errors/types");
const runtime_1 = require("../../errors/runtime");
const DEFAULT_ATTEMPT_LIMIT = 5;
const DEFAULT_THRESHOLD = 3;
const MIN_ATTEMPT_LIMIT = 2;
const MIN_SUCCESS_THRESHOLD = 1;
function _isQuarantineOption(option) {
return Object.values(quarantine_option_names_1.default).includes(option);
}
function validateQuarantineOptions(options) {
for (const key in options) {
if (!_isQuarantineOption(key))
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.invalidQuarantineOption, key);
}
const attemptLimit = typeof options.attemptLimit === 'number' ? options.attemptLimit : DEFAULT_ATTEMPT_LIMIT;
const successThreshold = typeof options.successThreshold === 'number' ? options.successThreshold : DEFAULT_THRESHOLD;
if (attemptLimit < MIN_ATTEMPT_LIMIT)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.invalidAttemptLimitValue, quarantine_option_names_1.default.attemptLimit, MIN_ATTEMPT_LIMIT);
if (successThreshold < MIN_SUCCESS_THRESHOLD)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.invalidSuccessThresholdValue, quarantine_option_names_1.default.successThreshold, MIN_SUCCESS_THRESHOLD);
if (successThreshold >= attemptLimit)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.invalidQuarantineParametersRatio, attemptLimit, successThreshold);
}
exports.validateQuarantineOptions = validateQuarantineOptions;
async function getQuarantineOptions(optionName, options) {
if (typeof options === 'boolean')
return true;
const parsedOptions = await (0, base_1.default)(options, {
skipOptionValueTypeConversion: true,
async onOptionParsed(key, value) {
if (!key || !value)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.optionValueIsNotValidKeyValue, optionName);
return Number(value);
},
});
validateQuarantineOptions(parsedOptions);
return parsedOptions;
}
exports.getQuarantineOptions = getQuarantineOptions;
class Quarantine {
constructor() {
this.attempts = [];
this.attemptLimit = DEFAULT_ATTEMPT_LIMIT;
this.successThreshold = DEFAULT_THRESHOLD;
this.failureThreshold = DEFAULT_THRESHOLD;
}
getFailedAttempts() {
return this.attempts.filter(({ errors }) => !!errors.length);
}
getPassedAttempts() {
return this.attempts.filter(({ errors }) => errors.length === 0);
}
setCustomParameters(attemptLimit, successThreshold) {
const needToUpdateTestRunThreshold = typeof attemptLimit === 'number';
const needToUpdatePassedQuarantineThreshold = typeof successThreshold === 'number';
const needToRecalculateFailedThreshold = needToUpdateTestRunThreshold || needToUpdatePassedQuarantineThreshold;
if (needToUpdateTestRunThreshold)
this.attemptLimit = attemptLimit;
if (needToUpdatePassedQuarantineThreshold)
this.successThreshold = successThreshold;
if (needToRecalculateFailedThreshold)
this._setFailedThreshold();
}
getNextAttemptNumber() {
return this.attempts.length + 1;
}
isThresholdReached(extraErrors) {
const { passedTimes, failedTimes } = this._getAttemptsResult(extraErrors);
const successThresholdReached = passedTimes >= this.successThreshold;
const failureThresholdReached = failedTimes >= this.failureThreshold;
return successThresholdReached || failureThresholdReached;
}
isFirstAttemptSuccessful(extraErrors) {
const { failedTimes, passedTimes } = this._getAttemptsResult(extraErrors);
return failedTimes === 0 && passedTimes > 0;
}
_getAttemptsResult(extraErrors) {
let failedTimes = this.getFailedAttempts().length;
let passedTimes = this.getPassedAttempts().length;
if (extraErrors) {
if (extraErrors.length)
failedTimes += extraErrors.length;
else
passedTimes += 1;
}
return { failedTimes, passedTimes };
}
_setFailedThreshold() {
this.failureThreshold = this.attemptLimit - this.successThreshold + 1;
}
}
exports.Quarantine = Quarantine;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic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