@testomatio/reporter 2.6.0 → 2.6.1

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.
@@ -262,6 +262,15 @@ class TestomatioPipe {
262
262
  responseType: 'json',
263
263
  });
264
264
  if (resp.data.artifacts) setS3Credentials(resp.data.artifacts);
265
+ if (resp.data.url) {
266
+ const respUrl = new URL(resp.data.url);
267
+ this.runUrl = `${this.url}${respUrl.pathname}`;
268
+ this.runPublicUrl = resp.data.public_url;
269
+ this.store.runUrl = this.runUrl;
270
+ this.store.runPublicUrl = this.runPublicUrl;
271
+ console.log(APP_PREFIX, '📊 Using existing run. Report ID:', this.runId);
272
+ console.log(APP_PREFIX, '📊 Report URL:', pc.magenta(this.runUrl));
273
+ }
265
274
  return;
266
275
  }
267
276
 
@@ -574,7 +583,9 @@ function printCreateIssue() {
574
583
  * @returns {string}
575
584
  */
576
585
  function hideTestomatioToken(data) {
577
- return data.replace(/"api_key": "[^"]+"/g, '"api_key": "<hidden>"').replace(/"(tstmt_[^"]+)"/g, 'tstmt_***');
586
+ return (typeof data === 'string' ? data : '')
587
+ .replace(/"api_key"\s*:\s*"[^"]+"/g, '"api_key": "<hidden>"')
588
+ .replace(/"(tstmt_[^"]+)"/g, '"tstmt_***"');
578
589
  }
579
590
 
580
591
  /**
@@ -1,5 +1,7 @@
1
+ import { playwrightLogsMarkers } from './adapter/utils/playwright.js';
1
2
  import { isPlaywright } from './helpers.js';
2
3
  import { services } from './services/index.js';
4
+ import pc from 'picocolors';
3
5
 
4
6
  /**
5
7
  * Stores path to file as artifact and uploads it to the S3 storage
@@ -8,7 +10,10 @@ import { services } from './services/index.js';
8
10
  * @returns {void}
9
11
  */
10
12
  function saveArtifact(data, context = null) {
11
- showPlaywrightWarning('artifact', 'Playwright supports artifacts out of the box.');
13
+ if (isPlaywright)
14
+ console.warn(`[TESTOMATIO] 'artifact' function is not supported for Playwright
15
+ Playwright supports artifacts out of the box.`);
16
+
12
17
  if (!data) return;
13
18
  services.artifacts.put(data, context);
14
19
  }
@@ -41,69 +46,104 @@ function addStep(message, logs) {
41
46
 
42
47
  /**
43
48
  * Add key-value pair(s) to the test report
44
- * @param {{[key: string]: string} | string} keyValue - object { key: value } (multiple props allowed) or key (string)
45
- * @param {string|null} [value=null] - optional value when keyValue is a string
49
+ * @param {{[key: string]: string} | string} keyValue - object { key: value } (multiple props allowed) OR key (string)
50
+ * @param {string|undefined} [value=undefined] - optional value when keyValue is a string
46
51
  * @returns {void}
52
+ *
53
+ * @example
54
+ * meta('key', 'value');
55
+ * meta({ key: 'value' });
56
+ * meta({ key1: 'value1', key2: 'value2' });
47
57
  */
48
- function setKeyValue(keyValue, value = null) {
49
- showPlaywrightWarning('meta', 'Use test annotations instead.');
50
-
58
+ function setKeyValue(keyValue, value = undefined) {
59
+ // in this case keyValue acts as key (value passed as second argument)
51
60
  if (typeof keyValue === 'string') {
52
- keyValue = { [keyValue]: value };
61
+ const key = keyValue;
62
+ keyValue = { [key]: value };
63
+ }
64
+
65
+ if (isPlaywright) {
66
+ console.log(`${playwrightLogsMarkers.meta} ${JSON.stringify(keyValue)}`);
67
+ return;
53
68
  }
69
+
70
+ // in this case keyValue is expected to be an object
54
71
  services.keyValues.put(keyValue);
55
72
  }
56
73
 
57
74
  /**
58
- * Add a single label to the test report
59
- * @param {string} key - label key (e.g. 'severity', 'feature', or just 'smoke' for labels without values)
60
- * @param {string|null} [value=null] - optional label value (e.g. 'high', 'login')
75
+ * Adds label(s) to the test
76
+ * @param {string | {
77
+ * [key: string]: string}
78
+ * } key - just label OR custom field name OR object with custom field name and value
79
+ * @param {string | null} [value=null] - optional label value (of custom field value)
80
+ * (used when key is a string)
61
81
  * @returns {void}
82
+ *
83
+ * @example
84
+ * label('high');
85
+ * label('priority', 'high');
86
+ * label({priority: 'high'});
62
87
  */
63
88
  function setLabel(key, value = null) {
64
- showPlaywrightWarning('label', 'Use test tag instead.');
65
- if (Array.isArray(value)) {
66
- return value.forEach(label => setLabel(key, label));
89
+ let labelsArr = [];
90
+
91
+ // process label('priority', 'high') and label('high'
92
+ if (typeof key === 'string') {
93
+ labelsArr = [value ? `${key}:${value}` : key];
94
+ // process label({priority: 'high'}), label({priority: 'high', scope: 'smoke'})
95
+ } else if (key !== null && typeof key === 'object') {
96
+ labelsArr = Object.entries(key).map(([key, value]) => `${key}:${value}`);
67
97
  }
68
- const labelObject =
69
- value !== null && value !== undefined && value !== '' ? { label: `${key}:${value}` } : { label: key };
70
- services.links.put([labelObject]);
98
+
99
+ const labels = labelsArr.map(l => ({ label: l }));
100
+ if (isPlaywright) {
101
+ console.log(`${playwrightLogsMarkers.label} ${JSON.stringify(labels)}`);
102
+ return;
103
+ }
104
+ services.links.put(labels);
71
105
  }
72
106
 
73
107
  /**
74
108
  * Add link(s) to the test report
75
- * @param {...string} testIds - test IDs to link
109
+ * @param {...string | string[]} testIds - test IDs to link
76
110
  * @returns {void}
111
+ *
112
+ * @example
113
+ * linkTest('T11111111', 'T22222222')
114
+ * or
115
+ * linkTest(['T11111111', 'T22222222'])
77
116
  */
78
117
  function linkTest(...testIds) {
118
+ const testIdsArr = testIds.flat();
119
+ const links = testIdsArr.map(testId => ({ test: testId }));
79
120
  if (isPlaywright) {
80
- console.log(`[TESTOMATIO-LINK-TESTS] ${JSON.stringify(testIds)}`);
121
+ console.log(`${playwrightLogsMarkers.linkTest} ${JSON.stringify(links)}`);
81
122
  return;
82
123
  }
83
- const links = testIds.map(testId => ({ test: testId }));
84
124
  services.links.put(links);
85
125
  }
86
126
 
87
127
  /**
88
128
  * Add JIRA issue link(s) to the test report
89
- * @param {...string} jiraIds - JIRA issue IDs to link
129
+ * @param {...(string | string[])} jiraIds - JIRA issue IDs to link
90
130
  * @returns {void}
131
+ *
132
+ * @example
133
+ * linkJira('TICKET-1', 'TICKET-2')
134
+ * or
135
+ * linkJira(['TICKET-1', 'TICKET-2'])
91
136
  */
92
137
  function linkJira(...jiraIds) {
138
+ const jiraIdsArr = jiraIds.flat();
139
+ const links = jiraIdsArr.map(jiraId => ({ jira: jiraId }));
93
140
  if (isPlaywright) {
94
- console.log(`[TESTOMATIO-LINK-JIRA] ${JSON.stringify(jiraIds)}`);
141
+ console.log(`${playwrightLogsMarkers.linkJira} ${JSON.stringify(links)}`);
95
142
  return;
96
143
  }
97
- const links = jiraIds.map(jiraId => ({ jira: jiraId }));
98
144
  services.links.put(links);
99
145
  }
100
146
 
101
- function showPlaywrightWarning(functionName, recommendation) {
102
- if (isPlaywright) {
103
- console.warn(`[TESTOMATIO] '${functionName}' function is not supported for Playwright. ${recommendation}`);
104
- }
105
- }
106
-
107
147
  export default {
108
148
  artifact: saveArtifact,
109
149
  log: logMessage,