testbeats 2.1.1 → 2.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testbeats",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
5
5
  "main": "src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -55,7 +55,7 @@
55
55
  "pretty-ms": "^7.0.1",
56
56
  "rosters": "0.0.1",
57
57
  "sade": "^1.8.1",
58
- "test-results-parser": "0.2.4"
58
+ "test-results-parser": "0.2.5"
59
59
  },
60
60
  "devDependencies": {
61
61
  "c8": "^7.12.0",
@@ -4,10 +4,11 @@ const FormData = require('form-data-lite');
4
4
  const TestResult = require('test-results-parser/src/models/TestResult');
5
5
  const { BeatsApi } = require('./beats.api');
6
6
  const logger = require('../utils/logger');
7
+ const TestAttachment = require('test-results-parser/src/models/TestAttachment');
7
8
 
8
9
  const MAX_ATTACHMENTS_PER_REQUEST = 5;
9
10
  const MAX_ATTACHMENTS_PER_RUN = 20;
10
- const MAX_ATTACHMENT_SIZE = 1024 * 1024;
11
+ const MAX_ATTACHMENT_SIZE = 2 * 1024 * 1024;
11
12
 
12
13
  class BeatsAttachments {
13
14
 
@@ -53,8 +54,6 @@ class BeatsAttachments {
53
54
  return;
54
55
  }
55
56
  logger.info(`⏳ Uploading ${this.attachments.length} attachments...`);
56
- const result_file = this.config.results[0].files[0];
57
- const result_file_dir = path.dirname(result_file);
58
57
  try {
59
58
  let count = 0;
60
59
  const size = MAX_ATTACHMENTS_PER_REQUEST;
@@ -68,7 +67,11 @@ class BeatsAttachments {
68
67
  form.append('test_run_id', this.test_run_id);
69
68
  const file_images = []
70
69
  for (const attachment of attachments_subset) {
71
- const attachment_path = path.join(result_file_dir, attachment.path);
70
+ const attachment_path = this.#getAttachmentFilePath(attachment);
71
+ if (!attachment_path) {
72
+ logger.warn(`⚠️ Unable to find attachment ${attachment.path}`);
73
+ continue;
74
+ }
72
75
  const stats = fs.statSync(attachment_path);
73
76
  if (stats.size > MAX_ATTACHMENT_SIZE) {
74
77
  logger.warn(`⚠️ Attachment ${attachment.path} is too big (${stats.size} bytes). Allowed size is ${MAX_ATTACHMENT_SIZE} bytes.`);
@@ -93,6 +96,33 @@ class BeatsAttachments {
93
96
  }
94
97
  }
95
98
 
99
+ /**
100
+ *
101
+ * @param {TestAttachment} attachment
102
+ */
103
+ #getAttachmentFilePath(attachment) {
104
+ const result_file = this.config.results[0].files[0];
105
+ const result_file_dir = path.dirname(result_file);
106
+ const relative_attachment_path = path.join(result_file_dir, attachment.path);
107
+ const raw_attachment_path = attachment.path;
108
+
109
+ try {
110
+ fs.statSync(relative_attachment_path);
111
+ return relative_attachment_path;
112
+ } catch {
113
+ // nothing
114
+ }
115
+
116
+ try {
117
+ fs.statSync(raw_attachment_path);
118
+ return raw_attachment_path;
119
+ } catch {
120
+ // nothing
121
+ }
122
+
123
+ return null;
124
+ }
125
+
96
126
 
97
127
 
98
128
  }
@@ -1,5 +1,6 @@
1
1
  const { BaseExtension } = require('./base.extension');
2
2
  const { STATUS, HOOK } = require("../helpers/constants");
3
+ const { truncate } = require('../helpers/helper');
3
4
 
4
5
  class ErrorClustersExtension extends BaseExtension {
5
6
 
@@ -35,7 +36,7 @@ class ErrorClustersExtension extends BaseExtension {
35
36
 
36
37
  const texts = [];
37
38
  for (const cluster of clusters) {
38
- texts.push(`${cluster.failure} - ${this.bold(`(x${cluster.count})`)}`);
39
+ texts.push(`${truncate(cluster.failure, 150)} - ${this.bold(`(x${cluster.count})`)}`);
39
40
  }
40
41
  this.text = this.mergeTexts(texts);
41
42
  }
@@ -46,9 +46,15 @@ function processData(data) {
46
46
  return data;
47
47
  }
48
48
 
49
+ /**
50
+ *
51
+ * @param {string} text
52
+ * @param {number} length
53
+ * @returns
54
+ */
49
55
  function truncate(text, length) {
50
56
  if (text && text.length > length) {
51
- return text.slice(0, length) + "...";
57
+ return text.slice(0, length).trim() + "...";
52
58
  } else {
53
59
  return text;
54
60
  }
@@ -103,12 +103,22 @@ class BasePlatform {
103
103
 
104
104
  const texts = [];
105
105
 
106
+ // webdriver io
107
+ if (suite.metadata.device && typeof suite.metadata.device === 'string') {
108
+ texts.push(`${suite.metadata.device}`);
109
+ }
110
+
106
111
  if (suite.metadata.platform && suite.metadata.platform.name && suite.metadata.platform.version) {
107
- texts.push(`${suite.metadata.platform.name} ${suite.metadata.platform.version}`)
112
+ texts.push(`${suite.metadata.platform.name} ${suite.metadata.platform.version}`);
108
113
  }
109
114
 
110
115
  if (suite.metadata.browser && suite.metadata.browser.name && suite.metadata.browser.version) {
111
- texts.push(`${suite.metadata.browser.name} ${suite.metadata.browser.version}`)
116
+ texts.push(`${suite.metadata.browser.name} ${suite.metadata.browser.version}`);
117
+ }
118
+
119
+ // playwright
120
+ if (suite.metadata.hostname && typeof suite.metadata.hostname === 'string') {
121
+ texts.push(`${suite.metadata.hostname}`);
112
122
  }
113
123
 
114
124
  return texts.join(' • ');