codeceptjs-testit-reporter
Version:
Plugin for sending CodeceptJS test run reports to TestIT
81 lines (80 loc) • 3.56 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var nanoid_1 = require("nanoid");
var utils_1 = require("./utils");
var StepsProcessor = /** @class */ (function () {
function StepsProcessor() {
var _this = this;
this.reset = function () {
_this.stepsMap = {};
_this.stepsTree = [];
_this.lastProcessedStepComment = null;
};
this.patchStepId = function (step) {
// ids may be created by other plugins
if (!step.id)
step.id = (0, nanoid_1.nanoid)();
if (step.metaStep && !step.metaStep.id)
_this.patchStepId(step.metaStep);
};
this.processComment = function (step) {
_this.lastProcessedStepComment = step;
};
this.processStep = function (step) {
var _a;
if (!step.id)
return;
if (step.metaStep && step.metaStep.id) {
var isMetaStepProcessedBefore = !!_this.stepsMap[step.metaStep.id];
if (!isMetaStepProcessedBefore)
_this.processStep(step.metaStep);
}
var stepResult = _this._prepareStepResult(step);
var parentStepResults = !step.metaStep
? _this.stepsTree
: (_a = _this.stepsMap[step.metaStep.id || '']) === null || _a === void 0 ? void 0 : _a.stepResults;
if (_this.lastProcessedStepComment && !step.isMetaStep()) {
parentStepResults === null || parentStepResults === void 0 ? void 0 : parentStepResults.push({ title: _this.lastProcessedStepComment });
_this.lastProcessedStepComment = null;
}
parentStepResults === null || parentStepResults === void 0 ? void 0 : parentStepResults.push(stepResult);
var isStepProcessedBefore = !!_this.stepsMap[step.id];
if (!isStepProcessedBefore)
_this.stepsMap[step.id] = stepResult;
};
this._prepareStepResult = function (step) {
var stepResult = {
title: step.toString(),
duration: step.startTime && step.endTime
? (step.endTime - step.startTime)
: undefined,
outcome: (0, utils_1.cjs2testItStepStatus)(step.status),
};
if (step.isMetaStep())
stepResult.stepResults = [];
return stepResult;
};
this.getStepResults = function () { return __spreadArray([], _this.stepsTree, true); };
this.getSteps = function () { return _this._stepResults2steps(_this.stepsTree) || []; };
this._stepResults2steps = function (stepResults) {
return stepResults === null || stepResults === void 0 ? void 0 : stepResults.map(function (s) { return ({
title: s.title || '',
steps: _this._stepResults2steps(s.stepResults),
}); });
};
this.stepsMap = {};
this.stepsTree = [];
this.lastProcessedStepComment = null;
}
return StepsProcessor;
}());
exports.default = StepsProcessor;