@testomatio/reporter 1.6.0-beta-2-artifacts → 2.0.0-beta-esm

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.
Files changed (97) hide show
  1. package/lib/adapter/codecept.js +288 -330
  2. package/lib/adapter/cucumber/current.js +195 -203
  3. package/lib/adapter/cucumber/legacy.js +130 -155
  4. package/lib/adapter/cucumber.js +5 -16
  5. package/lib/adapter/cypress-plugin/index.js +91 -105
  6. package/lib/adapter/jasmine/jasmine.js +63 -0
  7. package/lib/adapter/jasmine.js +54 -53
  8. package/lib/adapter/jest.js +97 -99
  9. package/lib/adapter/mocha/mocha.js +125 -0
  10. package/lib/adapter/mocha.js +111 -140
  11. package/lib/adapter/playwright.js +168 -200
  12. package/lib/adapter/vitest.js +144 -143
  13. package/lib/adapter/webdriver.js +113 -97
  14. package/lib/bin/reportXml.js +49 -49
  15. package/lib/bin/startTest.js +80 -97
  16. package/lib/client.js +344 -385
  17. package/lib/config.js +16 -21
  18. package/lib/constants.js +49 -43
  19. package/lib/data-storage.js +206 -188
  20. package/lib/fileUploader.js +245 -0
  21. package/lib/junit-adapter/adapter.js +17 -20
  22. package/lib/junit-adapter/csharp.js +18 -14
  23. package/lib/junit-adapter/index.js +27 -25
  24. package/lib/junit-adapter/java.js +41 -53
  25. package/lib/junit-adapter/javascript.js +30 -27
  26. package/lib/junit-adapter/python.js +38 -37
  27. package/lib/junit-adapter/ruby.js +11 -8
  28. package/lib/output.js +44 -52
  29. package/lib/package.json +1 -0
  30. package/lib/pipe/bitbucket.js +208 -227
  31. package/lib/pipe/csv.js +111 -124
  32. package/lib/pipe/github.js +184 -211
  33. package/lib/pipe/gitlab.js +164 -205
  34. package/lib/pipe/html.js +253 -312
  35. package/lib/pipe/index.js +83 -63
  36. package/lib/pipe/testomatio.js +391 -454
  37. package/lib/reporter-functions.js +16 -20
  38. package/lib/reporter.js +47 -17
  39. package/lib/services/artifacts.js +55 -51
  40. package/lib/services/index.js +14 -12
  41. package/lib/services/key-values.js +56 -53
  42. package/lib/services/logger.js +227 -245
  43. package/lib/utils/chalk.js +10 -0
  44. package/lib/utils/pipe_utils.js +91 -84
  45. package/lib/utils/utils.js +289 -273
  46. package/lib/xmlReader.js +480 -519
  47. package/package.json +57 -19
  48. package/src/adapter/codecept.js +369 -0
  49. package/src/adapter/cucumber/current.js +228 -0
  50. package/src/adapter/cucumber/legacy.js +158 -0
  51. package/src/adapter/cucumber.js +4 -0
  52. package/src/adapter/cypress-plugin/index.js +110 -0
  53. package/src/adapter/jasmine.js +60 -0
  54. package/src/adapter/jest.js +107 -0
  55. package/src/adapter/mocha.cjs +2 -0
  56. package/src/adapter/mocha.js +156 -0
  57. package/src/adapter/playwright.js +222 -0
  58. package/src/adapter/vitest.js +183 -0
  59. package/src/adapter/webdriver.js +111 -0
  60. package/src/bin/reportXml.js +67 -0
  61. package/src/bin/startTest.js +119 -0
  62. package/src/client.js +423 -0
  63. package/src/config.js +30 -0
  64. package/src/constants.js +49 -0
  65. package/src/data-storage.js +204 -0
  66. package/src/fileUploader.js +307 -0
  67. package/src/junit-adapter/adapter.js +23 -0
  68. package/src/junit-adapter/csharp.js +16 -0
  69. package/src/junit-adapter/index.js +28 -0
  70. package/src/junit-adapter/java.js +58 -0
  71. package/src/junit-adapter/javascript.js +31 -0
  72. package/src/junit-adapter/python.js +42 -0
  73. package/src/junit-adapter/ruby.js +10 -0
  74. package/src/output.js +57 -0
  75. package/src/pipe/bitbucket.js +254 -0
  76. package/src/pipe/csv.js +140 -0
  77. package/src/pipe/github.js +234 -0
  78. package/src/pipe/gitlab.js +229 -0
  79. package/src/pipe/html.js +366 -0
  80. package/src/pipe/index.js +73 -0
  81. package/src/pipe/testomatio.js +498 -0
  82. package/src/reporter-functions.js +44 -0
  83. package/src/reporter.cjs +22 -0
  84. package/src/reporter.js +24 -0
  85. package/src/services/artifacts.js +59 -0
  86. package/src/services/index.js +13 -0
  87. package/src/services/key-values.js +59 -0
  88. package/src/services/logger.js +314 -0
  89. package/src/template/emptyData.svg +23 -0
  90. package/src/template/testomatio.hbs +1421 -0
  91. package/src/utils/chalk.js +13 -0
  92. package/src/utils/pipe_utils.js +127 -0
  93. package/src/utils/utils.js +341 -0
  94. package/src/xmlReader.js +551 -0
  95. package/lib/bin/cli.js +0 -216
  96. package/lib/bin/uploadArtifacts.js +0 -86
  97. package/lib/uploader.js +0 -312
package/lib/pipe/html.js CHANGED
@@ -1,234 +1,195 @@
1
- const debug = require('debug')('@testomatio/reporter:pipe:html');
2
- const merge = require('lodash.merge');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const chalk = require('chalk');
6
- const handlebars = require('handlebars');
7
- const fileUrl = require('file-url');
8
-
9
- const { fileSystem, isSameTest, ansiRegExp } = require('../utils/utils');
10
- const { HTML_REPORT } = require('../constants');
11
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const debug_1 = __importDefault(require("debug"));
7
+ const lodash_merge_1 = __importDefault(require("lodash.merge"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const picocolors_1 = __importDefault(require("picocolors"));
11
+ const handlebars_1 = __importDefault(require("handlebars"));
12
+ const file_url_1 = __importDefault(require("file-url"));
13
+ const utils_js_1 = require("../utils/utils.js");
14
+ const constants_js_1 = require("../constants.js");
15
+ const node_url_1 = require("node:url");
16
+ const debug = (0, debug_1.default)('@testomatio/reporter:pipe:html');
17
+ // @ts-ignore – this line will be removed in compiled code (already defined in the global scope of commonjs)
12
18
  class HtmlPipe {
13
- constructor(params, store = {}) {
14
- this.store = store || {};
15
- this.title = params.title || process.env.TESTOMATIO_TITLE;
16
- this.apiKey = params.apiKey || process.env.TESTOMATIO;
17
- this.isHtml = process.env.TESTOMATIO_HTML_REPORT_SAVE;
18
-
19
- debug('HTML Pipe: ', this.apiKey ? 'API KEY' : '*no api key provided*');
20
-
21
- this.isEnabled = false;
22
- this.htmlOutputPath = '';
23
- this.fullHtmlOutputPath = '';
24
- this.filenameMsg = '';
25
- this.tests = [];
26
-
27
- if (this.isHtml) {
28
- this.isEnabled = true;
29
- this.htmlReportDir = process.env.TESTOMATIO_HTML_REPORT_FOLDER || HTML_REPORT.FOLDER;
30
-
31
- if (process.env.TESTOMATIO_HTML_FILENAME && process.env.TESTOMATIO_HTML_FILENAME.endsWith('.html')) {
32
- this.htmlReportName = process.env.TESTOMATIO_HTML_FILENAME;
33
- }
34
-
35
- if (process.env.TESTOMATIO_HTML_FILENAME && !process.env.TESTOMATIO_HTML_FILENAME.endsWith('.html')) {
36
- this.htmlReportName = HTML_REPORT.REPORT_DEFAULT_NAME;
37
- this.filenameMsg =
38
- 'HTML filename must include the extension ".html".' +
39
- ` The default report name "${this.htmlReportDir}/${HTML_REPORT.REPORT_DEFAULT_NAME}" is used!`;
40
- }
41
-
42
- if (!process.env.TESTOMATIO_HTML_FILENAME) {
43
- this.htmlReportName = HTML_REPORT.REPORT_DEFAULT_NAME;
44
- }
45
-
46
- this.templateFolderPath = path.resolve(__dirname, '..', 'template');
47
- this.templateHtmlPath = path.resolve(this.templateFolderPath, HTML_REPORT.TEMPLATE_NAME);
48
- this.htmlOutputPath = path.join(this.htmlReportDir, this.htmlReportName);
49
- // create a new folder for the HTML reports
50
- fileSystem.createDir(this.htmlReportDir);
51
-
52
- debug(
53
- chalk.yellow('HTML Pipe:'),
54
- `Save HTML report: ${this.isEnabled}`,
55
- `HTML report folder: ${this.htmlReportDir}, report name: ${this.htmlReportName}`,
56
- );
57
- }
58
- }
59
-
60
- async createRun() {
61
- // empty
62
- }
63
-
64
- updateRun() {
65
- // empty
66
- }
67
-
68
- /**
69
- * Add test data to the result array for saving. As a result of this function, we get a result object to save.
70
- * @param {import('../../types').RunData} test - object which includes each test entry.
71
- */
72
- addTest(test) {
73
- if (!this.isEnabled) return;
74
-
75
- if (!test.status) return;
76
-
77
- const index = this.tests.findIndex(t => isSameTest(t, test));
78
- // update if they were already added
79
- if (index >= 0) {
80
- this.tests[index] = merge(this.tests[index], test);
81
- return;
19
+ constructor(params, store = {}) {
20
+ this.store = store || {};
21
+ this.title = params.title || process.env.TESTOMATIO_TITLE;
22
+ this.apiKey = params.apiKey || process.env.TESTOMATIO;
23
+ this.isHtml = process.env.TESTOMATIO_HTML_REPORT_SAVE;
24
+ debug('HTML Pipe: ', this.apiKey ? 'API KEY' : '*no api key provided*');
25
+ this.isEnabled = false;
26
+ this.htmlOutputPath = '';
27
+ this.fullHtmlOutputPath = '';
28
+ this.filenameMsg = '';
29
+ this.tests = [];
30
+ if (this.isHtml) {
31
+ this.isEnabled = true;
32
+ this.htmlReportDir = process.env.TESTOMATIO_HTML_REPORT_FOLDER || constants_js_1.HTML_REPORT.FOLDER;
33
+ if (process.env.TESTOMATIO_HTML_FILENAME && process.env.TESTOMATIO_HTML_FILENAME.endsWith('.html')) {
34
+ this.htmlReportName = process.env.TESTOMATIO_HTML_FILENAME;
35
+ }
36
+ if (process.env.TESTOMATIO_HTML_FILENAME && !process.env.TESTOMATIO_HTML_FILENAME.endsWith('.html')) {
37
+ this.htmlReportName = constants_js_1.HTML_REPORT.REPORT_DEFAULT_NAME;
38
+ this.filenameMsg =
39
+ 'HTML filename must include the extension ".html".' +
40
+ ` The default report name "${this.htmlReportDir}/${constants_js_1.HTML_REPORT.REPORT_DEFAULT_NAME}" is used!`;
41
+ }
42
+ if (!process.env.TESTOMATIO_HTML_FILENAME) {
43
+ this.htmlReportName = constants_js_1.HTML_REPORT.REPORT_DEFAULT_NAME;
44
+ }
45
+ this.templateFolderPath = path_1.default.resolve(__dirname, '..', 'template');
46
+ this.templateHtmlPath = path_1.default.resolve(this.templateFolderPath, constants_js_1.HTML_REPORT.TEMPLATE_NAME);
47
+ this.htmlOutputPath = path_1.default.join(this.htmlReportDir, this.htmlReportName);
48
+ // create a new folder for the HTML reports
49
+ utils_js_1.fileSystem.createDir(this.htmlReportDir);
50
+ debug(picocolors_1.default.yellow('HTML Pipe:'), `Save HTML report: ${this.isEnabled}`, `HTML report folder: ${this.htmlReportDir}, report name: ${this.htmlReportName}`);
51
+ }
82
52
  }
83
-
84
- this.tests.push(test);
85
- }
86
-
87
- async finishRun(runParams) {
88
- if (!this.isEnabled) return;
89
-
90
- if (this.isHtml) {
91
- // GENERATE HTML reports based on the results data
92
- this.buildReport({
93
- runParams,
94
- // TODO: this.tests=[] in case of Mocha, need retest by Vitalii
95
- tests: this.tests,
96
- outputPath: this.htmlOutputPath,
97
- templatePath: this.templateHtmlPath,
98
- warningMsg: this.filenameMsg,
99
- });
53
+ async createRun() {
54
+ // empty
100
55
  }
101
- }
102
- /**
103
- * Generates an HTML report based on provided test data and a template.
104
- * @param {object} opts - Test options used to generate the HTML report:
105
- * runParams, tests, outputPath, templatePath
106
- * @returns {void} - This function does not return anything.
107
- */
108
-
109
- buildReport(opts) {
110
- const { runParams, tests, outputPath, templatePath, warningMsg: msg } = opts;
111
-
112
- debug('HTML tests data:', tests);
113
-
114
- if (!outputPath) {
115
- console.log(chalk.yellow(`🚨 HTML export path is not set, ignoring...`));
116
- return;
56
+ updateRun() {
57
+ // empty
117
58
  }
118
-
119
- console.log(chalk.yellow(`⏳ The test results will be added to the HTML report. It will take some time...`));
120
-
121
- if (msg) {
122
- console.log(chalk.blue(msg));
59
+ /**
60
+ * Add test data to the result array for saving. As a result of this function, we get a result object to save.
61
+ * @param {import('../../types').RunData} test - object which includes each test entry.
62
+ */
63
+ addTest(test) {
64
+ if (!this.isEnabled)
65
+ return;
66
+ if (!test.status)
67
+ return;
68
+ const index = this.tests.findIndex(t => (0, utils_js_1.isSameTest)(t, test));
69
+ // update if they were already added
70
+ if (index >= 0) {
71
+ this.tests[index] = (0, lodash_merge_1.default)(this.tests[index], test);
72
+ return;
73
+ }
74
+ this.tests.push(test);
123
75
  }
124
-
125
- tests.forEach(test => {
126
- if (!test.message?.trim()) {
127
- test.message = "This test has no 'message' code";
128
- }
129
-
130
- if (!test.suite_title?.trim()) {
131
- test.suite_title = 'Unknown suite';
132
- }
133
-
134
- if (!test.title?.trim()) {
135
- test.title = 'Unknown test title';
136
- }
137
-
138
- if (!test.files?.length) {
139
- test.files = 'This test has no files';
140
- }
141
-
142
- if (!test.steps?.trim()) {
143
- test.steps = "This test has no 'steps' code";
144
- } else {
145
- test.steps = removeAnsiColorCodes(test.steps);
146
- }
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 || {};
151
- // TODO: u can added an additional test values to this checks in the future
152
- });
153
-
154
- const data = {
155
- runId: this.store.runId || '',
156
- status: runParams.status || 'No status info',
157
- parallel: runParams.isParallel || 'No parallel info',
158
- runUrl: this.store.runUrl || '',
159
- executionTime: testExecutionSumTime(tests),
160
- executionDate: getCurrentDateTimeFormatted(),
161
- tests,
162
- };
163
- // generate output HTML based on the template
164
- const html = this.#generateHTMLReport(data, templatePath);
165
-
166
- if (!html) return;
167
-
168
- fs.writeFileSync(outputPath, html, 'utf-8');
169
- // Check if the file exists
170
- if (fs.existsSync(outputPath)) {
171
- // Get the absolute path of the file
172
- const absolutePath = path.resolve(outputPath);
173
- // Convert the file path to a file URL
174
- const fileUrlPath = fileUrl(absolutePath, { resolve: true });
175
-
176
- debug('HTML tests data:', fileUrlPath);
177
-
178
- console.log(chalk.green(`📊 The HTML report was successfully generated. Full filepath: ${fileUrlPath}`));
179
- } else {
180
- console.log(chalk.red(`🚨 Failed to generate the HTML report.`));
76
+ async finishRun(runParams) {
77
+ if (!this.isEnabled)
78
+ return;
79
+ if (this.isHtml) {
80
+ // GENERATE HTML reports based on the results data
81
+ this.buildReport({
82
+ runParams,
83
+ // TODO: this.tests=[] in case of Mocha, need retest by Vitalii
84
+ tests: this.tests,
85
+ outputPath: this.htmlOutputPath,
86
+ templatePath: this.templateHtmlPath,
87
+ warningMsg: this.filenameMsg,
88
+ });
89
+ }
181
90
  }
182
- }
183
-
184
- /**
185
- * Generates an HTML report based on provided test data and a template path.
186
- * @param {any} data - Test data used to generate the HTML report.
187
- * @param {string} [templatePath=""] - The path to the HTML template used for generating the report.
188
- * @returns {string | void} - The generated HTML report as a string or void if templatePath is not provided.
189
- */
190
- #generateHTMLReport(data, templatePath = '') {
191
- if (!templatePath) {
192
- console.log(chalk.red(`🚨 HTML template not found. Report generation is impossible!`));
193
- return;
91
+ /**
92
+ * Generates an HTML report based on provided test data and a template.
93
+ * @param {object} opts - Test options used to generate the HTML report:
94
+ * runParams, tests, outputPath, templatePath
95
+ * @returns {void} - This function does not return anything.
96
+ */
97
+ buildReport(opts) {
98
+ const { runParams, tests, outputPath, templatePath, warningMsg: msg } = opts;
99
+ debug('HTML tests data:', tests);
100
+ if (!outputPath) {
101
+ console.log(picocolors_1.default.yellow(`🚨 HTML export path is not set, ignoring...`));
102
+ return;
103
+ }
104
+ console.log(picocolors_1.default.yellow(`⏳ The test results will be added to the HTML report. It will take some time...`));
105
+ if (msg) {
106
+ console.log(picocolors_1.default.blue(msg));
107
+ }
108
+ tests.forEach(test => {
109
+ if (!test.message?.trim()) {
110
+ test.message = "This test has no 'message' code";
111
+ }
112
+ if (!test.suite_title?.trim()) {
113
+ test.suite_title = 'Unknown suite';
114
+ }
115
+ if (!test.title?.trim()) {
116
+ test.title = 'Unknown test title';
117
+ }
118
+ if (!test.files?.length) {
119
+ test.files = 'This test has no files';
120
+ }
121
+ if (!test.steps?.trim()) {
122
+ test.steps = "This test has no 'steps' code";
123
+ }
124
+ else {
125
+ test.steps = removeAnsiColorCodes(test.steps);
126
+ }
127
+ // TODO: future-proof: currently there is no need to display Artifacts and Metadata in HTML
128
+ test.artifacts = test.artifacts || [];
129
+ test.meta = test.meta || {};
130
+ // TODO: u can added an additional test values to this checks in the future
131
+ });
132
+ const data = {
133
+ runId: this.store.runId || '',
134
+ status: runParams.status || 'No status info',
135
+ parallel: runParams.isParallel || 'No parallel info',
136
+ runUrl: this.store.runUrl || '',
137
+ executionTime: testExecutionSumTime(tests),
138
+ executionDate: getCurrentDateTimeFormatted(),
139
+ tests,
140
+ };
141
+ // generate output HTML based on the template
142
+ const html = this.#generateHTMLReport(data, templatePath);
143
+ if (!html)
144
+ return;
145
+ fs_1.default.writeFileSync(outputPath, html, 'utf-8');
146
+ // Check if the file exists
147
+ if (fs_1.default.existsSync(outputPath)) {
148
+ // Get the absolute path of the file
149
+ const absolutePath = path_1.default.resolve(outputPath);
150
+ // Convert the file path to a file URL
151
+ const fileUrlPath = (0, file_url_1.default)(absolutePath, { resolve: true });
152
+ debug('HTML tests data:', fileUrlPath);
153
+ console.log(picocolors_1.default.green(`📊 The HTML report was successfully generated. Full filepath: ${fileUrlPath}`));
154
+ }
155
+ else {
156
+ console.log(picocolors_1.default.red(`🚨 Failed to generate the HTML report.`));
157
+ }
194
158
  }
195
-
196
- const templateSource = fs.readFileSync(templatePath, 'utf8');
197
- this.#loadReportHelpers();
198
- try {
199
- const template = handlebars.compile(templateSource);
200
-
201
- return template(data);
202
- } catch (e) {
203
- console.log(chalk.red('❌ Oops! An unknown error occurred when generating an HTML report'));
204
- console.log(chalk.red(e));
159
+ /**
160
+ * Generates an HTML report based on provided test data and a template path.
161
+ * @param {any} data - Test data used to generate the HTML report.
162
+ * @param {string} [templatePath=""] - The path to the HTML template used for generating the report.
163
+ * @returns {string | void} - The generated HTML report as a string or void if templatePath is not provided.
164
+ */
165
+ #generateHTMLReport(data, templatePath = '') {
166
+ if (!templatePath) {
167
+ console.log(picocolors_1.default.red(`🚨 HTML template not found. Report generation is impossible!`));
168
+ return;
169
+ }
170
+ const templateSource = fs_1.default.readFileSync(templatePath, 'utf8');
171
+ this.#loadReportHelpers();
172
+ try {
173
+ const template = handlebars_1.default.compile(templateSource);
174
+ return template(data);
175
+ }
176
+ catch (e) {
177
+ console.log(picocolors_1.default.red('❌ Oops! An unknown error occurred when generating an HTML report'));
178
+ console.log(picocolors_1.default.red(e));
179
+ }
205
180
  }
206
- }
207
-
208
- #loadReportHelpers() {
209
- handlebars.registerHelper(
210
- 'getTestsByStatus',
211
- (tests, status) => tests.filter(test => test.status.toLowerCase() === status.toLowerCase()).length,
212
- );
213
-
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">
181
+ #loadReportHelpers() {
182
+ handlebars_1.default.registerHelper('getTestsByStatus', (tests, status) => tests.filter(test => test.status.toLowerCase() === status.toLowerCase()).length);
183
+ handlebars_1.default.registerHelper('selectComponent', () => new handlebars_1.default.SafeString(`<select style="width: 70px;height: 38px;" class="form-select" aria-label="Tests counter on page">
219
184
  <option value="0">10</option>
220
185
  <option value="1">25</option>
221
186
  <option value="2">50</option>
222
- </select>`,
223
- ),
224
- );
225
- /* eslint-disable */
226
- handlebars.registerHelper('emptyDataComponent', () => {
227
- const svgFilePath = path.join(__dirname, '..', 'template', 'emptyData.svg');
228
- const svgContent = fs.readFileSync(svgFilePath, 'utf8');
229
-
230
- return new handlebars.SafeString(
231
- `
187
+ </select>`));
188
+ /* eslint-disable */
189
+ handlebars_1.default.registerHelper('emptyDataComponent', () => {
190
+ const svgFilePath = path_1.default.join(__dirname, '..', 'template', 'emptyData.svg');
191
+ const svgContent = fs_1.default.readFileSync(svgFilePath, 'utf8');
192
+ return new handlebars_1.default.SafeString(`
232
193
  <div class="noData">
233
194
  <div class="noDataSvg">
234
195
  ${svgContent}
@@ -236,67 +197,55 @@ class HtmlPipe {
236
197
  <div class="noDataText">
237
198
  NO MATCHING TESTS
238
199
  </div>
239
- <div>`,
240
- );
241
- });
242
- /* eslint-enable */
243
- handlebars.registerHelper('pageDispleyElements', tests => {
244
- // We wrapp the lines to the HTML format we need
245
- const totalTests = JSON.parse(
246
- JSON.stringify(tests)
247
- .replace(/<script>/g, '&lt;script&gt;')
248
- .replace(/<\/script>/g, '&lt;/script&gt;'), // eslint-disable-line
249
- );
250
-
251
- const paginationOptions = {
252
- 0: 10,
253
- 1: 25,
254
- 2: 50,
255
- };
256
- const statuses = ['all', 'passed', 'failed', 'skipped'];
257
- const pageItemGroups = {
258
- all: {},
259
- passed: {},
260
- failed: {},
261
- skipped: {},
262
- totalTests,
263
- };
264
-
265
- function paginateItems(items, pageSize) {
266
- const paginatedItems = [];
267
- for (let i = 0; i < items.length; i += pageSize) {
268
- paginatedItems.push(items.slice(i, i + pageSize));
269
- }
270
- return paginatedItems;
271
- }
272
-
273
- statuses.forEach(status => {
274
- for (const option in paginationOptions) {
275
- // eslint-disable-next-line no-prototype-builtins
276
- if (paginationOptions.hasOwnProperty(option)) {
277
- const pageSize = paginationOptions[option];
278
- let filteredItems = totalTests;
279
-
280
- if (status !== 'all') {
281
- filteredItems = totalTests.filter(item => item.status === status);
200
+ <div>`);
201
+ });
202
+ /* eslint-enable */
203
+ handlebars_1.default.registerHelper('pageDispleyElements', tests => {
204
+ // We wrapp the lines to the HTML format we need
205
+ const totalTests = JSON.parse(JSON.stringify(tests)
206
+ .replace(/<script>/g, '&lt;script&gt;')
207
+ .replace(/<\/script>/g, '&lt;/script&gt;'));
208
+ const paginationOptions = {
209
+ 0: 10,
210
+ 1: 25,
211
+ 2: 50,
212
+ };
213
+ const statuses = ['all', 'passed', 'failed', 'skipped'];
214
+ const pageItemGroups = {
215
+ all: {},
216
+ passed: {},
217
+ failed: {},
218
+ skipped: {},
219
+ totalTests,
220
+ };
221
+ function paginateItems(items, pageSize) {
222
+ const paginatedItems = [];
223
+ for (let i = 0; i < items.length; i += pageSize) {
224
+ paginatedItems.push(items.slice(i, i + pageSize));
225
+ }
226
+ return paginatedItems;
282
227
  }
283
-
284
- pageItemGroups[status][option] = paginateItems(filteredItems, pageSize);
285
- }
286
- }
287
- });
288
-
289
- pageItemGroups.totalTests = totalTests;
290
-
291
- return JSON.stringify(pageItemGroups);
292
- });
293
- }
294
-
295
- toString() {
296
- return 'HTML Reporter';
297
- }
228
+ statuses.forEach(status => {
229
+ for (const option in paginationOptions) {
230
+ // eslint-disable-next-line no-prototype-builtins
231
+ if (paginationOptions.hasOwnProperty(option)) {
232
+ const pageSize = paginationOptions[option];
233
+ let filteredItems = totalTests;
234
+ if (status !== 'all') {
235
+ filteredItems = totalTests.filter(item => item.status === status);
236
+ }
237
+ pageItemGroups[status][option] = paginateItems(filteredItems, pageSize);
238
+ }
239
+ }
240
+ });
241
+ pageItemGroups.totalTests = totalTests;
242
+ return JSON.stringify(pageItemGroups);
243
+ });
244
+ }
245
+ toString() {
246
+ return 'HTML Reporter';
247
+ }
298
248
  }
299
-
300
249
  /**
301
250
  * Calculates the total execution time for an array of tests.
302
251
  * @param {Object[]} tests - An array of test objects.
@@ -304,58 +253,50 @@ class HtmlPipe {
304
253
  * @returns {string} - The total execution time in a formatted duration string.
305
254
  */
306
255
  function testExecutionSumTime(tests) {
307
- const totalMilliseconds = tests.reduce((sum, test) => {
308
- if (typeof test.run_time === 'number' && !Number.isNaN(test.run_time)) {
309
- return sum + test.run_time;
310
- }
311
- return sum;
312
- }, 0);
313
-
314
- return formatDuration(totalMilliseconds);
256
+ const totalMilliseconds = tests.reduce((sum, test) => {
257
+ if (typeof test.run_time === 'number' && !Number.isNaN(test.run_time)) {
258
+ return sum + test.run_time;
259
+ }
260
+ return sum;
261
+ }, 0);
262
+ return formatDuration(totalMilliseconds);
315
263
  }
316
-
317
264
  /**
318
265
  * Removes ANSI color codes and converts newline characters to HTML line breaks in a given string.
319
266
  * @param {string} str - The input string containing ANSI color codes.
320
267
  * @returns {string} - The updated string with removed ANSI color codes and replaced newline characters.
321
268
  */
322
269
  function removeAnsiColorCodes(str) {
323
- let updatedStr = str.replace(ansiRegExp(), '');
324
- updatedStr = updatedStr.replace(/\n/g, '<br>');
325
-
326
- return updatedStr;
270
+ let updatedStr = str.replace((0, utils_js_1.ansiRegExp)(), '');
271
+ updatedStr = updatedStr.replace(/\n/g, '<br>');
272
+ return updatedStr;
327
273
  }
328
-
329
274
  /**
330
275
  * Formats duration in milliseconds into a human-readable string representation.
331
276
  * @param {number} duration - The duration in milliseconds.
332
277
  * @returns {string} - The formatted duration string (e.g., "2h 30m 15s 500ms").
333
278
  */
334
279
  function formatDuration(duration) {
335
- const milliseconds = duration % 1000;
336
- duration = (duration - milliseconds) / 1000;
337
- const seconds = duration % 60;
338
- duration = (duration - seconds) / 60;
339
- const minutes = duration % 60;
340
- const hours = (duration - minutes) / 60;
341
-
342
- return `${hours}h ${minutes}m ${seconds}s ${milliseconds}ms`;
280
+ const milliseconds = duration % 1000;
281
+ duration = (duration - milliseconds) / 1000;
282
+ const seconds = duration % 60;
283
+ duration = (duration - seconds) / 60;
284
+ const minutes = duration % 60;
285
+ const hours = (duration - minutes) / 60;
286
+ return `${hours}h ${minutes}m ${seconds}s ${milliseconds}ms`;
343
287
  }
344
-
345
288
  /**
346
289
  * Retrieves the current date and time in a formatted string.
347
290
  * @returns {string} - The formatted date and time string (e.g., "(01/01/2023 12:00:00)").
348
291
  */
349
292
  function getCurrentDateTimeFormatted() {
350
- const currentDate = new Date();
351
- const day = currentDate.getDate().toString().padStart(2, '0');
352
- const month = (currentDate.getMonth() + 1).toString().padStart(2, '0');
353
- const year = currentDate.getFullYear();
354
- const hours = currentDate.getHours().toString().padStart(2, '0');
355
- const minutes = currentDate.getMinutes().toString().padStart(2, '0');
356
- const seconds = currentDate.getSeconds().toString().padStart(2, '0');
357
-
358
- return `(${day}/${month}/${year} ${hours}:${minutes}:${seconds})`;
293
+ const currentDate = new Date();
294
+ const day = currentDate.getDate().toString().padStart(2, '0');
295
+ const month = (currentDate.getMonth() + 1).toString().padStart(2, '0');
296
+ const year = currentDate.getFullYear();
297
+ const hours = currentDate.getHours().toString().padStart(2, '0');
298
+ const minutes = currentDate.getMinutes().toString().padStart(2, '0');
299
+ const seconds = currentDate.getSeconds().toString().padStart(2, '0');
300
+ return `(${day}/${month}/${year} ${hours}:${minutes}:${seconds})`;
359
301
  }
360
-
361
302
  module.exports = HtmlPipe;