askui
Version:
Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on
81 lines (80 loc) • 2.85 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultStep = void 0;
const lodash_1 = require("lodash");
const control_command_error_1 = require("../../execution/control-command-error");
class DefaultStep {
constructor(instruction) {
this.instruction = instruction;
this.runs = [];
}
get status() {
var _a, _b;
return (_b = (_a = this.lastRun) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 'pending';
}
get begin() {
var _a;
return (_a = this.firstRun) === null || _a === void 0 ? void 0 : _a.begin;
}
get end() {
var _a;
return (_a = this.lastRun) === null || _a === void 0 ? void 0 : _a.end;
}
get error() {
var _a;
return (_a = this.lastRun) === null || _a === void 0 ? void 0 : _a.error;
}
get retries() {
var _a, _b;
return (_b = (_a = this.runs) === null || _a === void 0 ? void 0 : _a.slice(1)) !== null && _b !== void 0 ? _b : [];
}
get retryCount() {
var _a, _b;
return (_b = (_a = this.retries) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
}
get firstRun() {
var _a;
return (_a = this.runs) === null || _a === void 0 ? void 0 : _a[0];
}
get lastRun() {
var _a;
return (_a = this.runs) === null || _a === void 0 ? void 0 : _a[this.runs.length - 1];
}
get flaky() {
return this.retryCount > 0;
}
get duration() {
if (this.begin !== undefined && this.end !== undefined) {
return this.end.createdAt.getTime() - this.begin.createdAt.getTime();
}
return undefined;
}
onBegin(snapshot) {
this.runs = [...this.runs, {
status: 'running',
begin: snapshot,
}];
return (0, lodash_1.cloneDeep)(this);
}
onRetry(snapshot, error) {
this.onEnd(snapshot, error);
this.onBegin(snapshot);
return (0, lodash_1.cloneDeep)(this);
}
onEnd(snapshot, error) {
this.runs = [...this.runs.slice(0, -1), Object.assign(Object.assign({}, this.lastRun), {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
duration: snapshot.createdAt.getTime() - this.lastRun.begin.createdAt.getTime(), end: snapshot, error, status: DefaultStep.determineLastRunStatus(error) })];
return (0, lodash_1.cloneDeep)(this);
}
static determineLastRunStatus(error) {
if (error instanceof control_command_error_1.ControlCommandError) {
return 'failed';
}
if (error !== undefined) {
return 'erroneous';
}
return 'passed';
}
}
exports.DefaultStep = DefaultStep;