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

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
@@ -4,21 +4,12 @@ Publish results simple and easy.
4
4
 
5
5
  ## Installation
6
6
 
7
- To install the latest release version (2.1.x), run:
7
+ To install the latest release version (2.2.x), run:
8
8
 
9
9
  ```sh
10
10
  npm install -D cypress-qase-reporter
11
11
  ```
12
12
 
13
- <!-- if there's no current beta, comment the next block
14
- -->
15
-
16
- To install the latest beta version (2.2.x), run:
17
-
18
- ```sh
19
- npm install -D cypress-qase-reporter@beta
20
- ```
21
-
22
13
  ## Updating from v1 to v2.1
23
14
 
24
15
  To update an existing test project using Qase reporter from version 1 to version 2.1,
package/changelog.md CHANGED
@@ -1,3 +1,27 @@
1
+ # cypress-qase-reporter@2.2.0
2
+
3
+ ## What's new
4
+
5
+ Minor release of the Cypress reporter package
6
+
7
+ # cypress-qase-reporter@2.2.0-beta.3
8
+
9
+ ## What's new
10
+
11
+ Added the ability to add attachments to tests or steps:
12
+
13
+ - `qase.attach` - add an attachment to test or step
14
+
15
+ ```ts
16
+ it('test', () => {
17
+ qase.attach({ paths: '/path/to/file' });
18
+ qase.step('Step 1', () => {
19
+ cy.visit('https://example.com');
20
+ qase.attach({ name: 'attachment.txt', content: 'Hello, world!', contentType: 'text/plain' });
21
+ });
22
+ });
23
+ ```
24
+
1
25
  # cypress-qase-reporter@2.2.0-beta.2
2
26
 
3
27
  ## What's new
@@ -1,9 +1,11 @@
1
- import { Metadata } from './models';
1
+ import { Attach, Metadata } from './models';
2
+ import { Attachment } from 'qase-javascript-commons';
2
3
  export declare class MetadataManager {
3
4
  static getMetadata(): Metadata | undefined;
4
5
  static setIgnore(): void;
5
6
  static addStepStart(name: string): void;
6
7
  static addStepEnd(status: string): void;
8
+ static addAttach(attach: Attach): void;
7
9
  static setSuite(suite: string): void;
8
10
  static setComment(comment: string): void;
9
11
  static setTitle(title: string): void;
@@ -13,4 +15,5 @@ export declare class MetadataManager {
13
15
  private static setMetadata;
14
16
  static clear(): void;
15
17
  static isExists(): boolean;
18
+ static prepareAttach(attach: Attach): Attachment[];
16
19
  }
@@ -1,8 +1,13 @@
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.MetadataManager = void 0;
4
7
  const fs_1 = require("fs");
5
8
  const uuid_1 = require("uuid");
9
+ const path_1 = __importDefault(require("path"));
10
+ const qase_javascript_commons_1 = require("qase-javascript-commons");
6
11
  const metadataPath = 'qaseMetadata';
7
12
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
8
13
  class MetadataManager {
@@ -21,6 +26,8 @@ class MetadataManager {
21
26
  steps: [],
22
27
  currentStepId: undefined,
23
28
  firstStepName: undefined,
29
+ attachments: [],
30
+ stepAttachments: {},
24
31
  };
25
32
  try {
26
33
  const data = (0, fs_1.readFileSync)(metadataPath, 'utf8');
@@ -64,6 +71,28 @@ class MetadataManager {
64
71
  metadata.currentStepId = parentId;
65
72
  this.setMetadata(metadata);
66
73
  }
74
+ static addAttach(attach) {
75
+ const metadata = this.getMetadata() ?? {};
76
+ if (!metadata.attachments) {
77
+ metadata.attachments = [];
78
+ }
79
+ if (!metadata.stepAttachments) {
80
+ metadata.stepAttachments = {};
81
+ }
82
+ const attachments = this.prepareAttach(attach);
83
+ if (metadata.currentStepId) {
84
+ if (metadata.stepAttachments[metadata.currentStepId] === undefined) {
85
+ metadata.stepAttachments[metadata.currentStepId] = attachments;
86
+ }
87
+ else {
88
+ metadata.stepAttachments[metadata.currentStepId]?.push(...attachments);
89
+ }
90
+ }
91
+ else {
92
+ metadata.attachments.push(...attachments);
93
+ }
94
+ this.setMetadata(metadata);
95
+ }
67
96
  static setSuite(suite) {
68
97
  const metadata = this.getMetadata() ?? {};
69
98
  metadata.suite = suite;
@@ -117,5 +146,47 @@ class MetadataManager {
117
146
  static isExists() {
118
147
  return (0, fs_1.existsSync)(metadataPath);
119
148
  }
149
+ static prepareAttach(attach) {
150
+ const attachments = [];
151
+ if (attach.paths) {
152
+ if (Array.isArray(attach.paths)) {
153
+ attach.paths.forEach((file) => {
154
+ const attachmentName = path_1.default.basename(file);
155
+ const contentType = (0, qase_javascript_commons_1.getMimeTypes)(file);
156
+ attachments.push({
157
+ file_name: attachmentName,
158
+ mime_type: contentType,
159
+ file_path: file,
160
+ content: '',
161
+ size: 0,
162
+ id: (0, uuid_1.v4)(),
163
+ });
164
+ });
165
+ }
166
+ else {
167
+ const attachmentName = path_1.default.basename(attach.paths);
168
+ const contentType = (0, qase_javascript_commons_1.getMimeTypes)(attach.paths);
169
+ attachments.push({
170
+ file_name: attachmentName,
171
+ mime_type: contentType,
172
+ file_path: attach.paths,
173
+ content: '',
174
+ size: 0,
175
+ id: (0, uuid_1.v4)(),
176
+ });
177
+ }
178
+ }
179
+ else if (attach.content) {
180
+ attachments.push({
181
+ file_name: attach.name ?? 'attachment',
182
+ mime_type: attach.contentType ?? 'application/octet-stream',
183
+ file_path: null,
184
+ content: attach.content,
185
+ size: 0,
186
+ id: (0, uuid_1.v4)(),
187
+ });
188
+ }
189
+ return attachments;
190
+ }
120
191
  }
121
192
  exports.MetadataManager = MetadataManager;
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ import { Attachment } from 'qase-javascript-commons';
1
3
  export interface Metadata {
2
4
  title?: string | undefined;
3
5
  fields?: Record<string, string>;
@@ -9,6 +11,8 @@ export interface Metadata {
9
11
  steps?: (StepStart | StepEnd)[];
10
12
  currentStepId?: string | undefined;
11
13
  firstStepName?: string | undefined;
14
+ attachments?: Attachment[];
15
+ stepAttachments?: Record<string, Attachment[]>;
12
16
  }
13
17
  export interface StepStart {
14
18
  id: string;
@@ -21,3 +25,9 @@ export interface StepEnd {
21
25
  timestamp: number;
22
26
  status: string;
23
27
  }
28
+ export interface Attach {
29
+ name?: string;
30
+ paths?: string | string[];
31
+ content?: Buffer | string;
32
+ contentType?: string;
33
+ }
package/dist/metadata.js CHANGED
@@ -56,4 +56,10 @@ module.exports = function (on) {
56
56
  return null;
57
57
  },
58
58
  });
59
+ on('task', {
60
+ qaseAttach(value) {
61
+ manager_1.MetadataManager.addAttach(value);
62
+ return null;
63
+ },
64
+ });
59
65
  };
package/dist/mocha.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  /// <reference types="cypress" />
3
3
  /// <reference types="cypress" />
4
4
  /// <reference types="cypress" />
5
+ /// <reference types="node" />
5
6
  import { Test } from 'mocha';
6
7
  export declare const qase: {
7
8
  (caseId: number | string | number[] | string[], test: Test): Test;
@@ -14,7 +15,7 @@ export declare const qase: {
14
15
  * cy.visit('https://example.com');
15
16
  * });
16
17
  */
17
- title(value: string): void;
18
+ title(value: string): Cypress.Chainable<JQuery<void>>;
18
19
  /**
19
20
  * Set fields for the test case
20
21
  * @param {Record<string, string>} values
@@ -24,7 +25,7 @@ export declare const qase: {
24
25
  * cy.visit('https://example.com');
25
26
  * });
26
27
  */
27
- fields(values: Record<string, string>): void;
28
+ fields(values: Record<string, string>): Cypress.Chainable<JQuery<void>>;
28
29
  /**
29
30
  * Ignore the test case result in Qase
30
31
  * @example
@@ -33,7 +34,7 @@ export declare const qase: {
33
34
  * cy.visit('https://example.com');
34
35
  * });
35
36
  */
36
- ignore(): void;
37
+ ignore(): Cypress.Chainable<JQuery<void>>;
37
38
  /**
38
39
  * Set parameters for the test case
39
40
  * @param {Record<string, string>} values
@@ -43,7 +44,7 @@ export declare const qase: {
43
44
  * cy.visit('https://example.com');
44
45
  * });
45
46
  */
46
- parameters(values: Record<string, string>): void;
47
+ parameters(values: Record<string, string>): Cypress.Chainable<JQuery<void>>;
47
48
  /**
48
49
  * Set group parameters for the test case
49
50
  * @param {Record<string, string>} values
@@ -53,7 +54,7 @@ export declare const qase: {
53
54
  * cy.visit('https://example.com');
54
55
  * });
55
56
  */
56
- groupParameters(values: Record<string, string>): void;
57
+ groupParameters(values: Record<string, string>): Cypress.Chainable<JQuery<void>>;
57
58
  /**
58
59
  * Set a suite for the test case
59
60
  * @param {string} value
@@ -63,7 +64,7 @@ export declare const qase: {
63
64
  * cy.visit('https://example.com');
64
65
  * });
65
66
  */
66
- suite(value: string): void;
67
+ suite(value: string): Cypress.Chainable<JQuery<void>>;
67
68
  /**
68
69
  * Set a comment for the test case
69
70
  * @param {string} value
@@ -73,7 +74,7 @@ export declare const qase: {
73
74
  * cy.visit('https://example.com');
74
75
  * });
75
76
  */
76
- comment(value: string): void;
77
+ comment(value: string): Cypress.Chainable<JQuery<void>>;
77
78
  /**
78
79
  * Add a step to the test case
79
80
  * @param {string} name
@@ -87,4 +88,21 @@ export declare const qase: {
87
88
  * });
88
89
  */
89
90
  step<T = void>(name: string, body: () => T | PromiseLike<T>): Cypress.Chainable<JQuery<void>>;
91
+ /**
92
+ * Attach a file to the test case or the step
93
+ * @param attach
94
+ * @example
95
+ * it('test', () => {
96
+ * qase.attach({ name: 'attachment.txt', content: 'Hello, world!', contentType: 'text/plain' });
97
+ * qase.attach({ paths: '/path/to/file'});
98
+ * qase.attach({ paths: ['/path/to/file', '/path/to/another/file']});
99
+ * cy.visit('https://example.com');
100
+ * });
101
+ */
102
+ attach(attach: {
103
+ name?: string;
104
+ paths?: string | string[];
105
+ content?: Buffer | string;
106
+ contentType?: string;
107
+ }): Cypress.Chainable<JQuery<void>>;
90
108
  };
package/dist/mocha.js CHANGED
@@ -17,7 +17,7 @@ exports.qase = qase;
17
17
  * });
18
18
  */
19
19
  exports.qase.title = (value) => {
20
- cy.task('qaseTitle', value).then(() => {
20
+ return cy.task('qaseTitle', value).then(() => {
21
21
  //
22
22
  });
23
23
  };
@@ -31,7 +31,7 @@ exports.qase.title = (value) => {
31
31
  * });
32
32
  */
33
33
  exports.qase.fields = (values) => {
34
- cy.task('qaseFields', values).then(() => {
34
+ return cy.task('qaseFields', values).then(() => {
35
35
  //
36
36
  });
37
37
  };
@@ -44,7 +44,7 @@ exports.qase.fields = (values) => {
44
44
  * });
45
45
  */
46
46
  exports.qase.ignore = () => {
47
- cy.task('qaseIgnore').then(() => {
47
+ return cy.task('qaseIgnore').then(() => {
48
48
  //
49
49
  });
50
50
  };
@@ -58,7 +58,7 @@ exports.qase.ignore = () => {
58
58
  * });
59
59
  */
60
60
  exports.qase.parameters = (values) => {
61
- cy.task('qaseParameters', values).then(() => {
61
+ return cy.task('qaseParameters', values).then(() => {
62
62
  //
63
63
  });
64
64
  };
@@ -72,7 +72,7 @@ exports.qase.parameters = (values) => {
72
72
  * });
73
73
  */
74
74
  exports.qase.groupParameters = (values) => {
75
- cy.task('qaseGroupParameters', values).then(() => {
75
+ return cy.task('qaseGroupParameters', values).then(() => {
76
76
  //
77
77
  });
78
78
  };
@@ -86,7 +86,7 @@ exports.qase.groupParameters = (values) => {
86
86
  * });
87
87
  */
88
88
  exports.qase.suite = (value) => {
89
- cy.task('qaseSuite', value).then(() => {
89
+ return cy.task('qaseSuite', value).then(() => {
90
90
  //
91
91
  });
92
92
  };
@@ -100,7 +100,7 @@ exports.qase.suite = (value) => {
100
100
  * });
101
101
  */
102
102
  exports.qase.comment = (value) => {
103
- cy.task('qaseComment', value).then(() => {
103
+ return cy.task('qaseComment', value).then(() => {
104
104
  //
105
105
  });
106
106
  };
@@ -125,3 +125,19 @@ exports.qase.step = (name, body) => {
125
125
  });
126
126
  });
127
127
  };
128
+ /**
129
+ * Attach a file to the test case or the step
130
+ * @param attach
131
+ * @example
132
+ * it('test', () => {
133
+ * qase.attach({ name: 'attachment.txt', content: 'Hello, world!', contentType: 'text/plain' });
134
+ * qase.attach({ paths: '/path/to/file'});
135
+ * qase.attach({ paths: ['/path/to/file', '/path/to/another/file']});
136
+ * cy.visit('https://example.com');
137
+ * });
138
+ */
139
+ exports.qase.attach = (attach) => {
140
+ return cy.task('qaseAttach', attach).then(() => {
141
+ //
142
+ });
143
+ };
package/dist/reporter.js CHANGED
@@ -107,6 +107,7 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
107
107
  const attachments = this.screenshotsFolder
108
108
  ? CypressQaseReporter.findAttachments(ids, this.screenshotsFolder)
109
109
  : undefined;
110
+ attachments?.push(...(metadata?.attachments ?? []));
110
111
  let relations = {};
111
112
  if (test.parent !== undefined) {
112
113
  const data = [];
@@ -155,7 +156,7 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
155
156
  relations: relations,
156
157
  run_id: null,
157
158
  signature: this.getSignature(test, ids),
158
- steps: metadata?.steps ? this.getSteps(metadata.steps) : [],
159
+ steps: metadata?.steps ? this.getSteps(metadata.steps, metadata.stepAttachments ?? {}) : [],
159
160
  id: (0, uuid_1.v4)(),
160
161
  execution: {
161
162
  status: test.state
@@ -208,7 +209,7 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
208
209
  }
209
210
  return undefined;
210
211
  }
211
- getSteps(steps) {
212
+ getSteps(steps, attachments) {
212
213
  const result = [];
213
214
  const stepMap = new Map();
214
215
  for (const step of steps.sort((a, b) => a.timestamp - b.timestamp)) {
@@ -222,6 +223,9 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
222
223
  action: step.name,
223
224
  expected_result: null,
224
225
  };
226
+ if (attachments[step.id]) {
227
+ newStep.attachments = attachments[step.id] ?? [];
228
+ }
225
229
  const parentId = step.parentId;
226
230
  if (parentId) {
227
231
  newStep.parent_id = parentId;
package/docs/usage.md ADDED
@@ -0,0 +1,196 @@
1
+ # Qase Integration in Cypress
2
+
3
+ This guide demonstrates how to integrate Qase with Cypress, providing instructions on how to add Qase IDs, titles,
4
+ fields, suites, comments, and file attachments to your test cases.
5
+
6
+ ---
7
+
8
+ ## Adding QaseID to a Test
9
+
10
+ To associate a QaseID with a test in Cypress, use the `qase` function. This function accepts a single integer
11
+ representing the test's ID in Qase.
12
+
13
+ ### Example:
14
+
15
+ ```javascript
16
+ import { qase } from 'cypress-qase-reporter/mocha';
17
+
18
+ qase(1, it('simple test', () => {
19
+ cy.visit('https://example.com');
20
+ }));
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Adding a Title to a Test
26
+
27
+ You can provide a title for your test using the `qase.title` function. The function accepts a string, which will be
28
+ used as the test's title in Qase. If no title is provided, the test method name will be used by default.
29
+
30
+ ### Example:
31
+
32
+ ```javascript
33
+ import { qase } from 'cypress-qase-reporter/mocha';
34
+
35
+ it('test', () => {
36
+ qase.title('Title');
37
+ cy.visit('https://example.com');
38
+ });
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Adding Fields to a Test
44
+
45
+ The `qase.fields` function allows you to add additional metadata to a test case. You can specify multiple fields to
46
+ enhance test case information in Qase.
47
+
48
+ ### System Fields:
49
+
50
+ - `description` — Description of the test case.
51
+ - `preconditions` — Preconditions for the test case.
52
+ - `postconditions` — Postconditions for the test case.
53
+ - `severity` — Severity of the test case (e.g., `critical`, `major`).
54
+ - `priority` — Priority of the test case (e.g., `high`, `low`).
55
+ - `layer` — Test layer (e.g., `UI`, `API`).
56
+
57
+ ### Example:
58
+
59
+ ```javascript
60
+ import { qase } from 'cypress-qase-reporter/mocha';
61
+
62
+ it('test', () => {
63
+ qase.fields({ description: "Description", preconditions: "Preconditions" });
64
+ cy.visit('https://example.com');
65
+ });
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Adding a Suite to a Test
71
+
72
+ To assign a suite or sub-suite to a test, use the `qase.suite` function. It can receive a suite name, and optionally a
73
+ sub-suite, both as strings.
74
+
75
+ ### Example:
76
+
77
+ ```javascript
78
+ import { qase } from 'cypress-qase-reporter/mocha';
79
+
80
+ it('test', () => {
81
+ qase.suite("Suite 01");
82
+ cy.visit('https://example.com');
83
+ });
84
+
85
+ it('test', () => {
86
+ qase.suite("Suite 01\tSuite 02");
87
+ cy.visit('https://example.com');
88
+ });
89
+ ```
90
+
91
+ ---
92
+
93
+ ## Ignoring a Test in Qase
94
+
95
+ To exclude a test from being reported to Qase (while still executing the test in Cypress), use the `qase.ignore`
96
+ function. The test will run, but its result will not be sent to Qase.
97
+
98
+ ### Example:
99
+
100
+ ```javascript
101
+ import { qase } from 'cypress-qase-reporter/mocha';
102
+
103
+ it('test', () => {
104
+ qase.ignore();
105
+ cy.visit('https://example.com');
106
+ });
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Adding a Comment to a Test
112
+
113
+ You can attach comments to the test results in Qase using the `qase.comment` function. The comment will be displayed
114
+ alongside the test execution details in Qase.
115
+
116
+ ### Example:
117
+
118
+ ```javascript
119
+ import { qase } from 'cypress-qase-reporter/mocha';
120
+
121
+ it('test', () => {
122
+ qase.comment("Some comment");
123
+ cy.visit('https://example.com');
124
+ });
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Attaching Files to a Test
130
+
131
+ To attach files to a test result, use the `qase.attach` function. This method supports attaching one or multiple files,
132
+ along with optional file names, comments, and file types.
133
+
134
+ ### Example:
135
+
136
+ ```javascript
137
+ import { qase } from 'cypress-qase-reporter/mocha';
138
+
139
+ it('test', () => {
140
+ qase.attach({ name: 'attachment.txt', content: 'Hello, world!', contentType: 'text/plain' });
141
+ qase.attach({ paths: '/path/to/file' });
142
+ qase.attach({ paths: ['/path/to/file', '/path/to/another/file'] });
143
+ cy.visit('https://example.com');
144
+ });
145
+ ```
146
+
147
+ ## Adding Parameters to a Test
148
+
149
+ You can add parameters to a test case using the `qase.parameters` function. This function accepts an object with
150
+ parameter names and values.
151
+
152
+ ### Example:
153
+
154
+ ```javascript
155
+ import { qase } from 'cypress-qase-reporter/mocha';
156
+
157
+ it('test', () => {
158
+ qase.parameters({ param1: 'value1', param2: 'value2' });
159
+ cy.visit('https://example.com');
160
+ });
161
+ ```
162
+
163
+ ## Adding Group Parameters to a Test
164
+
165
+ To add group parameters to a test case, use the `qase.groupParameters` function. This function accepts an list with
166
+ group parameter names.
167
+
168
+ ### Example:
169
+
170
+ ```javascript
171
+ import { qase } from 'cypress-qase-reporter/mocha';
172
+
173
+ it('test', () => {
174
+ qase.parameters({ param1: 'value1', param2: 'value2' });
175
+ qase.groupParameters(['param1']);
176
+ cy.visit('https://example.com');
177
+ });
178
+ ```
179
+
180
+ ## Adding Steps to a Test
181
+
182
+ You can add steps to a test case using the `qase.step` function. This function accepts a string, which will be used as
183
+ the step description in Qase.
184
+
185
+ ### Example:
186
+
187
+ ```javascript
188
+ import { qase } from 'cypress-qase-reporter/mocha';
189
+
190
+ it('test', () => {
191
+ qase.step('Some step', () => {
192
+ // some actions
193
+ });
194
+ cy.visit('https://example.com');
195
+ });
196
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-qase-reporter",
3
- "version": "2.2.0-beta.2",
3
+ "version": "2.2.0",
4
4
  "description": "Qase Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,