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 CHANGED
@@ -1,3 +1,9 @@
1
+ # qase-javascript-commons@2.2.3
2
+
3
+ ## What's new
4
+
5
+ Fixed an issue when the reporter saves the state file in the wrong directory.
6
+
1
7
  # qase-javascript-commons@2.2.1
2
8
 
3
9
  ## What's new
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);
@@ -5,6 +5,7 @@ export interface StateModel {
5
5
  IsModeChanged: boolean | undefined;
6
6
  }
7
7
  export declare class StateManager {
8
+ static statePath: string;
8
9
  static getState(): StateModel;
9
10
  static setRunId(runId: number): void;
10
11
  static setMode(mode: ModeEnum): void;
@@ -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 statePath = 'reporterState.json';
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",