qase-javascript-commons 2.2.2 → 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/changelog.md +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/state/state.d.ts +1 -0
- package/dist/state/state.js +9 -5
- package/dist/steps/step.d.ts +16 -0
- package/dist/steps/step.js +87 -0
- package/package.json +1 -1
package/changelog.md
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/state/state.d.ts
CHANGED
package/dist/state/state.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.StateManager = void 0;
|
|
4
7
|
const fs_1 = require("fs");
|
|
5
|
-
const
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
6
9
|
class StateManager {
|
|
7
10
|
static getState() {
|
|
8
11
|
let state = {
|
|
@@ -11,7 +14,7 @@ class StateManager {
|
|
|
11
14
|
IsModeChanged: undefined,
|
|
12
15
|
};
|
|
13
16
|
try {
|
|
14
|
-
const data = (0, fs_1.readFileSync)(statePath, 'utf8');
|
|
17
|
+
const data = (0, fs_1.readFileSync)(this.statePath, 'utf8');
|
|
15
18
|
state = JSON.parse(data);
|
|
16
19
|
}
|
|
17
20
|
catch (err) {
|
|
@@ -38,7 +41,7 @@ class StateManager {
|
|
|
38
41
|
static setState(state) {
|
|
39
42
|
try {
|
|
40
43
|
const data = JSON.stringify(state);
|
|
41
|
-
(0, fs_1.writeFileSync)(statePath, data);
|
|
44
|
+
(0, fs_1.writeFileSync)(this.statePath, data);
|
|
42
45
|
}
|
|
43
46
|
catch (err) {
|
|
44
47
|
console.error('Error writing state file:', err);
|
|
@@ -46,14 +49,15 @@ class StateManager {
|
|
|
46
49
|
}
|
|
47
50
|
static clearState() {
|
|
48
51
|
try {
|
|
49
|
-
(0, fs_1.unlinkSync)(statePath);
|
|
52
|
+
(0, fs_1.unlinkSync)(this.statePath);
|
|
50
53
|
}
|
|
51
54
|
catch (err) {
|
|
52
55
|
console.error('Error clearing state file:', err);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
static isStateExists() {
|
|
56
|
-
return (0, fs_1.existsSync)(statePath);
|
|
59
|
+
return (0, fs_1.existsSync)(this.statePath);
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
exports.StateManager = StateManager;
|
|
63
|
+
StateManager.statePath = path_1.default.resolve(__dirname, 'reporterState.json');
|
|
@@ -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;
|