1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.AllureStep = exports.ExecutableItemWrapper = void 0;
|
4 | const constructors_js_1 = require("./constructors.js");
|
5 | const isPromise_js_1 = require("./isPromise.js");
|
6 | const model_js_1 = require("./model.js");
|
7 | const utils_js_1 = require("./utils.js");
|
8 | class ExecutableItemWrapper {
|
9 | constructor(info) {
|
10 | this.info = info;
|
11 | }
|
12 | get wrappedItem() {
|
13 | return this.info;
|
14 | }
|
15 | set name(name) {
|
16 | this.info.name = name;
|
17 | }
|
18 | set description(description) {
|
19 | this.info.description = description;
|
20 | }
|
21 | set descriptionHtml(descriptionHtml) {
|
22 | this.info.descriptionHtml = descriptionHtml;
|
23 | }
|
24 | set status(status) {
|
25 | this.info.status = status;
|
26 | }
|
27 | get status() {
|
28 | return this.info.status;
|
29 | }
|
30 | set statusDetails(details) {
|
31 | this.info.statusDetails = details;
|
32 | }
|
33 | set detailsMessage(message) {
|
34 | this.info.statusDetails.message = message;
|
35 | }
|
36 | set detailsTrace(trace) {
|
37 | this.info.statusDetails.trace = trace;
|
38 | }
|
39 | set stage(stage) {
|
40 | this.info.stage = stage;
|
41 | }
|
42 | parameter(name, value, options) {
|
43 | this.info.parameters.push(Object.assign(Object.assign({}, options), { name, value: (0, utils_js_1.serialize)(value) }));
|
44 | }
|
45 | get isAnyStepFailed() {
|
46 | return (0, utils_js_1.isAnyStepFailed)(this.info);
|
47 | }
|
48 | get isAllStepsEnded() {
|
49 | return (0, utils_js_1.isAllStepsEnded)(this.info);
|
50 | }
|
51 | addParameter(name, value, options) {
|
52 | this.parameter(name, value, options);
|
53 | }
|
54 | addAttachment(name, options, fileName) {
|
55 | if (typeof options === "string") {
|
56 | options = { contentType: options };
|
57 | }
|
58 | this.info.attachments.push({ name, type: options.contentType, source: fileName });
|
59 | }
|
60 | startStep(name, start) {
|
61 | const result = (0, constructors_js_1.stepResult)();
|
62 | this.info.steps.push(result);
|
63 | const allureStep = new AllureStep(result, start);
|
64 | allureStep.name = name;
|
65 | return allureStep;
|
66 | }
|
67 | wrap(fun) {
|
68 | return (...args) => {
|
69 | this.stage = model_js_1.Stage.RUNNING;
|
70 | let result;
|
71 | try {
|
72 | result = fun(args);
|
73 | }
|
74 | catch (error) {
|
75 | this.stage = model_js_1.Stage.INTERRUPTED;
|
76 | this.status = model_js_1.Status.BROKEN;
|
77 | if (error) {
|
78 | this.detailsMessage = error.message || "";
|
79 | this.detailsTrace = error.stack || "";
|
80 | }
|
81 | throw error;
|
82 | }
|
83 | if ((0, isPromise_js_1.isPromise)(result)) {
|
84 | const promise = result;
|
85 | return promise
|
86 | .then((res) => {
|
87 | this.status = model_js_1.Status.PASSED;
|
88 | this.stage = model_js_1.Stage.FINISHED;
|
89 | return res;
|
90 | })
|
91 | .catch((error) => {
|
92 | this.stage = model_js_1.Stage.INTERRUPTED;
|
93 | this.status = model_js_1.Status.BROKEN;
|
94 | if (error) {
|
95 | this.detailsMessage = error.message || "";
|
96 | this.detailsTrace = error.stack || "";
|
97 | }
|
98 | throw error;
|
99 | });
|
100 | }
|
101 | else {
|
102 | this.status = model_js_1.Status.PASSED;
|
103 | this.stage = model_js_1.Stage.FINISHED;
|
104 | return result;
|
105 | }
|
106 | };
|
107 | }
|
108 | addStep(step) {
|
109 | this.info.steps.push(step);
|
110 | }
|
111 | }
|
112 | exports.ExecutableItemWrapper = ExecutableItemWrapper;
|
113 | class AllureStep extends ExecutableItemWrapper {
|
114 | constructor(stepResult, start = Date.now()) {
|
115 | super(stepResult);
|
116 | this.stepResult = stepResult;
|
117 | this.stepResult.start = start;
|
118 | }
|
119 | endStep(stop = Date.now()) {
|
120 | this.stepResult.stop = stop;
|
121 | }
|
122 | }
|
123 | exports.AllureStep = AllureStep;
|
124 |
|
\ | No newline at end of file |