cucumberjs-qase-reporter 2.0.2 → 2.0.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,27 @@
1
+ # qase-cucumberjs@2.0.4
2
+
3
+ ## What's new
4
+
5
+ Fixed the issue with the `QaseFields` tag.
6
+
7
+ # qase-cucumberjs@2.0.3
8
+
9
+ ## What's new
10
+
11
+ Support attachments in the test results.
12
+
13
+ ```js
14
+ const { Given, Then } = require('cucumber');
15
+
16
+ Given('I have a step with attachment', async function() {
17
+ await this.attach('Hello, world!', 'text/plain');
18
+ });
19
+
20
+ Then('I have a step with attachment', async function() {
21
+ await this.attach('Hello, world!', 'text/plain');
22
+ });
23
+ ```
24
+
1
25
  # qase-cucumberjs@2.0.2
2
26
 
3
27
  ## What's new
package/dist/reporter.js CHANGED
@@ -9,6 +9,21 @@ const storage_1 = require("./storage");
9
9
  * @extends Formatter
10
10
  */
11
11
  class CucumberQaseReporter extends cucumber_1.Formatter {
12
+ /**
13
+ * @type {Record<string, string>}
14
+ * @private
15
+ */
16
+ storage;
17
+ /**
18
+ * @type {ReporterInterface}
19
+ * @private
20
+ */
21
+ reporter;
22
+ /**
23
+ * @type {EventEmitter}
24
+ * @private
25
+ */
26
+ eventBroadcaster;
12
27
  /**
13
28
  * @param {CucumberQaseOptionsType} options
14
29
  * @param {ConfigLoaderInterface} configLoader
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,54 +3,53 @@ 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;
9
- const qaseFieldsRegExp = /^@[Qq]ase[Ff]ields:(.+?)=(.+)$/g;
10
+ const qaseFieldsRegExp = /^@[Qq]ase[Ff]ields=(.+)$/g;
10
11
  const qaseIgnoreRegExp = /^@[Qq]ase[Ii][Gg][Nn][Oo][Rr][Ee]$/g;
11
12
  class Storage {
12
- constructor() {
13
- /**
14
- * @type {Record<string, Pickle>}
15
- * @private
16
- */
17
- this.pickles = {};
18
- /**
19
- * @type {Record<string, TestCaseStarted>}
20
- * @private
21
- */
22
- this.testCaseStarts = {};
23
- /**
24
- * @type {Record<string, TestStepFinished>}
25
- * @private
26
- */
27
- this.testCaseSteps = {};
28
- /**
29
- * @type {Record<string, TestStatusEnum>}
30
- * @private
31
- */
32
- this.testCaseStartedResult = {};
33
- /**
34
- * @type {Record<string, string[]>}
35
- * @private
36
- */
37
- this.testCaseStartedErrors = {};
38
- /**
39
- * @type {Record<string, string>}
40
- * @private
41
- */
42
- this.testCases = {};
43
- /**
44
- * @type {Record<string, string>}
45
- * @private
46
- */
47
- this.scenarios = {};
48
- /**
49
- * @type {Record<string, string>}
50
- * @private
51
- */
52
- this.attachments = {};
53
- }
13
+ /**
14
+ * @type {Record<string, Pickle>}
15
+ * @private
16
+ */
17
+ pickles = {};
18
+ /**
19
+ * @type {Record<string, TestCaseStarted>}
20
+ * @private
21
+ */
22
+ testCaseStarts = {};
23
+ /**
24
+ * @type {Record<string, TestStepFinished>}
25
+ * @private
26
+ */
27
+ testCaseSteps = {};
28
+ /**
29
+ * @type {Record<string, TestStatusEnum>}
30
+ * @private
31
+ */
32
+ testCaseStartedResult = {};
33
+ /**
34
+ * @type {Record<string, string[]>}
35
+ * @private
36
+ */
37
+ testCaseStartedErrors = {};
38
+ /**
39
+ * @type {Record<string, string>}
40
+ * @private
41
+ */
42
+ testCases = {};
43
+ /**
44
+ * @type {Record<string, string>}
45
+ * @private
46
+ */
47
+ scenarios = {};
48
+ /**
49
+ * @type {Record<string, string>}
50
+ * @private
51
+ */
52
+ attachments = {};
54
53
  /**
55
54
  * Add pickle to storage
56
55
  * @param {Pickle} pickle
@@ -77,17 +76,17 @@ class Storage {
77
76
  * @param {Attach} attachment
78
77
  */
79
78
  addAttachment(attachment) {
80
- if (attachment.testCaseStartedId && attachment.fileName) {
81
- if (!this.attachments[attachment.testCaseStartedId]) {
82
- this.attachments[attachment.testCaseStartedId] = [];
79
+ if (attachment.testStepId) {
80
+ if (!this.attachments[attachment.testStepId]) {
81
+ this.attachments[attachment.testStepId] = [];
83
82
  }
84
- this.attachments[attachment.testCaseStartedId]?.push({
85
- file_name: attachment.fileName,
83
+ this.attachments[attachment.testStepId]?.push({
84
+ file_name: this.getFileNameFromMediaType(attachment.mediaType),
86
85
  mime_type: attachment.mediaType,
87
86
  file_path: null,
88
87
  content: attachment.body,
89
88
  size: 0,
90
- id: attachment.fileName,
89
+ id: (0, uuid_1.v4)(),
91
90
  });
92
91
  }
93
92
  }
@@ -227,7 +226,7 @@ class Storage {
227
226
  end_time: null,
228
227
  duration: finished.testStepResult.duration.seconds,
229
228
  },
230
- attachments: [],
229
+ attachments: this.attachments[s.id] ?? [],
231
230
  steps: [],
232
231
  parent_id: null,
233
232
  };
@@ -235,6 +234,30 @@ class Storage {
235
234
  }
236
235
  return results;
237
236
  }
237
+ /**
238
+ * @type {Record<TestStepResultStatus, TestStatusEnum>}
239
+ */
240
+ static statusMap = {
241
+ [cucumber_1.Status.PASSED]: qase_javascript_commons_1.TestStatusEnum.passed,
242
+ [cucumber_1.Status.FAILED]: qase_javascript_commons_1.TestStatusEnum.failed,
243
+ [cucumber_1.Status.SKIPPED]: qase_javascript_commons_1.TestStatusEnum.skipped,
244
+ [cucumber_1.Status.AMBIGUOUS]: qase_javascript_commons_1.TestStatusEnum.failed,
245
+ [cucumber_1.Status.PENDING]: qase_javascript_commons_1.TestStatusEnum.skipped,
246
+ [cucumber_1.Status.UNDEFINED]: qase_javascript_commons_1.TestStatusEnum.skipped,
247
+ [cucumber_1.Status.UNKNOWN]: qase_javascript_commons_1.TestStatusEnum.skipped,
248
+ };
249
+ /**
250
+ * @type {Record<TestStepResultStatus, StepStatusEnum>}
251
+ */
252
+ static stepStatusMap = {
253
+ [cucumber_1.Status.PASSED]: qase_javascript_commons_1.StepStatusEnum.passed,
254
+ [cucumber_1.Status.FAILED]: qase_javascript_commons_1.StepStatusEnum.failed,
255
+ [cucumber_1.Status.SKIPPED]: qase_javascript_commons_1.StepStatusEnum.skipped,
256
+ [cucumber_1.Status.AMBIGUOUS]: qase_javascript_commons_1.StepStatusEnum.failed,
257
+ [cucumber_1.Status.PENDING]: qase_javascript_commons_1.StepStatusEnum.skipped,
258
+ [cucumber_1.Status.UNDEFINED]: qase_javascript_commons_1.StepStatusEnum.skipped,
259
+ [cucumber_1.Status.UNKNOWN]: qase_javascript_commons_1.StepStatusEnum.skipped,
260
+ };
238
261
  parseTags(tags) {
239
262
  const metadata = {
240
263
  ids: [],
@@ -256,7 +279,7 @@ class Storage {
256
279
  continue;
257
280
  }
258
281
  if (qaseFieldsRegExp.test(tag.name)) {
259
- const value = tag.name.replace(/^@[Qq]ase[Ff]ields:/, '');
282
+ const value = tag.name.replace(/^@[Qq]ase[Ff]ields=/, '');
260
283
  try {
261
284
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
262
285
  const record = JSON.parse(value);
@@ -298,29 +321,29 @@ class Storage {
298
321
  });
299
322
  return error;
300
323
  }
324
+ getFileNameFromMediaType(mediaType) {
325
+ const extensions = {
326
+ 'text/plain': 'txt',
327
+ 'application/json': 'json',
328
+ 'image/png': 'png',
329
+ 'image/jpeg': 'jpg',
330
+ 'image/gif': 'gif',
331
+ 'text/html': 'html',
332
+ 'application/pdf': 'pdf',
333
+ 'application/xml': 'xml',
334
+ 'application/zip': 'zip',
335
+ 'application/msword': 'doc',
336
+ 'application/vnd.ms-excel': 'xls',
337
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
338
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
339
+ };
340
+ const extension = extensions[mediaType];
341
+ if (extension) {
342
+ return `file.${extension}`;
343
+ }
344
+ else {
345
+ return 'file';
346
+ }
347
+ }
301
348
  }
302
349
  exports.Storage = Storage;
303
- /**
304
- * @type {Record<TestStepResultStatus, TestStatusEnum>}
305
- */
306
- Storage.statusMap = {
307
- [cucumber_1.Status.PASSED]: qase_javascript_commons_1.TestStatusEnum.passed,
308
- [cucumber_1.Status.FAILED]: qase_javascript_commons_1.TestStatusEnum.failed,
309
- [cucumber_1.Status.SKIPPED]: qase_javascript_commons_1.TestStatusEnum.skipped,
310
- [cucumber_1.Status.AMBIGUOUS]: qase_javascript_commons_1.TestStatusEnum.failed,
311
- [cucumber_1.Status.PENDING]: qase_javascript_commons_1.TestStatusEnum.skipped,
312
- [cucumber_1.Status.UNDEFINED]: qase_javascript_commons_1.TestStatusEnum.skipped,
313
- [cucumber_1.Status.UNKNOWN]: qase_javascript_commons_1.TestStatusEnum.skipped,
314
- };
315
- /**
316
- * @type {Record<TestStepResultStatus, StepStatusEnum>}
317
- */
318
- Storage.stepStatusMap = {
319
- [cucumber_1.Status.PASSED]: qase_javascript_commons_1.StepStatusEnum.passed,
320
- [cucumber_1.Status.FAILED]: qase_javascript_commons_1.StepStatusEnum.failed,
321
- [cucumber_1.Status.SKIPPED]: qase_javascript_commons_1.StepStatusEnum.skipped,
322
- [cucumber_1.Status.AMBIGUOUS]: qase_javascript_commons_1.StepStatusEnum.failed,
323
- [cucumber_1.Status.PENDING]: qase_javascript_commons_1.StepStatusEnum.skipped,
324
- [cucumber_1.Status.UNDEFINED]: qase_javascript_commons_1.StepStatusEnum.skipped,
325
- [cucumber_1.Status.UNKNOWN]: qase_javascript_commons_1.StepStatusEnum.skipped,
326
- };
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.4",
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
  }