@qavajs/format-report-portal 0.9.0 → 0.9.2

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.2
2
+ - :beetle: added capability to ignore errors
3
+
4
+ ## 0.9.1
5
+ - :beetle: added request retry in case of error
6
+
1
7
  ## 0.9.0
2
8
  - :rocket: implemented capability to add attributes to test
3
9
 
package/README.MD CHANGED
@@ -23,7 +23,9 @@ module.exports = {
23
23
  tags: ['Tag'],
24
24
  project: 'your project',
25
25
  launch: 'your launch name',
26
- mode: 'DEFAULT'
26
+ mode: 'DEFAULT',
27
+ retry: 1, // number of retries to send result to report portal (default - 1)
28
+ ignoreErrors: false // ignore RP errors (default: false)
27
29
  },
28
30
  }
29
31
  }
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const { Formatter, Status } = require('@cucumber/cucumber');
2
2
  const RPClient = require('@reportportal/client-javascript');
3
+ const { retry } = require('./utils');
3
4
 
4
5
  const RP_ATTRIBUTE_PREFIX = /^rp_attribute:\s*/;
5
6
  const isAttribute = (attachment) => attachment.mediaType === 'text/x.cucumber.log+plain' && RP_ATTRIBUTE_PREFIX.test(attachment.body)
@@ -18,14 +19,22 @@ class RPFormatter extends Formatter {
18
19
  }
19
20
 
20
21
  async processEnvelope(envelope) {
21
- if (envelope.testRunStarted) {
22
- await this.startLaunch();
23
- }
24
- else if (envelope.testRunFinished) {
25
- await this.finishLaunch();
26
- }
27
- else if (envelope.testCaseFinished) {
28
- await this.finishTest(envelope);
22
+ try {
23
+ if (envelope.testRunStarted) {
24
+ await this.startLaunch();
25
+ }
26
+ else if (envelope.testRunFinished) {
27
+ await this.finishLaunch();
28
+ }
29
+ else if (envelope.testCaseFinished) {
30
+ await this.finishTest(envelope);
31
+ }
32
+ } catch (err) {
33
+ if (this.rpConfig.ignoreErrors) {
34
+ console.error(err);
35
+ } else {
36
+ throw err;
37
+ }
29
38
  }
30
39
  }
31
40
 
@@ -60,75 +69,99 @@ class RPFormatter extends Formatter {
60
69
  const testCase = this.eventDataCollector.getTestCaseAttempt(envelope.testCaseFinished.testCaseStartedId);
61
70
  const featureName = testCase.gherkinDocument.feature.name;
62
71
  if (!this.features[featureName]) {
63
- const featureItem = this.rpClient.startTestItem({
64
- description:
65
- this.formatTags(testCase.gherkinDocument.feature.tags) +
66
- '\n' +
67
- testCase.gherkinDocument.feature.description,
68
- name: featureName,
69
- startTime: this.rpClient.helpers.now(),
70
- type: 'SUITE'
71
- }, this.launchId);
72
- this.features[featureName] = featureItem.tempId;
73
- this.promiseQ.push(featureItem.promise);
74
- await featureItem.promise;
72
+ await retry(async () => {
73
+ const featureItem = this.rpClient.startTestItem({
74
+ description:
75
+ this.formatTags(testCase.gherkinDocument.feature.tags) +
76
+ '\n' +
77
+ testCase.gherkinDocument.feature.description,
78
+ name: featureName,
79
+ startTime: this.rpClient.helpers.now(),
80
+ type: 'SUITE'
81
+ }, this.launchId);
82
+ this.features[featureName] = featureItem.tempId;
83
+ this.promiseQ.push(featureItem.promise);
84
+ await featureItem.promise;
85
+ }, this.rpConfig.retry);
75
86
  }
76
87
 
77
88
  const featureTempId = this.features[featureName];
78
89
  let startTime = this.rpClient.helpers.now();
79
90
  let endTime;
80
91
  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
- }, []);
92
+ const attributes = steps
93
+ .reduce((attachments, step) => {
94
+ const attrs = step.attachment
95
+ .filter(isAttribute)
96
+ .map(attachment => attachment.body.replace(RP_ATTRIBUTE_PREFIX, ''));
97
+ return [...new Set([...attachments, ...attrs])]
98
+ }, [])
99
+ .map(attachment => {
100
+ const [key, value] = attachment.split(':');
101
+ return key && value
102
+ ? { key, value, system: false }
103
+ : { value: key, system: false }
104
+ });
105
+
87
106
  // Start test
88
- const testItem = this.rpClient.startTestItem({
89
- description: this.formatTags(testCase.pickle.tags),
90
- name: testCase.pickle.name,
91
- startTime,
92
- type: 'STEP',
93
- attributes
94
- }, this.launchId, featureTempId);
95
- this.promiseQ.push(testItem.promise);
96
- await testItem.promise;
107
+ const testItem = await retry(async () => {
108
+ const testItem = this.rpClient.startTestItem({
109
+ description: this.formatTags(testCase.pickle.tags),
110
+ name: testCase.pickle.name,
111
+ startTime,
112
+ type: 'STEP',
113
+ attributes
114
+ }, this.launchId, featureTempId);
115
+ this.promiseQ.push(testItem.promise);
116
+ await testItem.promise;
117
+ return testItem;
118
+ }, this.rpConfig.retry);
97
119
 
98
120
  //send steps
99
121
  for (const step of steps) {
100
122
  const duration = step.result.duration;
101
123
  endTime = startTime + (duration.seconds * 1_000) + Math.floor(duration.nanos / 1_000_000);
102
- const nestedTestItem = this.rpClient.startTestItem({
103
- description: 'test description',
104
- name: this.getStepText(step, steps),
105
- startTime,
106
- type: 'STEP',
107
- hasStats: false
108
- }, this.launchId, testItem.tempId);
109
- this.promiseQ.push(nestedTestItem.promise);
110
- await nestedTestItem.promise;
124
+
125
+ const nestedTestItem = await retry(async () => {
126
+ const nestedTestItem = this.rpClient.startTestItem({
127
+ description: 'test description',
128
+ name: this.getStepText(step, steps),
129
+ startTime,
130
+ type: 'STEP',
131
+ hasStats: false
132
+ }, this.launchId, testItem.tempId);
133
+ this.promiseQ.push(nestedTestItem.promise);
134
+ await nestedTestItem.promise;
135
+ return nestedTestItem;
136
+ }, this.rpConfig.retry);
137
+
111
138
  if (step.result.message) {
112
- const log = await this.rpClient.sendLog(nestedTestItem.tempId, {
113
- level: 'ERROR',
114
- message: this.getMessage(step),
115
- time: startTime
116
- });
117
- this.promiseQ.push(log.promise);
118
- await log.promise;
139
+ await retry(async () => {
140
+ const log = await this.rpClient.sendLog(nestedTestItem.tempId, {
141
+ level: 'ERROR',
142
+ message: this.getMessage(step),
143
+ time: startTime
144
+ });
145
+ this.promiseQ.push(log.promise);
146
+ await log.promise;
147
+ }, this.rpConfig.retry);
119
148
  }
120
149
  if (step.attachment) {
121
150
  for (const attachment of step.attachment) {
122
- await this.sendAttachment(attachment, nestedTestItem, startTime);
151
+ await retry(async () => {
152
+ await this.sendAttachment(attachment, nestedTestItem, startTime);
153
+ }, this.rpConfig.retry);
123
154
  }
124
155
  }
125
- const nestedItemFinish = this.rpClient.finishTestItem(nestedTestItem.tempId, {
126
- status: this.getStatus(step),
127
- endTime
128
- });
129
- this.promiseQ.push(nestedItemFinish.promise);
130
- await nestedItemFinish.promise;
131
- startTime = endTime;
156
+ await retry(async () => {
157
+ const nestedItemFinish = this.rpClient.finishTestItem(nestedTestItem.tempId, {
158
+ status: this.getStatus(step),
159
+ endTime
160
+ });
161
+ this.promiseQ.push(nestedItemFinish.promise);
162
+ await nestedItemFinish.promise;
163
+ startTime = endTime;
164
+ }, this.rpConfig.retry);
132
165
  }
133
166
 
134
167
  //finish test item
@@ -168,6 +201,7 @@ class RPFormatter extends Formatter {
168
201
  const stepsBefore = steps.slice(0, steps.findIndex((element) => element === step));
169
202
  return stepsBefore.every(element => element.pickle === undefined) ? 'Before' : 'After'
170
203
  }
204
+
171
205
  getMessage(step) {
172
206
  return step.result.message
173
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qavajs/format-report-portal",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "cucumber formatter for report portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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.10"
23
+ "@reportportal/client-javascript": "^5.0.11"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@cucumber/cucumber": "^9.1.2",
27
- "@qavajs/cli": "^0.0.24",
28
- "@qavajs/memory": "^1.4.1"
27
+ "@qavajs/cli": "^0.26.0",
28
+ "@qavajs/memory": "^1.4.2"
29
29
  }
30
30
  }
package/utils.js ADDED
@@ -0,0 +1,18 @@
1
+ async function retry(fn, retries = 1) {
2
+ let currentTry = 0;
3
+ let lastError;
4
+ while (currentTry < retries) {
5
+ try {
6
+ const result = await fn();
7
+ return result;
8
+ } catch (err) {
9
+ console.error(err);
10
+ currentTry++;
11
+ lastError = err;
12
+ }
13
+ }
14
+ }
15
+
16
+ module.exports = {
17
+ retry
18
+ }