@qavajs/format-report-portal 0.14.3 → 1.0.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
+ ## 1.0.0
2
+ - added `legacyTimeFormat` flag to support old versions of report portal
3
+
4
+ ## 0.15.0
5
+ - added request/response renderer of internal mime type _text/x.response.json_
6
+
1
7
  ## 0.14.3
2
8
  - bump dependencies to get rid of vulnerabilities
3
9
 
package/README.MD CHANGED
@@ -27,7 +27,8 @@ module.exports = {
27
27
  retry: 1, // number of retries to send result to report portal (default - 1)
28
28
  ignoreErrors: false, // ignore RP errors (default: false)
29
29
  showLaunchURL: true, // log report portal launch link,
30
- tagsAsAttributes: true // (default: false tags go to description)
30
+ tagsAsAttributes: true, // (default: false - tags go to description)
31
+ legacyTimeFormat: true // (default: false - use legacy milliseconds precision instead of microseconds)
31
32
  },
32
33
  }
33
34
  }
package/index.js CHANGED
@@ -17,6 +17,9 @@ class RPFormatter extends Formatter {
17
17
  this.rpClient = new RPClient(this.rpConfig);
18
18
  this.promiseQ = [];
19
19
  this.stepDefinitions = {};
20
+ if (this.rpConfig.legacyTimeFormat) {
21
+ this.rpClient.helpers.now = () => { return Date.now() };
22
+ }
20
23
  }
21
24
 
22
25
  async processEnvelope(envelope) {
@@ -265,6 +268,12 @@ class RPFormatter extends Formatter {
265
268
  message: attachment.body,
266
269
  time: startTime
267
270
  });
271
+ } else if (attachment.mediaType === 'text/x.response.json') {
272
+ log = await this.rpClient.sendLog(testItem.tempId, {
273
+ level: 'INFO',
274
+ message: this.responseBody(attachment.body),
275
+ time: startTime
276
+ });
268
277
  } else {
269
278
  const attachmentData = {
270
279
  name: 'attachment',
@@ -279,6 +288,41 @@ class RPFormatter extends Formatter {
279
288
  }
280
289
  await log.promise;
281
290
  }
291
+
292
+ renderHeaders(headers) {
293
+ return Object.entries(headers).map(([key, value]) => `${key}: ${value}`).join('\n');
294
+ }
295
+
296
+ responseBody(log) {
297
+ const payload = JSON.parse(log);
298
+ const isText = header => ['application/json', 'text/plain', 'text/html'].some(mime => (header ?? '').includes(mime));
299
+ const reqBody = isText(payload.request.headers['content-type'])
300
+ ? Buffer.from(payload.request.body, 'base64').toString()
301
+ : payload.request.body;
302
+ const resBody = isText(payload.response.headers['content-type'])
303
+ ? Buffer.from(payload.response.body, 'base64').toString()
304
+ : payload.request.body;
305
+ return `${payload.request.method} ${payload.request.url} - ${payload.response.status}
306
+ **Request**
307
+ body:
308
+ \`\`\`
309
+ ${reqBody}
310
+ \`\`\`
311
+ headers:
312
+ \`\`\`
313
+ ${this.renderHeaders(payload.request.headers)}
314
+ \`\`\`
315
+ **Response**
316
+ body:
317
+ \`\`\`
318
+ ${resBody}
319
+ \`\`\`
320
+ headers:
321
+ \`\`\`
322
+ ${this.renderHeaders(payload.response.headers)}
323
+ \`\`\`
324
+ `
325
+ }
282
326
  }
283
327
 
284
328
  module.exports = RPFormatter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qavajs/format-report-portal",
3
- "version": "0.14.3",
3
+ "version": "1.0.0",
4
4
  "description": "cucumber formatter for report portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,12 +21,12 @@
21
21
  },
22
22
  "homepage": "https://github.com/qavajs/format-report-portal#readme",
23
23
  "dependencies": {
24
- "@reportportal/client-javascript": "^5.1.0"
24
+ "@reportportal/client-javascript": "^5.3.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@cucumber/cucumber": "^10.3.1",
28
- "@qavajs/cli": "^0.34.1",
29
- "@qavajs/memory": "^1.7.0",
27
+ "@cucumber/cucumber": "^11.1.0",
28
+ "@qavajs/cli": "^1.0.0",
29
+ "@qavajs/memory": "^1.10.2",
30
30
  "jest": "^29.7.0"
31
31
  }
32
32
  }