@qavajs/format-report-portal 0.0.8 → 0.9.1

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,6 @@
1
+ ## 0.9.0
2
+ - :rocket: implemented capability to add attributes to test
3
+
1
4
  ## 0.0.8
2
5
  - :beetle: fixed sending duration
3
6
 
package/README.MD CHANGED
@@ -1,10 +1,10 @@
1
1
  ## @qavajs/format-report-portal
2
2
  This package is formatter for EPAM report portal
3
3
 
4
- ### install
4
+ ### Install
5
5
  `npm install @qavajs/format-report-portal`
6
6
 
7
- ### configuration
7
+ ### Configuration
8
8
 
9
9
  add formatter to config.js
10
10
  ```javascript
@@ -31,7 +31,19 @@ module.exports = {
31
31
  ```
32
32
  Option `enable` is set to `true` even if it is not defined explicitly in rpConfig section.
33
33
 
34
- ### run e2e test
34
+ ### Test Level Attributes
35
+ Test level attributes can be added via cucumber logs e.g. in Before hook
36
+ ```javascript
37
+ const { Before } = require('@cucumber/cucumber');
38
+
39
+ Before(function () {
40
+ this.log('log from before'); //just log
41
+ this.log(`rp_attribute: fixed:42`); //static attribute
42
+ this.log(`rp_attribute: random:${Date.now()}`); //dynamic attribute
43
+ });
44
+ ```
45
+
46
+ ### Run E2E Test
35
47
  add token.json file with rp token and other config
36
48
  run
37
49
  `npm run test-e2e`
package/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  const { Formatter, Status } = require('@cucumber/cucumber');
2
2
  const RPClient = require('@reportportal/client-javascript');
3
+
4
+ const RP_ATTRIBUTE_PREFIX = /^rp_attribute:\s*/;
5
+ const isAttribute = (attachment) => attachment.mediaType === 'text/x.cucumber.log+plain' && RP_ATTRIBUTE_PREFIX.test(attachment.body)
6
+
3
7
  class RPFormatter extends Formatter {
4
8
  launchId = null;
5
9
 
@@ -73,18 +77,33 @@ class RPFormatter extends Formatter {
73
77
  const featureTempId = this.features[featureName];
74
78
  let startTime = this.rpClient.helpers.now();
75
79
  let endTime;
76
- // Start test item
80
+ const steps = this.getStepResults(testCase);
81
+ const attributes = steps
82
+ .reduce((attachments, step) => {
83
+ const attrs = step.attachment
84
+ .filter(isAttribute)
85
+ .map(attachment => attachment.body.replace(RP_ATTRIBUTE_PREFIX, ''));
86
+ return [...new Set([...attachments, ...attrs])]
87
+ }, [])
88
+ .map(attachment => {
89
+ const [key, value] = attachment.split(':');
90
+ return key && value
91
+ ? { key, value, system: false }
92
+ : { value: key, system: false }
93
+ });
94
+
95
+ // Start test
77
96
  const testItem = this.rpClient.startTestItem({
78
97
  description: this.formatTags(testCase.pickle.tags),
79
98
  name: testCase.pickle.name,
80
99
  startTime,
81
- type: 'STEP'
100
+ type: 'STEP',
101
+ attributes
82
102
  }, this.launchId, featureTempId);
83
103
  this.promiseQ.push(testItem.promise);
84
104
  await testItem.promise;
85
105
 
86
106
  //send steps
87
- const steps = this.getStepResults(testCase)
88
107
  for (const step of steps) {
89
108
  const duration = step.result.duration;
90
109
  endTime = startTime + (duration.seconds * 1_000) + Math.floor(duration.nanos / 1_000_000);
@@ -136,7 +155,7 @@ class RPFormatter extends Formatter {
136
155
  return testCase.testCase.testSteps.map(step => ({
137
156
  result: testCase.stepResults[step.id],
138
157
  pickle: testCase.pickle.steps.find(pickle => pickle.id === step.pickleStepId),
139
- attachment: testCase.stepAttachments[step.id]
158
+ attachment: testCase.stepAttachments[step.id] ?? []
140
159
  }))
141
160
  }
142
161
 
@@ -157,6 +176,7 @@ class RPFormatter extends Formatter {
157
176
  const stepsBefore = steps.slice(0, steps.findIndex((element) => element === step));
158
177
  return stepsBefore.every(element => element.pickle === undefined) ? 'Before' : 'After'
159
178
  }
179
+
160
180
  getMessage(step) {
161
181
  return step.result.message
162
182
  }
@@ -194,6 +214,7 @@ class RPFormatter extends Formatter {
194
214
 
195
215
  async sendAttachment(attachment, testItem, startTime) {
196
216
  let log;
217
+ if (attachment.mediaType === 'text/x.cucumber.log+plain' && RP_ATTRIBUTE_PREFIX.test(attachment.body)) return;
197
218
  if (attachment.mediaType === 'text/x.cucumber.log+plain') {
198
219
  log = await this.rpClient.sendLog(testItem.tempId, {
199
220
  level: 'INFO',
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@qavajs/format-report-portal",
3
- "version": "0.0.8",
3
+ "version": "0.9.1",
4
4
  "description": "cucumber formatter for report portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test-e2e": "qavajs run --config test-e2e/config.js"
7
+ "test:e2e": "qavajs run --config test-e2e/config.js"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -20,11 +20,11 @@
20
20
  },
21
21
  "homepage": "https://github.com/qavajs/format-report-portal#readme",
22
22
  "dependencies": {
23
- "@reportportal/client-javascript": "^5.0.8"
23
+ "@reportportal/client-javascript": "^5.0.10"
24
24
  },
25
25
  "devDependencies": {
26
- "@cucumber/cucumber": "^9.1.0",
27
- "@qavajs/cli": "^0.0.21",
28
- "@qavajs/memory": "^1.3.0"
26
+ "@cucumber/cucumber": "^9.1.2",
27
+ "@qavajs/cli": "^0.0.24",
28
+ "@qavajs/memory": "^1.4.1"
29
29
  }
30
30
  }