testbeats 2.1.2 → 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.2",
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",
@@ -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
  }