@qavajs/format-report-portal 0.9.1 → 0.9.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 +9 -0
- package/README.MD +3 -1
- package/index.js +80 -55
- package/package.json +4 -4
- package/utils.js +18 -0
package/CHANGELOG.MD
CHANGED
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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,18 +69,20 @@ 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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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];
|
|
@@ -87,56 +98,70 @@ class RPFormatter extends Formatter {
|
|
|
87
98
|
}, [])
|
|
88
99
|
.map(attachment => {
|
|
89
100
|
const [key, value] = attachment.split(':');
|
|
90
|
-
return key && value
|
|
101
|
+
return key && value
|
|
91
102
|
? { key, value, system: false }
|
|
92
103
|
: { value: key, system: false }
|
|
93
104
|
});
|
|
94
105
|
|
|
95
106
|
// Start test
|
|
96
|
-
const testItem =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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);
|
|
105
119
|
|
|
106
120
|
//send steps
|
|
107
121
|
for (const step of steps) {
|
|
108
122
|
const duration = step.result.duration;
|
|
109
123
|
endTime = startTime + (duration.seconds * 1_000) + Math.floor(duration.nanos / 1_000_000);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
|
|
119
138
|
if (step.result.message) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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);
|
|
127
148
|
}
|
|
128
149
|
if (step.attachment) {
|
|
129
150
|
for (const attachment of step.attachment) {
|
|
130
|
-
await
|
|
151
|
+
await retry(async () => {
|
|
152
|
+
await this.sendAttachment(attachment, nestedTestItem, startTime);
|
|
153
|
+
}, this.rpConfig.retry);
|
|
131
154
|
}
|
|
132
155
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
|
140
165
|
}
|
|
141
166
|
|
|
142
167
|
//finish test item
|
|
@@ -176,7 +201,7 @@ class RPFormatter extends Formatter {
|
|
|
176
201
|
const stepsBefore = steps.slice(0, steps.findIndex((element) => element === step));
|
|
177
202
|
return stepsBefore.every(element => element.pickle === undefined) ? 'Before' : 'After'
|
|
178
203
|
}
|
|
179
|
-
|
|
204
|
+
|
|
180
205
|
getMessage(step) {
|
|
181
206
|
return step.result.message
|
|
182
207
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qavajs/format-report-portal",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
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.
|
|
23
|
+
"@reportportal/client-javascript": "^5.0.12"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@cucumber/cucumber": "^9.1.2",
|
|
27
|
-
"@qavajs/cli": "^0.0
|
|
28
|
-
"@qavajs/memory": "^1.
|
|
27
|
+
"@qavajs/cli": "^0.26.0",
|
|
28
|
+
"@qavajs/memory": "^1.5.1"
|
|
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
|
+
}
|