qase-javascript-commons 2.2.3 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './reporters';
8
8
  export * from './writer';
9
9
  export * from './utils/get-package-version';
10
10
  export * from './utils/mimeTypes';
11
+ export * from './steps/step';
package/dist/index.js CHANGED
@@ -24,3 +24,4 @@ __exportStar(require("./reporters"), exports);
24
24
  __exportStar(require("./writer"), exports);
25
25
  __exportStar(require("./utils/get-package-version"), exports);
26
26
  __exportStar(require("./utils/mimeTypes"), exports);
27
+ __exportStar(require("./steps/step"), exports);
@@ -0,0 +1,16 @@
1
+ import { Attachment, TestStepType } from '../models';
2
+ export type StepFunction<T = any> = (this: QaseStep, step: QaseStep) => T | Promise<T>;
3
+ export declare class QaseStep {
4
+ name: string;
5
+ attachments: Attachment[];
6
+ steps: TestStepType[];
7
+ constructor(name: string);
8
+ attach(attach: {
9
+ name?: string;
10
+ type?: string;
11
+ content?: string;
12
+ paths?: string[] | string;
13
+ }): void;
14
+ step(name: string, body: StepFunction): Promise<void>;
15
+ run(body: StepFunction, messageEmitter: (step: TestStepType) => Promise<void>): Promise<void>;
16
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.QaseStep = void 0;
7
+ const uuid_1 = require("uuid");
8
+ const path_1 = __importDefault(require("path"));
9
+ const models_1 = require("../models");
10
+ class QaseStep {
11
+ constructor(name) {
12
+ this.name = '';
13
+ this.attachments = [];
14
+ this.steps = [];
15
+ this.name = name;
16
+ }
17
+ attach(attach) {
18
+ if (attach.paths) {
19
+ const files = Array.isArray(attach.paths) ? attach.paths : [attach.paths];
20
+ for (const file of files) {
21
+ const attachmentName = path_1.default.basename(file);
22
+ const contentType = 'application/octet-stream';
23
+ this.attachments.push({
24
+ id: (0, uuid_1.v4)(),
25
+ file_name: attachmentName,
26
+ mime_type: contentType,
27
+ content: '',
28
+ file_path: file,
29
+ size: 0,
30
+ });
31
+ }
32
+ return;
33
+ }
34
+ if (attach.content) {
35
+ const attachmentName = attach.name ?? 'attachment';
36
+ const contentType = attach.type ?? 'application/octet-stream';
37
+ this.attachments.push({
38
+ id: (0, uuid_1.v4)(),
39
+ file_name: attachmentName,
40
+ mime_type: contentType,
41
+ content: attach.content,
42
+ file_path: null,
43
+ size: attach.content.length,
44
+ });
45
+ }
46
+ }
47
+ async step(name, body) {
48
+ const childStep = new QaseStep(name);
49
+ // eslint-disable-next-line @typescript-eslint/require-await
50
+ await childStep.run(body, async (step) => {
51
+ this.steps.push(step);
52
+ });
53
+ }
54
+ async run(body, messageEmitter) {
55
+ const startDate = new Date().getTime();
56
+ const step = new models_1.TestStepType();
57
+ step.data = {
58
+ action: this.name,
59
+ expected_result: null,
60
+ };
61
+ try {
62
+ await body.call(this, this);
63
+ step.execution = {
64
+ start_time: startDate,
65
+ end_time: new Date().getTime(),
66
+ status: models_1.StepStatusEnum.passed,
67
+ duration: null,
68
+ };
69
+ step.attachments = this.attachments;
70
+ step.steps = this.steps;
71
+ await messageEmitter(step);
72
+ }
73
+ catch (e) {
74
+ step.execution = {
75
+ start_time: startDate,
76
+ end_time: new Date().getTime(),
77
+ status: models_1.StepStatusEnum.failed,
78
+ duration: null,
79
+ };
80
+ step.attachments = this.attachments;
81
+ step.steps = this.steps;
82
+ await messageEmitter(step);
83
+ throw e;
84
+ }
85
+ }
86
+ }
87
+ exports.QaseStep = QaseStep;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",