@testomatio/reporter 1.2.2-beta.show-error.1 → 1.2.2

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.
@@ -20,6 +20,7 @@ const keys = [
20
20
  'S3_BUCKET',
21
21
  'S3_ACCESS_KEY_ID',
22
22
  'S3_SECRET_ACCESS_KEY',
23
+ 'S3_SESSION_TOKEN',
23
24
  'TESTOMATIO_DISABLE_ARTIFACTS',
24
25
  'TESTOMATIO_PRIVATE_ARTIFACTS',
25
26
  'S3_FORCE_PATH_STYLE',
@@ -74,7 +75,8 @@ const _getFileExtBase64 = str => {
74
75
  };
75
76
 
76
77
  const _getS3Config = () => {
77
- const { S3_REGION, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_FORCE_PATH_STYLE, S3_ENDPOINT } = getConfig();
78
+ const { S3_REGION, S3_SESSION_TOKEN, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_FORCE_PATH_STYLE, S3_ENDPOINT } =
79
+ getConfig();
78
80
 
79
81
  const cfg = {
80
82
  region: S3_REGION,
@@ -85,6 +87,10 @@ const _getS3Config = () => {
85
87
  },
86
88
  };
87
89
 
90
+ if (S3_SESSION_TOKEN) {
91
+ cfg.credentials.sessionToken = S3_SESSION_TOKEN;
92
+ }
93
+
88
94
  if (S3_ENDPOINT) {
89
95
  cfg.endpoint = S3_ENDPOINT;
90
96
  }
package/lib/pipe/html.js CHANGED
@@ -91,7 +91,7 @@ class HtmlPipe {
91
91
  // GENERATE HTML reports based on the results data
92
92
  this.buildReport({
93
93
  runParams,
94
- // TODO: this.tests=[] in case of Mocha
94
+ // TODO: this.tests=[] in case of Mocha, need retest by Vitalii
95
95
  tests: this.tests,
96
96
  outputPath: this.htmlOutputPath,
97
97
  templatePath: this.templateHtmlPath,
@@ -123,30 +123,31 @@ class HtmlPipe {
123
123
  }
124
124
 
125
125
  tests.forEach(test => {
126
- if (!test.message || test.message.trim() === '') {
126
+ if (!test.message?.trim()) {
127
127
  test.message = "This test has no 'message' code";
128
128
  }
129
129
 
130
- if (!test.suite_title || test.suite_title.trim() === '') {
130
+ if (!test.suite_title?.trim()) {
131
131
  test.suite_title = 'Unknown suite';
132
132
  }
133
133
 
134
- if (!test.title || test.title.trim() === '') {
134
+ if (!test.title?.trim()) {
135
135
  test.title = 'Unknown test title';
136
136
  }
137
137
 
138
- if (!test.files || test.files.length === 0) {
138
+ if (!test.files?.length) {
139
139
  test.files = 'This test has no files';
140
140
  }
141
141
 
142
- if (test.steps) {
143
- if (!test.steps || test.steps.trim() === '') {
144
- test.steps = "This test has no 'steps' code";
145
- } else {
146
- test.steps = removeAnsiColorCodes(test.steps);
147
- }
142
+ if (!test.steps?.trim()) {
143
+ test.steps = "This test has no 'steps' code";
144
+ } else {
145
+ test.steps = removeAnsiColorCodes(test.steps);
148
146
  }
149
147
 
148
+ // TODO: future-proof: currently there is no need to display Artifacts and Metadata in HTML
149
+ test.artifacts = test.artifacts || [];
150
+ test.meta = test.meta || {};
150
151
  // TODO: u can added an additional test values to this checks in the future
151
152
  });
152
153
 
@@ -199,7 +200,8 @@ class HtmlPipe {
199
200
 
200
201
  return template(data);
201
202
  } catch (e) {
202
- console.log('Unknown HTML report generation error: ', e);
203
+ console.log(chalk.red(' Oops! An unknown error occurred when generating an HTML report'));
204
+ console.log(chalk.red(e));
203
205
  }
204
206
  }
205
207
 
@@ -209,42 +211,77 @@ class HtmlPipe {
209
211
  (tests, status) => tests.filter(test => test.status.toLowerCase() === status.toLowerCase()).length,
210
212
  );
211
213
 
212
- handlebars.registerHelper('json', tests => {
213
- // TODO: please refactor the code below, add meaningful variable names, separate into functions
214
- function replaceScriptTagsInArray(array) {
215
- return array.map(obj => {
216
- const keysToCheck = ['steps', 'stack', 'title', 'suite_title', 'message', 'code'];
217
- const newObj = {};
218
-
219
- for (const key in obj) {
220
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
221
- if (key === 'example') {
222
- newObj[key] = {};
223
- for (const subKey in obj[key]) {
224
- if (Object.prototype.hasOwnProperty.call(obj[key], subKey)) {
225
- newObj[key][subKey] =
226
- typeof obj[key][subKey] === 'string'
227
- ? obj[key][subKey].replace(/<script>/g, '<$cript>').replace(/<\/script>/g, '</$cript>')
228
- : obj[key][subKey];
229
- }
230
- }
231
- } else if (keysToCheck.includes(key)) {
232
- newObj[key] =
233
- typeof obj[key] === 'string'
234
- ? obj[key].replace(/<script>/g, '<$cript>').replace(/<\/script>/g, '</$cript>')
235
- : obj[key];
236
- } else {
237
- newObj[key] = obj[key];
238
- }
214
+ handlebars.registerHelper(
215
+ 'selectComponent',
216
+ () =>
217
+ new handlebars.SafeString(
218
+ `<select style="width: 70px;height: 38px;" class="form-select" aria-label="Tests counter on page">
219
+ <option value="0">10</option>
220
+ <option value="1">25</option>
221
+ <option value="2">50</option>
222
+ </select>`,
223
+ ),
224
+ );
225
+
226
+ handlebars.registerHelper(
227
+ 'emptyDataComponent',
228
+ () =>
229
+ new handlebars.SafeString(
230
+ `<div class="noData m-0">
231
+ NO MATCHING TESTS
232
+ </div>`,
233
+ ),
234
+ );
235
+
236
+ handlebars.registerHelper('pageDispleyElements', tests => {
237
+ // We wrapp the lines to the HTML format we need
238
+ const totalTests = JSON.parse(
239
+ JSON.stringify(tests)
240
+ .replace(/<script>/g, '&lt;script&gt;')
241
+ .replace(/<\/script>/g, '&lt;/script&gt;'), // eslint-disable-line
242
+ );
243
+
244
+ const paginationOptions = {
245
+ 0: 10,
246
+ 1: 25,
247
+ 2: 50,
248
+ };
249
+ const statuses = ['all', 'passed', 'failed', 'skipped'];
250
+ const pageItemGroups = {
251
+ all: {},
252
+ passed: {},
253
+ failed: {},
254
+ skipped: {},
255
+ totalTests,
256
+ };
257
+
258
+ function paginateItems(items, pageSize) {
259
+ const paginatedItems = [];
260
+ for (let i = 0; i < items.length; i += pageSize) {
261
+ paginatedItems.push(items.slice(i, i + pageSize));
262
+ }
263
+ return paginatedItems;
264
+ }
265
+
266
+ statuses.forEach(status => {
267
+ for (const option in paginationOptions) {
268
+ // eslint-disable-next-line no-prototype-builtins
269
+ if (paginationOptions.hasOwnProperty(option)) {
270
+ const pageSize = paginationOptions[option];
271
+ let filteredItems = totalTests;
272
+
273
+ if (status !== 'all') {
274
+ filteredItems = totalTests.filter(item => item.status === status);
239
275
  }
276
+
277
+ pageItemGroups[status][option] = paginateItems(filteredItems, pageSize);
240
278
  }
279
+ }
280
+ });
241
281
 
242
- return newObj;
243
- });
244
- }
282
+ pageItemGroups.totalTests = totalTests;
245
283
 
246
- // Remove ANSI escape codes
247
- return JSON.stringify(replaceScriptTagsInArray(tests));
284
+ return JSON.stringify(pageItemGroups);
248
285
  });
249
286
  }
250
287
 
@@ -261,7 +298,7 @@ class HtmlPipe {
261
298
  */
262
299
  function testExecutionSumTime(tests) {
263
300
  const totalMilliseconds = tests.reduce((sum, test) => {
264
- if (typeof test.run_time === 'number') {
301
+ if (typeof test.run_time === 'number' && !Number.isNaN(test.run_time)) {
265
302
  return sum + test.run_time;
266
303
  }
267
304
  return sum;
@@ -190,7 +190,6 @@ class TestomatioPipe {
190
190
  'Error creating Testomat.io report, please check if your API key is valid. Skipping report | ',
191
191
  err?.response?.statusText || err?.status || err.message,
192
192
  );
193
- printCreateIssue(err);
194
193
  }
195
194
  debug('"createRun" function finished');
196
195
  }
@@ -232,11 +231,8 @@ class TestomatioPipe {
232
231
  chalk.yellow(`Warning: ${data?.title || ''} (${err.response?.status})`),
233
232
  `Report couldn't be processed: ${err?.response?.data?.message}`,
234
233
  );
235
- printCreateIssue(err);
236
234
  } else {
237
235
  console.log(APP_PREFIX, chalk.blue(data?.title || ''), "Report couldn't be processed", err);
238
-
239
-
240
236
  }
241
237
  });
242
238
  }
@@ -304,7 +300,6 @@ class TestomatioPipe {
304
300
  }
305
301
  } catch (err) {
306
302
  console.log(APP_PREFIX, 'Error updating status, skipping...', err);
307
- printCreateIssue(err);
308
303
  }
309
304
  debug('Run finished');
310
305
  }
@@ -314,24 +309,4 @@ class TestomatioPipe {
314
309
  }
315
310
  }
316
311
 
317
- let registeredErrorHints = false;
318
- function printCreateIssue(err) {
319
- if (registeredErrorHints) return;
320
- registeredErrorHints = true;
321
- process.on('beforeExit', () => {
322
- console.log(APP_PREFIX, 'There was error reporting to Testomat.io:');
323
- console.log(APP_PREFIX, 'If you think this is a bug please create an issue: https://github.com/testomatio/app/issues/new');
324
- console.log(APP_PREFIX, 'Provide this information:');
325
- console.log(APP_PREFIX, 'Error:', err.message || err.code);
326
- if (!err.config) return;
327
-
328
- const time = new Date().toUTCString();
329
- const { data, url, baseURL, method } = err?.config || {}
330
- console.log('```js')
331
- console.log({ data, url, baseURL, method, time });
332
- console.log('```')
333
- console.log();
334
- });
335
- }
336
-
337
312
  module.exports = TestomatioPipe;