cypress-qase-reporter 2.2.0-beta.1 → 2.2.0-beta.2

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/README.md CHANGED
@@ -106,6 +106,7 @@ parameterize your tests.
106
106
  - `qase.parameters` - set the parameters of the test case
107
107
  - `qase.groupParameters` - set the group parameters of the test case
108
108
  - `qase.ignore` - ignore the test case in Qase. The test will be executed, but the results will not be sent to Qase.
109
+ - `qase.step` - create a step in the test case
109
110
 
110
111
  For example:
111
112
 
@@ -206,8 +207,8 @@ module.exports = cypress.defineConfig({
206
207
  video: false,
207
208
  e2e: {
208
209
  setupNodeEvents(on, config) {
209
- require('cypress-qase-reporter/plugin')(on, config)
210
- require('cypress-qase-reporter/metadata')(on)
210
+ require('cypress-qase-reporter/plugin')(on, config)
211
+ require('cypress-qase-reporter/metadata')(on)
211
212
  },
212
213
  },
213
214
  });
package/changelog.md CHANGED
@@ -1,3 +1,19 @@
1
+ # cypress-qase-reporter@2.2.0-beta.2
2
+
3
+ ## What's new
4
+
5
+ Added the ability to add steps in tests:
6
+
7
+ - `qase.step` - add a step to the test
8
+
9
+ ```ts
10
+ it('test', () => {
11
+ qase.step('Step 1', () => {
12
+ cy.visit('https://example.com');
13
+ });
14
+ });
15
+ ```
16
+
1
17
  # cypress-qase-reporter@2.2.0-beta.1
2
18
 
3
19
  ## What's new
@@ -2,6 +2,8 @@ import { Metadata } from './models';
2
2
  export declare class MetadataManager {
3
3
  static getMetadata(): Metadata | undefined;
4
4
  static setIgnore(): void;
5
+ static addStepStart(name: string): void;
6
+ static addStepEnd(status: string): void;
5
7
  static setSuite(suite: string): void;
6
8
  static setComment(comment: string): void;
7
9
  static setTitle(title: string): void;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MetadataManager = void 0;
4
4
  const fs_1 = require("fs");
5
+ const uuid_1 = require("uuid");
5
6
  const metadataPath = 'qaseMetadata';
6
7
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
7
8
  class MetadataManager {
@@ -17,6 +18,9 @@ class MetadataManager {
17
18
  ignore: false,
18
19
  suite: undefined,
19
20
  comment: undefined,
21
+ steps: [],
22
+ currentStepId: undefined,
23
+ firstStepName: undefined,
20
24
  };
21
25
  try {
22
26
  const data = (0, fs_1.readFileSync)(metadataPath, 'utf8');
@@ -33,6 +37,33 @@ class MetadataManager {
33
37
  metadata.ignore = true;
34
38
  this.setMetadata(metadata);
35
39
  }
40
+ static addStepStart(name) {
41
+ const metadata = this.getMetadata() ?? {};
42
+ if (metadata.firstStepName === name) {
43
+ return;
44
+ }
45
+ if (!metadata.steps) {
46
+ metadata.steps = [];
47
+ }
48
+ const id = (0, uuid_1.v4)();
49
+ const parentId = metadata.currentStepId ?? undefined;
50
+ metadata.steps.push({ timestamp: Date.now(), name, id: id, parentId: parentId });
51
+ metadata.currentStepId = id;
52
+ if (!metadata.firstStepName) {
53
+ metadata.firstStepName = name;
54
+ }
55
+ this.setMetadata(metadata);
56
+ }
57
+ static addStepEnd(status) {
58
+ const metadata = this.getMetadata() ?? {};
59
+ if (!metadata.steps || !metadata.currentStepId) {
60
+ return;
61
+ }
62
+ const parentId = metadata.steps.reverse().find((step) => step.id === metadata.currentStepId)?.parentId;
63
+ metadata.steps.push({ timestamp: Date.now(), status, id: metadata.currentStepId });
64
+ metadata.currentStepId = parentId;
65
+ this.setMetadata(metadata);
66
+ }
36
67
  static setSuite(suite) {
37
68
  const metadata = this.getMetadata() ?? {};
38
69
  metadata.suite = suite;
@@ -6,4 +6,18 @@ export interface Metadata {
6
6
  ignore?: boolean;
7
7
  suite?: string | undefined;
8
8
  comment?: string | undefined;
9
+ steps?: (StepStart | StepEnd)[];
10
+ currentStepId?: string | undefined;
11
+ firstStepName?: string | undefined;
12
+ }
13
+ export interface StepStart {
14
+ id: string;
15
+ timestamp: number;
16
+ name: string;
17
+ parentId: string | undefined;
18
+ }
19
+ export interface StepEnd {
20
+ id: string;
21
+ timestamp: number;
22
+ status: string;
9
23
  }
package/dist/metadata.js CHANGED
@@ -44,4 +44,16 @@ module.exports = function (on) {
44
44
  return null;
45
45
  },
46
46
  });
47
+ on('task', {
48
+ qaseStepStart(value) {
49
+ manager_1.MetadataManager.addStepStart(value);
50
+ return null;
51
+ },
52
+ });
53
+ on('task', {
54
+ qaseStepEnd(value) {
55
+ manager_1.MetadataManager.addStepEnd(value);
56
+ return null;
57
+ },
58
+ });
47
59
  };
package/dist/mocha.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  /// <reference types="cypress" />
2
+ /// <reference types="cypress" />
3
+ /// <reference types="cypress" />
4
+ /// <reference types="cypress" />
2
5
  import { Test } from 'mocha';
3
6
  export declare const qase: {
4
7
  (caseId: number | string | number[] | string[], test: Test): Test;
@@ -71,4 +74,17 @@ export declare const qase: {
71
74
  * });
72
75
  */
73
76
  comment(value: string): void;
77
+ /**
78
+ * Add a step to the test case
79
+ * @param {string} name
80
+ * @param {() => T | PromiseLike<T>} body
81
+ * @example
82
+ * it('test', () => {
83
+ * qase.step("Some step", () => {
84
+ * // some actions
85
+ * });
86
+ * cy.visit('https://example.com');
87
+ * });
88
+ */
89
+ step<T = void>(name: string, body: () => T | PromiseLike<T>): Cypress.Chainable<JQuery<void>>;
74
90
  };
package/dist/mocha.js CHANGED
@@ -104,3 +104,24 @@ exports.qase.comment = (value) => {
104
104
  //
105
105
  });
106
106
  };
107
+ /**
108
+ * Add a step to the test case
109
+ * @param {string} name
110
+ * @param {() => T | PromiseLike<T>} body
111
+ * @example
112
+ * it('test', () => {
113
+ * qase.step("Some step", () => {
114
+ * // some actions
115
+ * });
116
+ * cy.visit('https://example.com');
117
+ * });
118
+ */
119
+ exports.qase.step = (name, body) => {
120
+ return cy.task('qaseStepStart', name).then(() => {
121
+ return Cypress.Promise.resolve(body());
122
+ }).then(() => {
123
+ cy.task('qaseStepEnd', 'passed').then(() => {
124
+ //
125
+ });
126
+ });
127
+ };
@@ -70,5 +70,6 @@ export declare class CypressQaseReporter extends reporters.Base {
70
70
  * @private
71
71
  */
72
72
  private getFile;
73
+ private getSteps;
73
74
  }
74
75
  export {};
package/dist/reporter.js CHANGED
@@ -155,7 +155,7 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
155
155
  relations: relations,
156
156
  run_id: null,
157
157
  signature: this.getSignature(test, ids),
158
- steps: [],
158
+ steps: metadata?.steps ? this.getSteps(metadata.steps) : [],
159
159
  id: (0, uuid_1.v4)(),
160
160
  execution: {
161
161
  status: test.state
@@ -208,6 +208,43 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
208
208
  }
209
209
  return undefined;
210
210
  }
211
+ getSteps(steps) {
212
+ const result = [];
213
+ const stepMap = new Map();
214
+ for (const step of steps.sort((a, b) => a.timestamp - b.timestamp)) {
215
+ if (!('status' in step)) {
216
+ const newStep = new qase_javascript_commons_1.TestStepType();
217
+ newStep.id = step.id;
218
+ newStep.execution.status = qase_javascript_commons_1.StepStatusEnum.failed;
219
+ newStep.execution.start_time = step.timestamp;
220
+ newStep.execution.end_time = Date.now();
221
+ newStep.data = {
222
+ action: step.name,
223
+ expected_result: null,
224
+ };
225
+ const parentId = step.parentId;
226
+ if (parentId) {
227
+ newStep.parent_id = parentId;
228
+ const parent = stepMap.get(parentId);
229
+ if (parent) {
230
+ parent.steps.push(newStep);
231
+ }
232
+ }
233
+ else {
234
+ result.push(newStep);
235
+ }
236
+ stepMap.set(step.id, newStep);
237
+ }
238
+ else {
239
+ const stepType = stepMap.get(step.id);
240
+ if (stepType) {
241
+ stepType.execution.status = step.status;
242
+ stepType.execution.end_time = step.timestamp;
243
+ }
244
+ }
245
+ }
246
+ return result;
247
+ }
211
248
  }
212
249
  exports.CypressQaseReporter = CypressQaseReporter;
213
250
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-qase-reporter",
3
- "version": "2.2.0-beta.1",
3
+ "version": "2.2.0-beta.2",
4
4
  "description": "Qase Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,