@testomatio/reporter 1.2.2-beta-html-pagination-feature → 1.2.2-beta-html-pagination-feature-v2

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/lib/pipe/html.js CHANGED
@@ -135,11 +135,13 @@ class HtmlPipe {
135
135
  test.title = 'Unknown test title';
136
136
  }
137
137
 
138
- if (!test.files || test.files.length === 0) {
139
- test.files = 'This test has no files';
138
+ if ('files' in test) {
139
+ if (test.files.length === 0) {
140
+ test.files = 'This test has no files';
141
+ }
140
142
  }
141
143
 
142
- if (test.steps) {
144
+ if ('steps' in test) {
143
145
  if (!test.steps || test.steps.trim() === '') {
144
146
  test.steps = "This test has no 'steps' code";
145
147
  } else {
@@ -147,6 +149,15 @@ class HtmlPipe {
147
149
  }
148
150
  }
149
151
 
152
+ // TODO: future-proof: currently there is no need to display Artifacts and Metadata in HTML
153
+ if ('artifacts' in test) {
154
+ test.artifacts = [];
155
+ }
156
+
157
+ if ('meta' in test) {
158
+ test.meta = {};
159
+ }
160
+
150
161
  // TODO: u can added an additional test values to this checks in the future
151
162
  });
152
163
 
@@ -198,9 +209,8 @@ class HtmlPipe {
198
209
  const template = handlebars.compile(templateSource);
199
210
 
200
211
  return template(data);
201
- }
202
- catch (e) {
203
- console.log(chalk.red("❌ Oops! An unknown error occurred when generating an HTML report"));
212
+ } catch (e) {
213
+ console.log(chalk.red('❌ Oops! An unknown error occurred when generating an HTML report'));
204
214
  console.log(chalk.red(e));
205
215
  }
206
216
  }
@@ -213,82 +223,75 @@ class HtmlPipe {
213
223
 
214
224
  handlebars.registerHelper(
215
225
  'selectComponent',
216
- () => new handlebars.SafeString(
217
- `<select style="width: 70px;height: 38px;" class="form-select" aria-label="Tests counter on page">
226
+ () =>
227
+ new handlebars.SafeString(
228
+ `<select style="width: 70px;height: 38px;" class="form-select" aria-label="Tests counter on page">
218
229
  <option value="0">10</option>
219
230
  <option value="1">25</option>
220
231
  <option value="2">50</option>
221
- </select>`
222
- )
232
+ </select>`,
233
+ ),
223
234
  );
224
235
 
225
236
  handlebars.registerHelper(
226
237
  'emptyDataComponent',
227
- () => new handlebars.SafeString(
228
- `<div class="noData m-0">
238
+ () =>
239
+ new handlebars.SafeString(
240
+ `<div class="noData m-0">
229
241
  NO MATCHING TESTS
230
- </div>`
231
- )
242
+ </div>`,
243
+ ),
232
244
  );
233
245
 
234
- handlebars.registerHelper(
235
- 'pageDispleyElements',
236
- tests => {
237
- // We wrapp the lines to the HTML format we need
238
- const totalTests =
239
- JSON.parse(
240
- JSON.stringify(tests)
241
- .replace(/<script>/g, '&lt;script&gt;')
242
- .replace(/<\/script>/g, '&lt;\/script&gt;') // eslint-disable-line
243
- );
244
-
245
- const paginationOptions = {
246
- '0': 10,
247
- '1': 25,
248
- '2': 50
249
- };
250
- const statuses = [
251
- 'all',
252
- 'passed',
253
- 'failed',
254
- 'skipped'
255
- ];
256
- const pageItemGroups = {
257
- 'all': {},
258
- 'passed': {},
259
- 'failed': {},
260
- 'skipped': {},
261
- 'totalTests': totalTests
262
- };
263
-
264
- function paginateItems(items, pageSize) {
265
- const paginatedItems = [];
266
- for (let i = 0; i < items.length; i += pageSize) {
267
- paginatedItems.push(items.slice(i, i + pageSize));
268
- }
269
- return paginatedItems;
246
+ handlebars.registerHelper('pageDispleyElements', tests => {
247
+ // We wrapp the lines to the HTML format we need
248
+ const totalTests = JSON.parse(
249
+ JSON.stringify(tests)
250
+ .replace(/<script>/g, '&lt;script&gt;')
251
+ .replace(/<\/script>/g, '&lt;/script&gt;'), // eslint-disable-line
252
+ );
253
+
254
+ const paginationOptions = {
255
+ 0: 10,
256
+ 1: 25,
257
+ 2: 50,
258
+ };
259
+ const statuses = ['all', 'passed', 'failed', 'skipped'];
260
+ const pageItemGroups = {
261
+ all: {},
262
+ passed: {},
263
+ failed: {},
264
+ skipped: {},
265
+ totalTests,
266
+ };
267
+
268
+ function paginateItems(items, pageSize) {
269
+ const paginatedItems = [];
270
+ for (let i = 0; i < items.length; i += pageSize) {
271
+ paginatedItems.push(items.slice(i, i + pageSize));
270
272
  }
273
+ return paginatedItems;
274
+ }
275
+
276
+ statuses.forEach(status => {
277
+ for (const option in paginationOptions) {
278
+ if (Object.hasOwnProperty.call(paginationOptions, option)) {
279
+ const pageSize = paginationOptions[option];
280
+ let filteredItems = totalTests;
281
+
282
+ if (status !== 'all') {
283
+ filteredItems = totalTests.filter(item => item.status === status);
284
+ }
271
285
 
272
- statuses.forEach(status => {
273
- for (const option in paginationOptions) {
274
- if (Object.hasOwnProperty.call(paginationOptions, option)) {
275
- const pageSize = paginationOptions[option];
276
- let filteredItems = totalTests;
277
-
278
- if (status !== 'all') {
279
- filteredItems = totalTests.filter(item => item.status === status);
280
- }
281
-
282
- pageItemGroups[status][option] = paginateItems(filteredItems, pageSize);
283
- }
286
+ pageItemGroups[status][option] = paginateItems(filteredItems, pageSize);
284
287
  }
285
- });
286
-
287
- pageItemGroups.totalTests = totalTests;
288
+ }
289
+ });
288
290
 
289
- return JSON.stringify(pageItemGroups);
290
- }
291
- );
291
+ pageItemGroups.totalTests = totalTests;
292
+
293
+ return JSON.stringify(pageItemGroups);
294
+ });
292
295
  }
293
296
 
294
297
  toString() {
@@ -304,7 +307,7 @@ class HtmlPipe {
304
307
  */
305
308
  function testExecutionSumTime(tests) {
306
309
  const totalMilliseconds = tests.reduce((sum, test) => {
307
- if (typeof test.run_time === 'number') {
310
+ if (typeof test.run_time === 'number' && !Number.isNaN(test.run_time)) {
308
311
  return sum + test.run_time;
309
312
  }
310
313
  return sum;
@@ -654,7 +654,7 @@
654
654
  content_files = content.querySelector('div[type="files"]').querySelector('span');
655
655
 
656
656
  content_error.innerHTML = steps;
657
- content_status.innerHTML = category;
657
+ content_status.innerHTML = category.toUpperCase();
658
658
  content_message.innerHTML = message;
659
659
  //if no file - empty message, else - files
660
660
  (files.includes("This test has no files"))
@@ -688,10 +688,11 @@
688
688
 
689
689
  function createFileItemContainer(file) {
690
690
  let fileIcon;
691
- const fileName = createFileName(file),
692
- fileItemContainer = document.createElement('div');
693
691
 
694
- const fileExtension = file.path.split('.').pop().toLowerCase();
692
+ const filepath = file?.path || file;
693
+ const fileName = createFileName(file);
694
+ const fileItemContainer = document.createElement('div');
695
+ const fileExtension = filepath.split('.').pop().toLowerCase();
695
696
 
696
697
  fileItemContainer.classList.add('d-flex', 'flex-column', 'align-items-center', 'mr-3');
697
698
 
@@ -782,22 +783,26 @@
782
783
  }
783
784
 
784
785
  function createImagePreview(file) {
786
+ //TODO: consider using "../${file}", maybe we should get full paths when generating artifacts in Mocha!
787
+ const filepath = file?.path || `../${file}`;
785
788
  const imagePreview = document.createElement('img');
786
789
  // component styles
787
- imagePreview.src = file.path;
790
+ imagePreview.src = filepath;
788
791
  imagePreview.alt = 'Image Preview';
789
- imagePreview.style.maxWidth = '150px';
790
- imagePreview.style.height = '200px';
792
+ imagePreview.style.maxWidth = '200px';
793
+ imagePreview.style.height = '150px';
791
794
  imagePreview.style.cursor = 'pointer';
792
795
 
793
796
  imagePreview.addEventListener('click', () => {
794
- window.open(file.path, '_blank');
797
+ window.open(filepath, '_blank');
795
798
  });
796
799
 
797
800
  return imagePreview;
798
801
  }
799
802
 
800
803
  function createFileIcon(file, svg) {
804
+ //TODO: consider using "../${file}", maybe we should get full paths when generating artifacts in Mocha!
805
+ const filepath = file?.path || `../${file}`;
801
806
  const fileIcon = document.createElement('div');
802
807
  // component styles
803
808
  fileIcon.innerHTML = svg;
@@ -806,23 +811,25 @@
806
811
  fileIcon.style.cursor = 'pointer';
807
812
 
808
813
  fileIcon.addEventListener('click', () => {
809
- window.open(file.path, '_blank');
814
+ window.open(filepath, '_blank');
810
815
  });
811
816
 
812
817
  return fileIcon;
813
818
  }
814
819
 
815
820
  function createFileName(file) {
821
+ //TODO: consider using "../${file}", maybe we should get full paths when generating artifacts in Mocha!
822
+ const filepath = file?.path || `../${file}`;
816
823
  const fileName = document.createElement('div');
817
824
  // component styles
818
825
  fileName.style.fontSize = '14px';
819
826
  fileName.style.marginTop = '10px';
820
827
  fileName.style.cursor = 'pointer';
821
828
 
822
- fileName.textContent = file.path.split('/').pop().split('.').slice(0, -1).join('.');
829
+ fileName.textContent = filepath.split('/').pop();
823
830
 
824
831
  fileName.addEventListener('click', () => {
825
- window.open(file.path, '_blank');
832
+ window.open(filepath, '_blank');
826
833
  });
827
834
 
828
835
  return fileName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.2.2-beta-html-pagination-feature",
3
+ "version": "1.2.2-beta-html-pagination-feature-v2",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",