@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
@@ -0,0 +1,551 @@
1
+ import createDebugMessages from 'debug';
2
+ import path from 'path';
3
+ import pc from 'picocolors';
4
+ import fs from 'fs';
5
+ import { XMLParser } from 'fast-xml-parser';
6
+ import { APP_PREFIX, STATUS } from './constants.js';
7
+ import { randomUUID } from 'crypto';
8
+ import { fileURLToPath } from 'url';
9
+ import {
10
+ fetchFilesFromStackTrace,
11
+ fetchIdFromOutput,
12
+ fetchSourceCode,
13
+ fetchSourceCodeFromStackTrace,
14
+ fetchIdFromCode,
15
+ humanize,
16
+ } from './utils/utils.js';
17
+ import {pipesFactory} from './pipe/index.js';
18
+ import adapterFactory from './junit-adapter/index.js';
19
+ import {config} from './config.js';
20
+ import { upload } from './fileUploader.js';
21
+
22
+ // @ts-ignore this line will be removed in compiled code, because __dirname is defined in commonjs
23
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
24
+ const debug = createDebugMessages('@testomatio/reporter:xml');
25
+
26
+ const ridRunId = randomUUID();
27
+
28
+ const TESTOMATIO_URL = process.env.TESTOMATIO_URL || 'https://app.testomat.io';
29
+ const { TESTOMATIO_RUNGROUP_TITLE, TESTOMATIO_TITLE, TESTOMATIO_ENV, TESTOMATIO_RUN } = process.env;
30
+
31
+ const options = {
32
+ ignoreDeclaration: true,
33
+ ignoreAttributes: false,
34
+ alwaysCreateTextNode: false,
35
+ attributeNamePrefix: '',
36
+ parseTagValue: true,
37
+ };
38
+
39
+ const reduceOptions = {};
40
+
41
+ class XmlReader {
42
+ constructor(opts = {}) {
43
+ this.requestParams = {
44
+ apiKey: opts.apiKey || config.TESTOMATIO,
45
+ url: opts.url || TESTOMATIO_URL,
46
+ title: TESTOMATIO_TITLE,
47
+ env: TESTOMATIO_ENV,
48
+ group_title: TESTOMATIO_RUNGROUP_TITLE,
49
+ // batch uploading is implemented for xml already
50
+ isBatchEnabled: false,
51
+ };
52
+ this.runId = opts.runId || TESTOMATIO_RUN;
53
+ this.adapter = adapterFactory(opts.lang?.toLowerCase(), opts);
54
+ if (!this.adapter) throw new Error('XML adapter for this format not found');
55
+
56
+ this.opts = opts || {};
57
+ this.store = {};
58
+ this.pipesPromise = pipesFactory(opts, this.store);
59
+
60
+ this.parser = new XMLParser(options);
61
+ this.tests = [];
62
+ this.stats = {};
63
+ this.stats.language = opts.lang?.toLowerCase();
64
+ this.filesToUpload = {};
65
+
66
+ // @ts-ignore
67
+ const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
68
+ this.version = JSON.parse(fs.readFileSync(packageJsonPath).toString()).version;
69
+ console.log(APP_PREFIX, `Testomatio Reporter v${this.version}`);
70
+ }
71
+
72
+ connectAdapter() {
73
+ if (this.opts.javaTests) {
74
+ this.adapter = adapterFactory('java', this.opts);
75
+ return this.adapter;
76
+ }
77
+ this.adapter = adapterFactory(this.stats.language, this.opts);
78
+ return this.adapter;
79
+ }
80
+
81
+ parse(fileName) {
82
+ let xmlData = fs.readFileSync(path.resolve(fileName)).toString();
83
+
84
+ // we remove too long stack traces
85
+ const cutRegexes = [
86
+ /(<output><!\[CDATA\[)([\s\S]*?)(\]\]><\/output>)/g,
87
+ /(<system-err><!\[CDATA\[)([\s\S]*?)(\]\]><\/system-err>)/g,
88
+ /(<system-out><!\[CDATA\[)([\s\S]*?)(\]\]><\/system-out>)/g,
89
+ ];
90
+
91
+ for (const regex of cutRegexes) {
92
+ xmlData = xmlData.replace(regex, (_, p1, p2, p3) => `${p1}${p2.substring(0, 5000)}${p3}`);
93
+ }
94
+
95
+ const jsonResult = this.parser.parse(xmlData);
96
+ let jsonSuite;
97
+
98
+ if (jsonResult.testsuites) {
99
+ jsonSuite = jsonResult.testsuites;
100
+ } else if (jsonResult.testsuite) {
101
+ jsonSuite = jsonResult;
102
+ } else if (jsonResult.TestRun) {
103
+ return this.processTRX(jsonResult);
104
+ } else if (jsonResult['test-run']) {
105
+ return this.processNUnit(jsonResult['test-run']);
106
+ } else if (jsonResult.assemblies) {
107
+ return this.processXUnit(jsonResult.assemblies);
108
+ } else {
109
+ console.log(jsonResult);
110
+ throw new Error("Format can't be parsed");
111
+ }
112
+
113
+ return this.processJUnit(jsonSuite);
114
+ }
115
+
116
+ processJUnit(jsonSuite) {
117
+ const { testsuite, name, tests, failures, errors } = jsonSuite;
118
+
119
+ reduceOptions.preferClassname = this.stats.language === 'python';
120
+ const resultTests = processTestSuite(testsuite);
121
+
122
+ const hasFailures = resultTests.filter(t => t.status === 'failed').length > 0;
123
+ const status = failures > 0 || errors > 0 || hasFailures ? 'failed' : 'passed';
124
+
125
+ this.tests = this.tests.concat(resultTests);
126
+
127
+ return {
128
+ status,
129
+ create_tests: true,
130
+ name,
131
+ tests_count: parseInt(tests, 10),
132
+ passed_count: parseInt(tests, 10) - parseInt(failures, 10),
133
+ failed_count: parseInt(failures, 10),
134
+ skipped_count: 0,
135
+ tests: resultTests,
136
+ };
137
+ }
138
+
139
+ processNUnit(jsonSuite) {
140
+ const { result, total, passed, failed, inconclusive, skipped } = jsonSuite;
141
+
142
+ reduceOptions.preferClassname = this.stats.language === 'python';
143
+ const resultTests = processTestSuite(jsonSuite['test-suite']);
144
+
145
+ this.tests = this.tests.concat(resultTests);
146
+
147
+ return {
148
+ status: result?.toLowerCase(),
149
+ create_tests: true,
150
+ tests_count: parseInt(total, 10),
151
+ passed_count: parseInt(passed, 10),
152
+ failed_count: parseInt(failed, 10),
153
+ skipped_count: parseInt(inconclusive + skipped, 10),
154
+ tests: resultTests,
155
+ };
156
+ }
157
+
158
+ processTRX(jsonSuite) {
159
+ let defs = jsonSuite?.TestRun?.TestDefinitions?.UnitTest;
160
+ if (!Array.isArray(defs)) defs = [defs].filter(d => !!d);
161
+
162
+ const tests =
163
+ defs.map(td => {
164
+ const title = td.name.replace(/\(.*?\)/, '').trim();
165
+ let example = td.name.match(/\((.*?)\)/);
166
+ if (example) example = { ...example[1].split(',') };
167
+ const suite = td.TestMethod.className.split(', ')[0].split('.');
168
+ const suite_title = suite.pop();
169
+ return {
170
+ title,
171
+ example,
172
+ file: suite.join('/'),
173
+ description: td.Description,
174
+ suite_title,
175
+ id: td.Execution.id,
176
+ };
177
+ }) || [];
178
+
179
+ let result = jsonSuite?.TestRun?.Results?.UnitTestResult;
180
+ if (!Array.isArray(result)) result = [result].filter(d => !!d);
181
+
182
+ const results = result.map(td => ({
183
+ id: td.executionId,
184
+ // seconds are used in junit reports, but ms are used by testomatio
185
+ run_time: parseFloat(td.duration) * 1000,
186
+ status: td.outcome,
187
+ stack: td.Output.StdOut,
188
+ files: td?.ResultFiles?.ResultFile?.map(rf => rf.path),
189
+ }));
190
+
191
+ results.forEach(r => {
192
+ const test = tests.find(t => t.id === r.id) || {};
193
+ r.suite_title = test.suite_title;
194
+ r.title = test.title?.trim();
195
+ if (test.code) r.code = test.code;
196
+ if (test.description) r.description = test.description;
197
+ if (test.example) r.example = test.example;
198
+ if (test.file) r.file = test.file;
199
+ r.create = true;
200
+ if (r.status === 'Passed') r.status = STATUS.PASSED;
201
+ if (r.status === 'Failed') r.status = STATUS.FAILED;
202
+ if (r.status === 'Skipped') r.status = STATUS.SKIPPED;
203
+ delete r.id;
204
+ });
205
+
206
+ debug(results);
207
+
208
+ const counters = jsonSuite?.TestRun?.ResultSummary?.Counters || {};
209
+
210
+ const failed_count = parseInt(counters.failed, 10) + parseInt(counters.error, 10);
211
+
212
+ let status = STATUS.PASSED.toString();
213
+ if (failed_count > 0) status = STATUS.FAILED;
214
+
215
+ this.tests = results.filter(t => !!t.title);
216
+
217
+ return {
218
+ status,
219
+ create_tests: true,
220
+ tests_count: parseInt(counters.total, 10),
221
+ passed_count: parseInt(counters.passed, 10),
222
+ skipped_count: parseInt(counters.notExecuted, 10),
223
+ failed_count,
224
+ tests: results,
225
+ };
226
+ }
227
+
228
+ processXUnit(assemblies) {
229
+ const tests = [];
230
+
231
+ assemblies = Array.isArray(assemblies.assembly) ? assemblies.assembly : [assemblies.assembly];
232
+
233
+ assemblies.forEach(assembly => {
234
+ const { collection } = assembly;
235
+
236
+ const suites = Array.isArray(collection) ? collection : [collection];
237
+
238
+ suites.forEach(suite => {
239
+ const { test } = suite;
240
+ if (!test) return;
241
+ const cases = Array.isArray(test) ? test : [test];
242
+ cases.forEach(testCase => {
243
+ const { type, time, result } = testCase;
244
+
245
+ let message = '';
246
+ let stack = '';
247
+
248
+ if (testCase.failure) {
249
+ message = testCase.failure.message;
250
+ stack = testCase.failure['stack-trace'];
251
+ }
252
+ if (testCase.reason) {
253
+ message = testCase.reason.message;
254
+ }
255
+
256
+ let status = STATUS.PASSED;
257
+ if (result === 'Pass') status = STATUS.PASSED;
258
+ if (result === 'Fail') status = STATUS.FAILED;
259
+ if (result === 'Skip') status = STATUS.SKIPPED;
260
+
261
+ const pathParts = type.split('.');
262
+ const suite_title = pathParts[pathParts.length - 1];
263
+ const file = pathParts.slice(0, -1).join('/');
264
+ const title = testCase.method || testCase.name.split('.').pop();
265
+ const run_time = parseFloat(time) * 1000;
266
+
267
+ tests.push({
268
+ create: true,
269
+ stack,
270
+ message,
271
+ file,
272
+ status,
273
+ title,
274
+ suite_title,
275
+ run_time,
276
+ });
277
+ });
278
+ });
279
+ });
280
+
281
+ const hasFailures = tests.filter(t => t.status === STATUS.FAILED).length > 0;
282
+ const status = hasFailures ? STATUS.FAILED : STATUS.PASSED;
283
+
284
+ this.tests = tests;
285
+
286
+ debug(tests);
287
+
288
+ return {
289
+ status,
290
+ create_tests: true,
291
+ name: 'xUnit',
292
+ tests_count: tests.length,
293
+ passed_count: tests.filter(t => t.status === STATUS.PASSED).length,
294
+ failed_count: tests.filter(t => t.status === STATUS.FAILED).length,
295
+ skipped_count: tests.filter(t => t.status === STATUS.SKIPPED).length,
296
+ tests,
297
+ };
298
+ }
299
+
300
+ calculateStats() {
301
+ this.stats = {
302
+ ...this.stats,
303
+ status: 'passed',
304
+ create_tests: true,
305
+ tests_count: 0,
306
+ passed_count: 0,
307
+ failed_count: 0,
308
+ skipped_count: 0,
309
+ };
310
+ this.tests.forEach(t => {
311
+ this.stats.tests_count++;
312
+ if (t.status === 'passed') this.stats.passed_count++;
313
+ if (t.status === 'failed') this.stats.failed_count++;
314
+ });
315
+ if (this.stats.failed_count) this.stats.status = 'failed';
316
+
317
+ return this.stats;
318
+ }
319
+
320
+ fetchSourceCode() {
321
+ this.tests.forEach(t => {
322
+ try {
323
+ const file = this.adapter.getFilePath(t);
324
+ if (!file) return;
325
+
326
+ if (!this.stats.language) {
327
+ if (file.endsWith('.php')) this.stats.language = 'php';
328
+ if (file.endsWith('.py')) this.stats.language = 'python';
329
+ if (file.endsWith('.java')) this.stats.language = 'java';
330
+ if (file.endsWith('.rb')) this.stats.language = 'ruby';
331
+ if (file.endsWith('.js')) this.stats.language = 'js';
332
+ if (file.endsWith('.ts')) this.stats.language = 'ts';
333
+ }
334
+
335
+ if (!fs.existsSync(file)) {
336
+ debug('Failed to open file with the source code', file);
337
+ return;
338
+ }
339
+ const contents = fs.readFileSync(file).toString();
340
+ t.code = fetchSourceCode(contents, { ...t, lang: this.stats.language });
341
+ if (t.code) debug('Fetched code for test %s', t.title);
342
+ t.test_id = fetchIdFromCode(t.code, { lang: this.stats.language });
343
+ if (t.test_id) debug('Fetched test id %s for test %s', t.test_id, t.title);
344
+ } catch (err) {
345
+ debug(err);
346
+ }
347
+ });
348
+ }
349
+
350
+ formatTests() {
351
+ this.tests.forEach(t => {
352
+ if (t.file) {
353
+ t.file = t.file.replace(process.cwd() + path.sep, '');
354
+ }
355
+
356
+ this.adapter.formatTest(t);
357
+
358
+ t.title = humanize(t.title);
359
+ });
360
+ }
361
+
362
+ formatErrors() {
363
+ this.tests
364
+ .filter(t => !!t.stack)
365
+ .forEach(t => {
366
+ t.stack = this.formatStack(t);
367
+ t.message = this.adapter.formatMessage(t);
368
+ });
369
+ }
370
+
371
+ formatStack(t) {
372
+ const stack = this.adapter.formatStack(t);
373
+
374
+ const sourcePart = fetchSourceCodeFromStackTrace(stack);
375
+
376
+ if (!sourcePart) return stack;
377
+
378
+ const separator = pc.bold(pc.red('################[ Failure ]################'));
379
+
380
+ return `${stack}\n\n${separator}\n${fetchSourceCodeFromStackTrace(stack)}`;
381
+ }
382
+
383
+ async uploadArtifacts() {
384
+ for (const test of this.tests.filter(t => !!t.stack)) {
385
+ let files = [];
386
+ if (test.files?.length) files = test.files.map(f => path.join(process.cwd(), f));
387
+ files = [...files, ...fetchFilesFromStackTrace(test.stack)];
388
+
389
+ if (!files.length) continue;
390
+
391
+ const runId = this.runId || this.store.runId || Date.now().toString();
392
+ test.artifacts = await Promise.all(files.map(f => upload.uploadFileByPath(f, runId)));
393
+ console.log(APP_PREFIX, `🗄️ Uploaded ${pc.bold(`${files.length} artifacts`)} for test ${test.title}`);
394
+ }
395
+ }
396
+
397
+ async createRun() {
398
+ const runParams = {
399
+ api_key: this.requestParams.apiKey,
400
+ title: this.requestParams.title,
401
+ env: this.requestParams.env,
402
+ group_title: this.requestParams.group_title,
403
+ isBatchEnabled: this.requestParams.isBatchEnabled,
404
+ };
405
+
406
+ debug('Run', runParams);
407
+ this.pipes = this.pipes || (await this.pipesPromise);
408
+
409
+ return Promise.all(this.pipes.map(p => p.createRun(runParams)));
410
+ }
411
+
412
+ async uploadData() {
413
+ await this.uploadArtifacts();
414
+ this.calculateStats();
415
+ this.connectAdapter();
416
+ this.fetchSourceCode();
417
+ this.formatErrors();
418
+ this.formatTests();
419
+
420
+ debug('Uploading data', {
421
+ ...this.stats,
422
+ tests: this.tests,
423
+ });
424
+
425
+ const dataString = {
426
+ ...this.stats,
427
+ api_key: this.requestParams.apiKey,
428
+ status: 'finished',
429
+ tests: this.tests,
430
+ };
431
+
432
+ this.pipes = this.pipes || (await this.pipesPromise);
433
+ return Promise.all(this.pipes.map(p => p.finishRun(dataString)));
434
+ }
435
+
436
+ async _finishRun() {
437
+ this.pipes = this.pipes || (await this.pipesPromise);
438
+ return Promise.all(this.pipes.map(p => p.finishRun({ status: 'finished' })));
439
+ }
440
+ }
441
+
442
+ export default XmlReader;
443
+
444
+ function reduceTestCases(prev, item) {
445
+ let testCases = item.testcase;
446
+ if (!testCases) testCases = item['test-case'];
447
+ if (!Array.isArray(testCases)) {
448
+ testCases = [testCases];
449
+ }
450
+
451
+ // suite inside test case
452
+ if (item['test-suite'] && item['test-suite']['test-case']) testCases.push(...item['test-suite']['test-case']);
453
+
454
+ const suiteOutput = item['system-out'] || item.output || item.log || '';
455
+ const suiteErr = item['system-err'] || item.output || item.log || '';
456
+ testCases
457
+ .filter(t => !!t)
458
+ .forEach(testCaseItem => {
459
+ const file = testCaseItem.file || item.filepath || '';
460
+
461
+ let stack = '';
462
+ let message = '';
463
+ if (testCaseItem.error) stack = testCaseItem.error;
464
+ if (testCaseItem.failure) stack = testCaseItem.failure;
465
+ if (testCaseItem?.failure?.['stack-trace']) stack = testCaseItem.failure['stack-trace'];
466
+ if (testCaseItem?.failure?.message) message = testCaseItem.failure.message;
467
+ if (testCaseItem?.error?.message) message = testCaseItem.error.message;
468
+
469
+ if (testCaseItem.failure && testCaseItem.failure['#text']) stack = testCaseItem.failure['#text'];
470
+ if (testCaseItem.error && testCaseItem.error['#text']) stack = testCaseItem.error['#text'];
471
+ if (!message) message = stack.trim().split('\n')[0];
472
+
473
+ const isParametrized = item.type === 'ParameterizedMethod';
474
+ const preferClassname = reduceOptions.preferClassname || isParametrized;
475
+
476
+ // SpecFlow config
477
+ let { title, tags } = fetchProperties(isParametrized ? item : testCaseItem);
478
+ let example = null;
479
+ const suiteTitle = preferClassname ? testCaseItem.classname : item.name || testCaseItem.classname;
480
+
481
+ title ||= testCaseItem.name || testCaseItem.methodname || testCaseItem.classname;
482
+ tags ||= [];
483
+
484
+ const exampleMatches = testCaseItem.name?.match(/\S\((.*?)\)/);
485
+ if (exampleMatches) {
486
+ example = { ...exampleMatches[1].split(',').map(v => v.trim().replace(/[^\w\s-]/g, '')) };
487
+ title = title.replace(/\(.*?\)/, '').trim();
488
+ }
489
+
490
+ // eslint-disable-next-line
491
+ stack = `${
492
+ testCaseItem['system-out'] || testCaseItem.output || testCaseItem.log || ''
493
+ }\n\n${stack}\n\n${suiteOutput}\n\n${suiteErr}`.trim();
494
+ const testId = fetchIdFromOutput(stack);
495
+
496
+ let status = STATUS.PASSED.toString();
497
+ if ('failure' in testCaseItem || 'error' in testCaseItem) status = STATUS.FAILED;
498
+ if ('skipped' in testCaseItem) status = STATUS.SKIPPED;
499
+
500
+ let rid = null;
501
+ if (testCaseItem.id) rid = `${ridRunId}-${testCaseItem.id}`;
502
+
503
+ prev.push({
504
+ rid,
505
+ file,
506
+ stack,
507
+ example,
508
+ tags,
509
+ create: true,
510
+ test_id: testId,
511
+ message,
512
+ line: testCaseItem.lineno,
513
+ // seconds are used in junit reports, but ms are used by testomatio
514
+ run_time: parseFloat(testCaseItem.time || testCaseItem.duration) * 1000,
515
+ status,
516
+ title,
517
+ suite_title: suiteTitle,
518
+ });
519
+ });
520
+ return prev;
521
+ }
522
+
523
+ function processTestSuite(testsuite) {
524
+ if (!testsuite) return [];
525
+ if (testsuite.testsuite) return processTestSuite(testsuite.testsuite);
526
+ if (testsuite['test-suite'] && !testsuite['test-case']) return processTestSuite(testsuite['test-suite']);
527
+
528
+ let suites = testsuite;
529
+ if (!Array.isArray(testsuite)) {
530
+ suites = [testsuite];
531
+ }
532
+
533
+ const subSuites = suites.filter(s => s['test-suite'] && !testsuite['test-case']);
534
+
535
+ return [...subSuites.map(s => processTestSuite(s['test-suite'])), ...suites.reduce(reduceTestCases, [])].flat();
536
+ }
537
+
538
+ function fetchProperties(item) {
539
+ const tags = [];
540
+ let title = '';
541
+
542
+ if (!item.properties) return {};
543
+
544
+ const prop = [item.properties?.property].flat().find(p => p.name === 'Description');
545
+ if (prop) title = prop.value;
546
+ [item.properties?.property]
547
+ .flat()
548
+ .filter(p => p.name === 'Category')
549
+ .forEach(p => tags.push(p.value));
550
+ return { title, tags };
551
+ }