cucumberjs-qase-reporter 2.0.2 → 2.0.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
+ # qase-cucumberjs@2.0.3
2
+
3
+ ## What's new
4
+
5
+ Support attachments in the test results.
6
+
7
+ ```js
8
+ const { Given, Then } = require('cucumber');
9
+
10
+ Given('I have a step with attachment', async function () {
11
+ await this.attach('Hello, world!', 'text/plain');
12
+ });
13
+
14
+ Then('I have a step with attachment', async function () {
15
+ await this.attach('Hello, world!', 'text/plain');
16
+ });
17
+ ```
18
+
1
19
  # qase-cucumberjs@2.0.2
2
20
 
3
21
  ## What's new
package/dist/storage.d.ts CHANGED
@@ -104,5 +104,6 @@ export declare class Storage {
104
104
  */
105
105
  private getSignature;
106
106
  private getError;
107
+ private getFileNameFromMediaType;
107
108
  }
108
109
  export {};
package/dist/storage.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Storage = void 0;
4
4
  const qase_javascript_commons_1 = require("qase-javascript-commons");
5
5
  const cucumber_1 = require("@cucumber/cucumber");
6
+ const uuid_1 = require("uuid");
6
7
  const qaseIdRegExp = /^@[Qq]-?(\d+)$/g;
7
8
  const newQaseIdRegExp = /^@[Qq]ase[Ii][Dd]=(\d+)$/g;
8
9
  const qaseTitleRegExp = /^@[Qq]ase[Tt]itle=(.+)$/g;
@@ -77,17 +78,17 @@ class Storage {
77
78
  * @param {Attach} attachment
78
79
  */
79
80
  addAttachment(attachment) {
80
- if (attachment.testCaseStartedId && attachment.fileName) {
81
- if (!this.attachments[attachment.testCaseStartedId]) {
82
- this.attachments[attachment.testCaseStartedId] = [];
81
+ if (attachment.testStepId) {
82
+ if (!this.attachments[attachment.testStepId]) {
83
+ this.attachments[attachment.testStepId] = [];
83
84
  }
84
- this.attachments[attachment.testCaseStartedId]?.push({
85
- file_name: attachment.fileName,
85
+ this.attachments[attachment.testStepId]?.push({
86
+ file_name: this.getFileNameFromMediaType(attachment.mediaType),
86
87
  mime_type: attachment.mediaType,
87
88
  file_path: null,
88
89
  content: attachment.body,
89
90
  size: 0,
90
- id: attachment.fileName,
91
+ id: (0, uuid_1.v4)(),
91
92
  });
92
93
  }
93
94
  }
@@ -227,7 +228,7 @@ class Storage {
227
228
  end_time: null,
228
229
  duration: finished.testStepResult.duration.seconds,
229
230
  },
230
- attachments: [],
231
+ attachments: this.attachments[s.id] ?? [],
231
232
  steps: [],
232
233
  parent_id: null,
233
234
  };
@@ -298,6 +299,30 @@ class Storage {
298
299
  });
299
300
  return error;
300
301
  }
302
+ getFileNameFromMediaType(mediaType) {
303
+ const extensions = {
304
+ 'text/plain': 'txt',
305
+ 'application/json': 'json',
306
+ 'image/png': 'png',
307
+ 'image/jpeg': 'jpg',
308
+ 'image/gif': 'gif',
309
+ 'text/html': 'html',
310
+ 'application/pdf': 'pdf',
311
+ 'application/xml': 'xml',
312
+ 'application/zip': 'zip',
313
+ 'application/msword': 'doc',
314
+ 'application/vnd.ms-excel': 'xls',
315
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
316
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
317
+ };
318
+ const extension = extensions[mediaType];
319
+ if (extension) {
320
+ return `file.${extension}`;
321
+ }
322
+ else {
323
+ return 'file';
324
+ }
325
+ }
301
326
  }
302
327
  exports.Storage = Storage;
303
328
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cucumberjs-qase-reporter",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Qase TMS CucumberJS Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "main": "./dist/index.js",
@@ -49,6 +49,7 @@
49
49
  "@jest/globals": "^29.5.0",
50
50
  "@types/jest": "^29.5.2",
51
51
  "jest": "^29.5.0",
52
- "ts-jest": "^29.1.0"
52
+ "ts-jest": "^29.1.0",
53
+ "uuid": "^9.0.0"
53
54
  }
54
55
  }