@testomatio/reporter 1.2.0-beta-1 → 1.2.0-beta-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.
package/lib/pipe/html.js CHANGED
@@ -5,7 +5,7 @@ const path = require('path');
5
5
  const chalk = require('chalk');
6
6
  const handlebars = require('handlebars');
7
7
 
8
- const { fileSystem, isSameTest } = require('../utils/utils');
8
+ const { fileSystem, isSameTest, ansiRegExp } = require('../utils/utils');
9
9
  const { HTML_REPORT } = require('../constants');
10
10
 
11
11
  class HtmlPipe {
@@ -74,6 +74,8 @@ class HtmlPipe {
74
74
  addTest(test) {
75
75
  if (!this.isEnabled) return;
76
76
 
77
+ if (!test.steps || !test.status) return;
78
+
77
79
  const index = this.tests.findIndex(t => isSameTest(t, test));
78
80
  // update if they were already added
79
81
  if (index >= 0) {
@@ -88,6 +90,37 @@ class HtmlPipe {
88
90
  if (!this.isEnabled) return;
89
91
 
90
92
  if (this.isHtml) {
93
+
94
+ this.tests.forEach(test => {
95
+
96
+ if (!test.message || test.message.trim() === "") {
97
+ test.message = "This test has no 'message' code";
98
+ }
99
+
100
+ if (!test.suite_title || test.suite_title.trim() === "") {
101
+ test.suite_title = "Unknown suite";
102
+ }
103
+
104
+ if (!test.title || test.title.trim() === "") {
105
+ test.title = "Unknown test title";
106
+ }
107
+
108
+ if (!test.files || test.files.length === 0) {
109
+ test.files = "This test has no files";
110
+ }
111
+
112
+ if (test.steps) {
113
+ if (!test.steps || test.steps.trim() === "") {
114
+ test.steps = "This test has no 'steps' code";
115
+ }
116
+ else {
117
+ test.steps = this.#removeAnsiColorCodes(test.steps);
118
+ }
119
+ }
120
+
121
+ // TODO: u can added an additional test values to this checks in the future
122
+ });
123
+
91
124
  this.data = {
92
125
  runId: this.store.runId,
93
126
  status: runParams.status,
@@ -142,7 +175,49 @@ class HtmlPipe {
142
175
  tests.filter(test => test.status.toLowerCase() === status.toLowerCase()).length
143
176
  );
144
177
 
145
- handlebars.registerHelper('json', (obj) => JSON.stringify(obj));
178
+ handlebars.registerHelper('json', (tests) => {
179
+ function replaceScriptTagsInArray(array) {
180
+ return array.map(obj => {
181
+ const keysToCheck = ["steps", "stack", "title", "suite_title", "message", "code"];
182
+ const newObj = {};
183
+
184
+ for (const key in obj) {
185
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
186
+ if (key === "example") {
187
+ newObj[key] = {};
188
+ for (const subKey in obj[key]) {
189
+ if (Object.prototype.hasOwnProperty.call(obj[key], subKey)) {
190
+ newObj[key][subKey] = typeof obj[key][subKey] === "string"
191
+ ? obj[key][subKey]
192
+ .replace(/<script>/g, "<$cript>")
193
+ .replace(/<\/script>/g, "</$cript>")
194
+ : obj[key][subKey];
195
+ }
196
+ }
197
+ } else if (keysToCheck.includes(key)) {
198
+ newObj[key] = typeof obj[key] === "string"
199
+ ? obj[key].replace(/<script>/g, "<$cript>").replace(/<\/script>/g, "</$cript>")
200
+ : obj[key];
201
+ } else {
202
+ newObj[key] = obj[key];
203
+ }
204
+ }
205
+ }
206
+
207
+ return newObj;
208
+ });
209
+ }
210
+
211
+ // Remove ANSI escape codes
212
+ return JSON.stringify(replaceScriptTagsInArray(tests));
213
+ });
214
+ }
215
+
216
+ #removeAnsiColorCodes(str) {
217
+ let updatedStr = str.replace(ansiRegExp(), "");
218
+ updatedStr = updatedStr.replace(/\n/g, '<br>');
219
+
220
+ return updatedStr;
146
221
  }
147
222
 
148
223
  toString() {
@@ -471,8 +471,8 @@
471
471
  }
472
472
 
473
473
  // processing and adding test data to the template
474
- function addOneTest(category,testInfo = {}){
475
- const { suite, title, steps, message, files } = testInfo;
474
+ function addOneTest(category,testData = {}){
475
+ const { suite_title, title, steps, message, files } = testData;
476
476
  // radio btn test's count
477
477
  function incrementCount(element) {
478
478
  let count = parseInt(element.textContent);
@@ -562,7 +562,7 @@
562
562
 
563
563
  const testitem__name = clone.querySelector('.testitem__name');
564
564
 
565
- const fullTestName = suite ? suite + " - " + title : title;
565
+ const fullTestName = suite_title ? suite_title + " - " + title : title;
566
566
  testitem__name.textContent = fullTestName;
567
567
 
568
568
  const body = clone.querySelector('.testitem__body');
@@ -579,11 +579,16 @@
579
579
 
580
580
  let content_files = content.querySelector('div[type="files"]').querySelector('span');
581
581
 
582
- if (files && files.length > 0) {
582
+ if (files.includes("This test has no files")) {
583
+ content_files.innerHTML = files;
584
+ }
585
+
586
+ if (!files.includes("This test has no files")) {
583
587
  const filesList = document.createElement('ul');
584
588
  content_files.innerHTML = "";
585
589
 
586
- files.forEach((file) => {
590
+ if (Array.isArray(files) && files.length > 0) {
591
+ files.forEach((file) => {
587
592
  const listItem = document.createElement('li');
588
593
  const fileLink = document.createElement('a');
589
594
  fileLink.href = file.path;
@@ -594,10 +599,9 @@
594
599
  filesList.appendChild(listItem);
595
600
  });
596
601
 
597
- content_files.appendChild(filesList);
598
- }
599
- else {
600
- content_files.innerHTML = "Files are not found for this test";
602
+ content_files.appendChild(filesList);
603
+
604
+ }
601
605
  }
602
606
 
603
607
  const testitem__top = clone.querySelector('.testitem__top');
@@ -680,40 +684,11 @@
680
684
  search();
681
685
 
682
686
  const executedTests = {{{ json tests }}};
683
-
684
- // TODO: move to HTML pipe
685
- function removeAnsiColorCodes(text) {
686
- text = text.replace(/\u001b\[[0-9;]*m/g, '');
687
- text = text.replace(/\n/g, '<br>');
688
-
689
- return text;
690
- }
691
687
 
692
688
  for (let i = 0; i < executedTests.length; i++) {
693
689
  const status = executedTests[i].status;
694
- const testInfo = {
695
- suite: executedTests[i].suite_title,
696
- title: executedTests[i].title,
697
- steps: removeAnsiColorCodes(executedTests[i].steps),
698
- message: executedTests[i].message,
699
- files: executedTests[i].files,
700
- status: status,
701
- }
702
-
703
- if (!testInfo.steps && testInfo.steps.trim() === "") {
704
- testInfo.steps = "Step code is not found for this test";
705
- }
706
-
707
- if (!testInfo.message && testInfo.message.trim() === "") {
708
- testInfo.message = "Message code is not found for this test";
709
- }
710
-
711
- if (!testInfo.suite && testInfo.suite.trim() === "") {
712
- testInfo.suite = "Unknown suite";
713
- }
714
690
 
715
- // call the addOneTest() function for each test
716
- addOneTest(status, testInfo);
691
+ addOneTest(status, executedTests[i]);
717
692
  }
718
693
  </script>
719
694
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.2.0-beta-1",
3
+ "version": "1.2.0-beta-2",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",