@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 +72 -69
- package/lib/template/testomatio.hbs +18 -11
- package/package.json +1 -1
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 (
|
|
139
|
-
test.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
|
|
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
|
-
|
|
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
|
-
() =>
|
|
217
|
-
|
|
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
|
-
() =>
|
|
228
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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, '<script>')
|
|
251
|
+
.replace(/<\/script>/g, '</script>'), // 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
|
-
|
|
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
|
-
|
|
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
|
|
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 =
|
|
790
|
+
imagePreview.src = filepath;
|
|
788
791
|
imagePreview.alt = 'Image Preview';
|
|
789
|
-
imagePreview.style.maxWidth = '
|
|
790
|
-
imagePreview.style.height = '
|
|
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(
|
|
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(
|
|
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 =
|
|
829
|
+
fileName.textContent = filepath.split('/').pop();
|
|
823
830
|
|
|
824
831
|
fileName.addEventListener('click', () => {
|
|
825
|
-
window.open(
|
|
832
|
+
window.open(filepath, '_blank');
|
|
826
833
|
});
|
|
827
834
|
|
|
828
835
|
return fileName;
|
package/package.json
CHANGED