@qavajs/format-report-portal 0.0.7 → 0.9.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/CHANGELOG.MD CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.9.0
2
+ - :rocket: implemented capability to add attributes to test
3
+
4
+ ## 0.0.8
5
+ - :beetle: fixed sending duration
6
+
1
7
  ## 0.0.7
2
8
  - :beetle: implemented sending real step duration
3
9
 
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,21 +77,28 @@ 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.reduce((attachments, step) => {
82
+ const attrs = step.attachment
83
+ .filter(isAttribute)
84
+ .map(attachment => attachment.body.replace(RP_ATTRIBUTE_PREFIX, ''));
85
+ return [...new Set([...attachments, ...attrs])]
86
+ }, []);
87
+ // Start test
77
88
  const testItem = this.rpClient.startTestItem({
78
89
  description: this.formatTags(testCase.pickle.tags),
79
90
  name: testCase.pickle.name,
80
91
  startTime,
81
- type: 'STEP'
92
+ type: 'STEP',
93
+ attributes
82
94
  }, this.launchId, featureTempId);
83
95
  this.promiseQ.push(testItem.promise);
84
96
  await testItem.promise;
85
97
 
86
98
  //send steps
87
- const steps = this.getStepResults(testCase)
88
99
  for (const step of steps) {
89
100
  const duration = step.result.duration;
90
- endTime = startTime + (duration.seconds * 1000) + Math.floor(duration.nanos / 1000);
101
+ endTime = startTime + (duration.seconds * 1_000) + Math.floor(duration.nanos / 1_000_000);
91
102
  const nestedTestItem = this.rpClient.startTestItem({
92
103
  description: 'test description',
93
104
  name: this.getStepText(step, steps),
@@ -136,7 +147,7 @@ class RPFormatter extends Formatter {
136
147
  return testCase.testCase.testSteps.map(step => ({
137
148
  result: testCase.stepResults[step.id],
138
149
  pickle: testCase.pickle.steps.find(pickle => pickle.id === step.pickleStepId),
139
- attachment: testCase.stepAttachments[step.id]
150
+ attachment: testCase.stepAttachments[step.id] ?? []
140
151
  }))
141
152
  }
142
153
 
@@ -194,6 +205,7 @@ class RPFormatter extends Formatter {
194
205
 
195
206
  async sendAttachment(attachment, testItem, startTime) {
196
207
  let log;
208
+ if (attachment.mediaType === 'text/x.cucumber.log+plain' && RP_ATTRIBUTE_PREFIX.test(attachment.body)) return;
197
209
  if (attachment.mediaType === 'text/x.cucumber.log+plain') {
198
210
  log = await this.rpClient.sendLog(testItem.tempId, {
199
211
  level: 'INFO',
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@qavajs/format-report-portal",
3
- "version": "0.0.7",
3
+ "version": "0.9.0",
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
  }