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

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,21 @@
1
+ # cypress-qase-reporter@2.2.0-beta.3
2
+
3
+ ## What's new
4
+
5
+ Added the ability to add attachments to tests or steps:
6
+
7
+ - `qase.attach` - add an attachment to test or step
8
+
9
+ ```ts
10
+ it('test', () => {
11
+ qase.attach({ paths: '/path/to/file' });
12
+ qase.step('Step 1', () => {
13
+ cy.visit('https://example.com');
14
+ qase.attach({ name: 'attachment.txt', content: 'Hello, world!', contentType: 'text/plain' });
15
+ });
16
+ });
17
+ ```
18
+
1
19
  # cypress-qase-reporter@2.2.0-beta.2
2
20
 
3
21
  ## 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/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-beta.3",
4
4
  "description": "Qase Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,