@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 +6 -0
- package/README.MD +3 -1
- package/index.js +93 -59
- 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,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
|
-
|
|
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];
|
|
78
89
|
let startTime = this.rpClient.helpers.now();
|
|
79
90
|
let endTime;
|
|
80
91
|
const steps = this.getStepResults(testCase);
|
|
81
|
-
const attributes = steps
|
|
82
|
-
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
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 =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
151
|
+
await retry(async () => {
|
|
152
|
+
await this.sendAttachment(attachment, nestedTestItem, startTime);
|
|
153
|
+
}, this.rpConfig.retry);
|
|
123
154
|
}
|
|
124
155
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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.
|
|
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.
|
|
23
|
+
"@reportportal/client-javascript": "^5.0.11"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@cucumber/cucumber": "^9.1.2",
|
|
27
|
-
"@qavajs/cli": "^0.0
|
|
28
|
-
"@qavajs/memory": "^1.4.
|
|
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
|
+
}
|