@qavajs/format-report-portal 0.0.4 → 0.0.5

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,2 +1,6 @@
1
+ ## 0.0.5
2
+ - :rocket: updated step logging as nested steps instead plain logs
3
+ - :beetle: added capability to attach multiple attachment to step
4
+
1
5
  ## 0.0.4
2
6
  - :beetle: fixed issue with sending text plain
package/README.MD CHANGED
@@ -15,6 +15,8 @@ module.exports = {
15
15
  ],
16
16
  formatOptions: {
17
17
  rpConfig: {
18
+ enable: true,
19
+ debug: false,
18
20
  token: 'your token',
19
21
  endpoint: 'https://your-rp-instance/api/v1',
20
22
  description: 'Description',
@@ -27,3 +29,9 @@ module.exports = {
27
29
  }
28
30
  }
29
31
  ```
32
+ Option `enable` is set to `true` even if it is not defined explicitly in rpConfig section.
33
+
34
+ ### run e2e test
35
+ add token.json file with rp token and other config
36
+ run
37
+ `npm run test-e2e`
package/index.js CHANGED
@@ -5,9 +5,12 @@ class RPFormatter extends Formatter {
5
5
 
6
6
  constructor(options) {
7
7
  super(options);
8
+ const rpEnable = options.parsedArgvOptions.rpConfig.enable;
9
+ if (rpEnable !== undefined && !rpEnable) return undefined;
8
10
  options.eventBroadcaster.on('envelope', this.processEnvelope.bind(this));
9
11
  this.rpConfig = options.parsedArgvOptions.rpConfig;
10
12
  this.rpClient = new RPClient(this.rpConfig);
13
+ this.promiseQ = [];
11
14
  }
12
15
 
13
16
  async processEnvelope(envelope) {
@@ -28,15 +31,18 @@ class RPFormatter extends Formatter {
28
31
  startTime: this.rpClient.helpers.now(),
29
32
  description: this.rpConfig.description,
30
33
  attributes: this.rpConfig.tags,
31
- mode: this.rpConfig.mode
34
+ mode: this.rpConfig.mode,
35
+ debug: this.rpConfig.debug
32
36
  });
33
37
 
34
38
  this.launchId = launchObj.tempId;
35
39
  this.features = {};
40
+ this.promiseQ.push(launchObj.promise);
36
41
  await launchObj.promise;
37
42
  }
38
43
 
39
44
  async finishLaunch() {
45
+ await Promise.allSettled(this.promiseQ);
40
46
  for (const featureName in this.features) {
41
47
  await this.rpClient.finishTestItem(this.features[featureName], { status: 'PASSED' }).promise;
42
48
  }
@@ -60,6 +66,7 @@ class RPFormatter extends Formatter {
60
66
  type: 'SUITE'
61
67
  }, this.launchId);
62
68
  this.features[featureName] = featureItem.tempId;
69
+ this.promiseQ.push(featureItem.promise);
63
70
  await featureItem.promise;
64
71
  }
65
72
 
@@ -71,36 +78,63 @@ class RPFormatter extends Formatter {
71
78
  startTime: this.rpClient.helpers.now(),
72
79
  type: 'STEP'
73
80
  }, this.launchId, featureTempId);
81
+ this.promiseQ.push(testItem.promise);
74
82
  await testItem.promise;
75
83
 
76
84
  //send steps
77
85
  const steps = this.getStepResults(testCase)
78
86
  for (const step of steps) {
79
- const attachment = step.attachment && step.attachment[0]
80
- ? {
81
- name: 'attachment',
82
- type: step.attachment[0].mediaType,
83
- content: step.attachment[0].mediaType === 'text/plain'
84
- ? Buffer.from(step.attachment[0].body).toString('base64')
85
- : step.attachment[0].body,
87
+ const nestedTestItem = this.rpClient.startTestItem({
88
+ description: 'test description',
89
+ name: this.getStepText(step, steps),
90
+ startTime: this.rpClient.helpers.now(),
91
+ type: 'STEP',
92
+ hasStats: false
93
+ }, this.launchId, testItem.tempId);
94
+ this.promiseQ.push(nestedTestItem.promise);
95
+ await nestedTestItem.promise;
96
+ if (step.result.message) {
97
+ const log = await this.rpClient.sendLog(nestedTestItem.tempId, {
98
+ level: 'ERROR',
99
+ message: this.getMessage(step),
100
+ time: this.rpClient.helpers.now()
101
+ });
102
+ this.promiseQ.push(log.promise);
103
+ await log.promise;
104
+ }
105
+ if (step.attachment) {
106
+ for (const attachment of step.attachment) {
107
+ const attachmentData = {
108
+ name: 'attachment',
109
+ type: attachment.mediaType,
110
+ content: this.prepareContent(attachment),
111
+ };
112
+ const log = await this.rpClient.sendLog(nestedTestItem.tempId, {
113
+ level: 'INFO',
114
+ message: 'Attachment',
115
+ time: this.rpClient.helpers.now()
116
+ }, attachmentData);
117
+ this.promiseQ.push(log.promise);
118
+ await log.promise;
86
119
  }
87
- : undefined;
88
- await this.rpClient.sendLog(testItem.tempId, {
89
- level: step.result.status === Status.PASSED
90
- ? 'INFO'
91
- : 'ERROR',
92
- message: this.getMessage(step),
93
- time: this.rpClient.helpers.now()
94
- }, attachment).promise
120
+ }
121
+ const nestedItemFinish = this.rpClient.finishTestItem(nestedTestItem.tempId, {
122
+ status: this.getStatus(step),
123
+ endTime: this.rpClient.helpers.now()
124
+ });
125
+ this.promiseQ.push(nestedItemFinish.promise);
126
+ await nestedItemFinish.promise;
95
127
  }
96
128
 
97
129
  //finish test item
98
130
  const status = Object.values(testCase.stepResults).some(step => step.status !== Status.PASSED)
99
131
  ? Status.FAILED.toLowerCase()
100
132
  : Status.PASSED.toLowerCase()
101
- await this.rpClient.finishTestItem(testItem.tempId, {
133
+ const testItemFinish = this.rpClient.finishTestItem(testItem.tempId, {
102
134
  status
103
- }).promise;
135
+ });
136
+ this.promiseQ.push(testItemFinish.promise);
137
+ await testItemFinish.promise;
104
138
  }
105
139
 
106
140
  getStepResults(testCase) {
@@ -111,8 +145,8 @@ class RPFormatter extends Formatter {
111
145
  }))
112
146
  }
113
147
 
114
- getMessage(step) {
115
- if (!step.pickle) return 'Hook';
148
+ getStepText(step, steps) {
149
+ if (!step.pickle) return this.hookKeyword(step, steps);
116
150
  const messageParts = [step.pickle.text];
117
151
  if (step.pickle.argument) {
118
152
  if (step.pickle.argument.dataTable) messageParts.push(
@@ -120,11 +154,25 @@ class RPFormatter extends Formatter {
120
154
  )
121
155
  if (step.pickle.argument.docString) messageParts.push(this.formatDocString(step.pickle.argument.docString))
122
156
  }
123
- if (step.result.status === Status.FAILED) messageParts.push(step.result.message)
124
157
 
125
158
  return messageParts.join('\n')
126
159
  }
127
160
 
161
+ hookKeyword(step, steps) {
162
+ const stepsBefore = steps.slice(0, steps.findIndex((element) => element === step));
163
+ return stepsBefore.every(element => element.pickle === undefined) ? 'Before' : 'After'
164
+ }
165
+ getMessage(step) {
166
+ return step.result.message
167
+ }
168
+
169
+ getStatus(step) {
170
+ if (step.result.status !== Status.PASSED) {
171
+ return Status.FAILED.toLowerCase()
172
+ }
173
+ return Status.PASSED.toLowerCase()
174
+ }
175
+
128
176
  formatTable(dataTable) {
129
177
  const TR = '<tr>';
130
178
  const TRE = '</tr>';
@@ -141,6 +189,13 @@ class RPFormatter extends Formatter {
141
189
  formatTags(tags) {
142
190
  return tags.map(tag => '<code>' + tag.name + '</code>').join('')
143
191
  }
192
+
193
+ prepareContent(attachment) {
194
+ return ['text/plain', 'application/json'].includes(attachment.mediaType)
195
+ ? Buffer.from(attachment.body).toString('base64')
196
+ : attachment.body
197
+ }
198
+
144
199
  }
145
200
 
146
201
  module.exports = RPFormatter
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@qavajs/format-report-portal",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "cucumber formatter for report portal",
5
5
  "main": "index.js",
6
- "scripts": {},
6
+ "scripts": {
7
+ "test-e2e": "qavajs run --config test-e2e/config.js"
8
+ },
7
9
  "repository": {
8
10
  "type": "git",
9
11
  "url": "git+https://github.com/qavajs/format-report-portal.git"
@@ -18,5 +20,12 @@
18
20
  "homepage": "https://github.com/qavajs/format-report-portal#readme",
19
21
  "dependencies": {
20
22
  "@reportportal/client-javascript": "^5.0.8"
23
+ },
24
+ "devDependencies": {
25
+ "@cucumber/cucumber": "^9.0.0",
26
+ "@qavajs/cli": "^0.0.18",
27
+ "@qavajs/memory": "^1.2.0",
28
+ "@qavajs/po-playwright": "^0.0.7",
29
+ "@qavajs/steps-playwright": "^0.0.14"
21
30
  }
22
31
  }
@@ -1,32 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v2
15
- - uses: actions/setup-node@v2
16
- with:
17
- node-version: 16
18
- - run: npm ci
19
-
20
- publish-npm:
21
- needs: build
22
- runs-on: ubuntu-latest
23
- steps:
24
- - uses: actions/checkout@v2
25
- - uses: actions/setup-node@v2
26
- with:
27
- node-version: 16
28
- registry-url: https://registry.npmjs.org/
29
- - run: npm ci
30
- - run: npm publish --access public
31
- env:
32
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}