@testomatio/reporter 2.7.3-beta.1-vitest → 2.7.3-beta.3.allure

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.
@@ -0,0 +1,456 @@
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 path_1 = __importDefault(require("path"));
8
+ const picocolors_1 = __importDefault(require("picocolors"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const glob_1 = require("glob");
11
+ const constants_js_1 = require("./constants.js");
12
+ const crypto_1 = require("crypto");
13
+ const url_1 = require("url");
14
+ const config_js_1 = require("./config.js");
15
+ const uploader_js_1 = require("./uploader.js");
16
+ const index_js_1 = require("./pipe/index.js");
17
+ const utils_js_1 = require("./utils/utils.js");
18
+ const index_js_2 = __importDefault(require("./junit-adapter/index.js"));
19
+ // @ts-ignore
20
+ const debug = (0, debug_1.default)('@testomatio/reporter:allure');
21
+ const TESTOMATIO_URL = process.env.TESTOMATIO_URL || 'https://app.testomat.io';
22
+ const { TESTOMATIO_RUNGROUP_TITLE, TESTOMATIO_SUITE, TESTOMATIO_TITLE, TESTOMATIO_ENV, TESTOMATIO_RUN } = process.env;
23
+ class AllureReader {
24
+ constructor(opts = {}) {
25
+ this.requestParams = {
26
+ apiKey: opts.apiKey || config_js_1.config.TESTOMATIO,
27
+ url: opts.url || TESTOMATIO_URL,
28
+ title: TESTOMATIO_TITLE,
29
+ env: TESTOMATIO_ENV,
30
+ group_title: TESTOMATIO_RUNGROUP_TITLE,
31
+ isBatchEnabled: true,
32
+ };
33
+ this.runId = opts.runId || TESTOMATIO_RUN;
34
+ this.opts = opts || {};
35
+ this.withPackage = opts.withPackage || false;
36
+ this.store = {};
37
+ this.pipesPromise = (0, index_js_1.pipesFactory)(opts, this.store);
38
+ this._tests = [];
39
+ this.stats = {};
40
+ this.suites = {};
41
+ this.uploader = new uploader_js_1.S3Uploader();
42
+ // Allure results already contain steps and stack traces for all tests,
43
+ // so enable passing them for passed tests by default
44
+ if (!process.env.TESTOMATIO_STACK_PASSED) {
45
+ process.env.TESTOMATIO_STACK_PASSED = '1';
46
+ }
47
+ if (!process.env.TESTOMATIO_STEPS_PASSED) {
48
+ process.env.TESTOMATIO_STEPS_PASSED = '1';
49
+ }
50
+ const packageJsonPath = path_1.default.resolve(__dirname, '..', 'package.json');
51
+ this.version = JSON.parse(fs_1.default.readFileSync(packageJsonPath).toString()).version;
52
+ console.log(constants_js_1.APP_PREFIX, `Testomatio Reporter v${this.version}`);
53
+ }
54
+ get tests() {
55
+ return this._tests;
56
+ }
57
+ set tests(value) {
58
+ this._tests = value;
59
+ }
60
+ async createRun() {
61
+ const runParams = {
62
+ api_key: this.requestParams.apiKey,
63
+ title: this.requestParams.title,
64
+ env: this.requestParams.env,
65
+ group_title: this.requestParams.group_title,
66
+ isBatchEnabled: this.requestParams.isBatchEnabled,
67
+ };
68
+ debug('Run', runParams);
69
+ this.pipes = this.pipes || (await this.pipesPromise);
70
+ const run = await Promise.all(this.pipes.map(p => p.createRun(runParams)));
71
+ this.uploader.checkEnabled();
72
+ return run;
73
+ }
74
+ parse(resultsPattern) {
75
+ this._tests = [];
76
+ let pattern = resultsPattern;
77
+ // Auto-append wildcard if pattern refers to a directory (like XML command does)
78
+ if (!pattern.endsWith('.json') && !pattern.includes('*')) {
79
+ if (pattern.endsWith('/') || (fs_1.default.existsSync(pattern) && fs_1.default.statSync(pattern).isDirectory())) {
80
+ pattern = pattern.replace(/\/+$/, '') + '/*-result.json';
81
+ }
82
+ else {
83
+ pattern += '*-result.json';
84
+ }
85
+ }
86
+ const resultsDir = path_1.default.dirname(pattern);
87
+ console.log(constants_js_1.APP_PREFIX, `Scanning for Allure results in: ${resultsDir}`);
88
+ console.log(constants_js_1.APP_PREFIX, `Using pattern: ${pattern}`);
89
+ const resultFiles = glob_1.glob.sync(pattern);
90
+ const containerFiles = glob_1.glob.sync(pattern.replace('*-result.json', '*-container.json'));
91
+ if (resultFiles.length === 0 && containerFiles.length === 0) {
92
+ throw new Error(`No Allure result files found matching pattern: ${pattern}`);
93
+ }
94
+ console.log(constants_js_1.APP_PREFIX, `Found ${resultFiles.length} result files and ${containerFiles.length} container files`);
95
+ this.parseContainerFiles(containerFiles);
96
+ // Store all tests temporarily for deduplication by historyId
97
+ const allTests = [];
98
+ for (const file of resultFiles) {
99
+ const fullPath = file;
100
+ const fileDir = path_1.default.dirname(file);
101
+ try {
102
+ const resultData = JSON.parse(fs_1.default.readFileSync(fullPath, 'utf8'));
103
+ const test = this.processAllureResult(resultData, fileDir);
104
+ if (test) {
105
+ test._historyId = resultData.historyId;
106
+ test._stop = resultData.stop || 0;
107
+ allTests.push(test);
108
+ }
109
+ }
110
+ catch (err) {
111
+ console.warn(constants_js_1.APP_PREFIX, `Failed to parse ${file}:`, err.message);
112
+ debug('Parse error:', err);
113
+ }
114
+ }
115
+ const attemptsMap = new Map();
116
+ for (const test of allTests) {
117
+ const historyId = test._historyId || test.rid;
118
+ if (!attemptsMap.has(historyId)) {
119
+ attemptsMap.set(historyId, []);
120
+ }
121
+ attemptsMap.get(historyId).push(test);
122
+ }
123
+ const uniqueTestsMap = new Map();
124
+ for (const [historyId, attempts] of attemptsMap) {
125
+ uniqueTestsMap.set(historyId, this.combineRetryAttempts(attempts));
126
+ }
127
+ // Convert map to array and clean up internal fields
128
+ this._tests = Array.from(uniqueTestsMap.values()).map(t => {
129
+ delete t._historyId;
130
+ delete t._stop;
131
+ return t;
132
+ });
133
+ console.log(constants_js_1.APP_PREFIX, `Processed ${this._tests.length} unique tests (from ${allTests.length} result files)`);
134
+ return this.calculateStats();
135
+ }
136
+ parseContainerFiles(containerFiles) {
137
+ for (const file of containerFiles) {
138
+ try {
139
+ const data = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
140
+ if (data.name && data.children) {
141
+ data.children.forEach(uuid => {
142
+ this.suites[uuid] = data.name;
143
+ });
144
+ }
145
+ }
146
+ catch (err) {
147
+ debug('Failed to parse container file:', file, err.message);
148
+ }
149
+ }
150
+ debug('Parsed suites:', this.suites);
151
+ }
152
+ processAllureResult(result, resultsDir) {
153
+ const test = {
154
+ rid: result.uuid || (0, crypto_1.randomUUID)(),
155
+ title: result.name || 'Unknown test',
156
+ status: this.mapStatus(result.status),
157
+ suite_title: this.extractSuiteTitle(result),
158
+ file: this.extractFile(result),
159
+ run_time: this.calculateRunTime(result),
160
+ steps: this.convertSteps(result.steps || []),
161
+ message: result.statusDetails?.message || '',
162
+ stack: result.statusDetails?.trace || '',
163
+ meta: this.extractMeta(result),
164
+ links: this.extractLinks(result),
165
+ artifacts: [],
166
+ create: true,
167
+ overwrite: true,
168
+ };
169
+ // Add description if present
170
+ if (result.description) {
171
+ test.description = result.description;
172
+ }
173
+ if (result.parameters && result.parameters.length > 0) {
174
+ test.example = this.convertParameters(result.parameters);
175
+ }
176
+ if (result.attachments && result.attachments.length > 0) {
177
+ const attachments = result.attachments
178
+ .map(att => {
179
+ const fullPath = path_1.default.join(resultsDir, att.source);
180
+ if (fs_1.default.existsSync(fullPath)) {
181
+ return fullPath;
182
+ }
183
+ debug('Attachment file not found:', fullPath);
184
+ return null;
185
+ })
186
+ .filter(Boolean);
187
+ if (attachments.length > 0) {
188
+ test.files = attachments;
189
+ }
190
+ }
191
+ return test;
192
+ }
193
+ mapStatus(status) {
194
+ const statusMap = {
195
+ passed: 'passed',
196
+ failed: 'failed',
197
+ broken: 'failed',
198
+ skipped: 'skipped',
199
+ pending: 'skipped',
200
+ };
201
+ return statusMap[status] || 'failed';
202
+ }
203
+ extractSuiteTitle(result) {
204
+ const labels = result.labels || [];
205
+ // Only use suite label for suite_title
206
+ // Epic and Feature are sent as separate labels in meta
207
+ const suiteLabel = labels.find(l => l.name === 'suite')?.value;
208
+ if (suiteLabel) {
209
+ return this.stripNamespace(suiteLabel);
210
+ }
211
+ // Fallback to parentSuite or subSuite if no suite label
212
+ const parentSuite = labels.find(l => l.name === 'parentSuite')?.value;
213
+ const subSuite = labels.find(l => l.name === 'subSuite')?.value;
214
+ if (parentSuite && subSuite) {
215
+ return `${parentSuite} / ${subSuite}`;
216
+ }
217
+ if (parentSuite)
218
+ return parentSuite;
219
+ if (subSuite)
220
+ return subSuite;
221
+ return 'Default Suite';
222
+ }
223
+ stripNamespace(suiteName) {
224
+ if (suiteName && suiteName.includes('.')) {
225
+ return suiteName.split('.').pop();
226
+ }
227
+ return suiteName;
228
+ }
229
+ extractFile(result) {
230
+ const labels = result.labels || [];
231
+ const packageLabel = labels.find(l => l.name === 'package')?.value;
232
+ const testClassLabel = labels.find(l => l.name === 'testClass')?.value;
233
+ if (!packageLabel) {
234
+ return null;
235
+ }
236
+ const ext = this.getFileExtension(result);
237
+ let className;
238
+ if (testClassLabel) {
239
+ className = testClassLabel.split('.').pop();
240
+ }
241
+ else if (result.fullName) {
242
+ const fullNameParts = result.fullName.split('.');
243
+ className = fullNameParts[fullNameParts.length - 2] || fullNameParts[fullNameParts.length - 1];
244
+ }
245
+ else {
246
+ return null;
247
+ }
248
+ if (this.withPackage) {
249
+ const parts = packageLabel.split('.');
250
+ return `${parts.join('/')}/${className}.${ext}`;
251
+ }
252
+ return `${className}.${ext}`;
253
+ }
254
+ getFileExtension(result) {
255
+ const labels = result.labels || [];
256
+ const languageLabel = labels.find(l => l.name === 'language')?.value;
257
+ const extMap = {
258
+ java: 'java',
259
+ kotlin: 'kt',
260
+ javascript: 'js',
261
+ typescript: 'ts',
262
+ python: 'py',
263
+ ruby: 'rb',
264
+ 'c#': 'cs',
265
+ php: 'php',
266
+ };
267
+ return extMap[languageLabel?.toLowerCase()] || 'java';
268
+ }
269
+ extractMeta(result) {
270
+ const labels = result.labels || [];
271
+ const excludedLabels = [
272
+ 'suite', 'package', 'parentSuite', 'subSuite',
273
+ 'testClass', 'testMethod', 'epic', 'feature',
274
+ ];
275
+ const meta = {};
276
+ labels.forEach(label => {
277
+ if (!excludedLabels.includes(label.name)) {
278
+ meta[label.name] = label.value;
279
+ }
280
+ });
281
+ return meta;
282
+ }
283
+ extractLinks(result) {
284
+ const labels = result.labels || [];
285
+ const links = [];
286
+ const epicLabel = labels.find(l => l.name === 'epic');
287
+ const featureLabel = labels.find(l => l.name === 'feature');
288
+ if (epicLabel?.value) {
289
+ links.push({ label: `epic:${epicLabel.value}` });
290
+ }
291
+ if (featureLabel?.value) {
292
+ links.push({ label: `feature:${featureLabel.value}` });
293
+ }
294
+ return links.length > 0 ? links : undefined;
295
+ }
296
+ convertSteps(steps, depth = 0) {
297
+ if (depth >= 10)
298
+ return null;
299
+ return steps
300
+ .map(step => {
301
+ const convertedStep = {
302
+ category: 'user',
303
+ title: step.name || step.title || 'Unknown step',
304
+ duration: this.calculateRunTime(step),
305
+ steps: this.convertSteps(step.steps || [], depth + 1),
306
+ };
307
+ if (convertedStep.steps && convertedStep.steps.length === 0) {
308
+ delete convertedStep.steps;
309
+ }
310
+ if (convertedStep.duration === 0) {
311
+ delete convertedStep.duration;
312
+ }
313
+ return convertedStep;
314
+ })
315
+ .filter(Boolean);
316
+ }
317
+ calculateRunTime(item) {
318
+ if (item.start && item.stop) {
319
+ const durationMs = item.stop - item.start;
320
+ return durationMs / 1000;
321
+ }
322
+ return null;
323
+ }
324
+ convertParameters(parameters) {
325
+ const example = {};
326
+ parameters.forEach(param => {
327
+ if (param.name) {
328
+ example[param.name] = param.value;
329
+ }
330
+ });
331
+ return example;
332
+ }
333
+ combineRetryAttempts(attempts) {
334
+ attempts.sort((a, b) => (a._stop || 0) - (b._stop || 0));
335
+ const finalTest = attempts[attempts.length - 1];
336
+ const retryCount = attempts.length - 1;
337
+ if (retryCount > 0) {
338
+ finalTest.retries = retryCount;
339
+ }
340
+ const failedAttempts = attempts.filter(t => t.status === 'failed');
341
+ if (failedAttempts.length === 0) {
342
+ return finalTest;
343
+ }
344
+ const failureMessages = [];
345
+ const failureStacks = [];
346
+ for (const failed of failedAttempts) {
347
+ const attemptNum = attempts.indexOf(failed) + 1;
348
+ if (failed.message) {
349
+ failureMessages.push(`[Attempt ${attemptNum}] ${failed.message}`);
350
+ }
351
+ if (failed.stack) {
352
+ failureStacks.push(`\n--- Attempt ${attemptNum} ---\n${failed.stack}`);
353
+ }
354
+ }
355
+ if (failureMessages.length > 0) {
356
+ finalTest.message = failureMessages.join('\n');
357
+ }
358
+ if (failureStacks.length > 0) {
359
+ finalTest.stack = failureStacks.join('\n');
360
+ }
361
+ if (finalTest.status === 'passed') {
362
+ finalTest.status = 'failed';
363
+ const retryMsg = `Test passed after ${failedAttempts.length} retries. Previous failures:\n`;
364
+ finalTest.message = retryMsg + finalTest.message;
365
+ }
366
+ return finalTest;
367
+ }
368
+ calculateStats() {
369
+ this.stats = {
370
+ create_tests: true,
371
+ tests_count: this._tests.length,
372
+ passed_count: 0,
373
+ failed_count: 0,
374
+ skipped_count: 0,
375
+ duration: 0,
376
+ status: 'passed',
377
+ tests: this._tests,
378
+ };
379
+ this._tests.forEach(t => {
380
+ if (t.status === 'passed')
381
+ this.stats.passed_count++;
382
+ if (t.status === 'failed')
383
+ this.stats.failed_count++;
384
+ if (t.status === 'skipped')
385
+ this.stats.skipped_count++;
386
+ });
387
+ this.stats.duration = this._tests.reduce((acc, t) => acc + (t.run_time || 0), 0);
388
+ if (this.stats.failed_count)
389
+ this.stats.status = 'failed';
390
+ debug('Stats:', this.stats);
391
+ return this.stats;
392
+ }
393
+ fetchSourceCode() {
394
+ const adapter = this.adapter || (0, index_js_2.default)(this.getLanguage(), this.opts);
395
+ this._tests.forEach(t => {
396
+ try {
397
+ let filePath = t.file;
398
+ if (adapter && adapter.getFilePath) {
399
+ filePath = adapter.getFilePath(t);
400
+ }
401
+ if (!filePath)
402
+ return;
403
+ if (!fs_1.default.existsSync(filePath)) {
404
+ debug('Source file not found:', filePath);
405
+ return;
406
+ }
407
+ const contents = fs_1.default.readFileSync(filePath).toString();
408
+ const code = (0, utils_js_1.fetchSourceCode)(contents, { ...t, lang: this.getLanguage() });
409
+ if (code) {
410
+ t.code = code;
411
+ debug('Fetched code for test %s', t.title);
412
+ }
413
+ const testId = (0, utils_js_1.fetchIdFromCode)(contents, { lang: this.getLanguage() });
414
+ if (testId) {
415
+ t.test_id = testId;
416
+ debug('Fetched test id %s for test %s', testId, t.title);
417
+ }
418
+ }
419
+ catch (err) {
420
+ debug('Failed to fetch source code:', err.message);
421
+ }
422
+ });
423
+ }
424
+ getLanguage() {
425
+ if (this._tests.length === 0)
426
+ return null;
427
+ return this._tests[0].meta?.language || this.opts.lang;
428
+ }
429
+ async uploadArtifacts() {
430
+ for (const test of this._tests.filter(t => t.files && t.files.length > 0)) {
431
+ const runId = this.runId || this.store.runId || Date.now().toString();
432
+ const artifacts = await Promise.all(test.files.map(f => this.uploader.uploadFileByPath(f, [runId, test.rid, path_1.default.basename(f)])));
433
+ test.artifacts = artifacts.filter(a => a && a.link).map(a => a.link);
434
+ delete test.files;
435
+ if (test.artifacts.length > 0) {
436
+ console.log(constants_js_1.APP_PREFIX, `🗄️ Uploaded ${picocolors_1.default.bold(`${test.artifacts.length} artifacts`)} for test ${test.title}`);
437
+ }
438
+ }
439
+ }
440
+ async uploadData() {
441
+ await this.uploadArtifacts();
442
+ this.calculateStats();
443
+ this.fetchSourceCode();
444
+ const dataString = {
445
+ ...this.stats,
446
+ api_key: this.requestParams.apiKey,
447
+ status: 'finished',
448
+ duration: this.stats.duration,
449
+ tests: this._tests,
450
+ };
451
+ debug('Uploading data', dataString);
452
+ this.pipes = this.pipes || (await this.pipesPromise);
453
+ return Promise.all(this.pipes.map(p => p.finishRun(dataString)));
454
+ }
455
+ }
456
+ module.exports = AllureReader;
package/lib/bin/cli.js CHANGED
@@ -10,6 +10,7 @@ const glob_1 = require("glob");
10
10
  const debug_1 = __importDefault(require("debug"));
11
11
  const client_js_1 = __importDefault(require("../client.js"));
12
12
  const xmlReader_js_1 = __importDefault(require("../xmlReader.js"));
13
+ const allureReader_js_1 = __importDefault(require("../allureReader.js"));
13
14
  const constants_js_1 = require("../constants.js");
14
15
  const utils_js_1 = require("../utils/utils.js");
15
16
  const config_js_1 = require("../config.js");
@@ -237,6 +238,33 @@ program
237
238
  if (timeoutTimer)
238
239
  clearTimeout(timeoutTimer);
239
240
  });
241
+ program
242
+ .command('allure')
243
+ .description('Parse Allure result files and upload to Testomat.io')
244
+ .argument('<pattern>', 'Allure result directory pattern')
245
+ .option('-d, --dir <dir>', 'Project directory')
246
+ .option('--timelimit <time>', 'default time limit in seconds to kill a stuck process')
247
+ .option('--with-package', 'Keep full package path in file names (default: strip package prefix)')
248
+ .action(async (pattern, opts) => {
249
+ const runReader = new allureReader_js_1.default({ withPackage: opts.withPackage });
250
+ let timeoutTimer;
251
+ if (opts.timelimit) {
252
+ timeoutTimer = setTimeout(() => {
253
+ console.log(`⚠️ Reached timeout of ${opts.timelimit}s. Exiting... (Exit code is 0 to not fail the pipeline)`);
254
+ process.exit(0);
255
+ }, parseInt(opts.timelimit, 10) * 1000);
256
+ }
257
+ try {
258
+ await runReader.parse(pattern);
259
+ await runReader.createRun();
260
+ await runReader.uploadData();
261
+ }
262
+ catch (err) {
263
+ console.log(constants_js_1.APP_PREFIX, 'Error uploading Allure results:', err);
264
+ }
265
+ if (timeoutTimer)
266
+ clearTimeout(timeoutTimer);
267
+ });
240
268
  program
241
269
  .command('upload-artifacts')
242
270
  .description('Upload artifacts to Testomat.io')
package/lib/client.d.ts CHANGED
@@ -65,10 +65,9 @@ export class Client {
65
65
  *
66
66
  * Updates the status of the current test run and finishes the run.
67
67
  * @param {'passed' | 'failed' | 'skipped' | 'finished'} status - The status of the current test run.
68
- * @param {Partial<import('../types/types.js').RunData>} [params] - Additional run params (e.g. duration).
69
68
  * Must be one of "passed", "failed", or "finished"
70
69
  * @returns {Promise<any>} - A Promise that resolves when finishes the run.
71
70
  */
72
- updateRunStatus(status: "passed" | "failed" | "skipped" | "finished", params?: Partial<import("../types/types.js").RunData>): Promise<any>;
71
+ updateRunStatus(status: "passed" | "failed" | "skipped" | "finished"): Promise<any>;
73
72
  }
74
73
  import { S3Uploader } from './uploader.js';
package/lib/client.js CHANGED
@@ -223,7 +223,7 @@ class Client {
223
223
  errorFormatted += (0, log_formatter_js_1.formatError)(error) || '';
224
224
  message = error?.message;
225
225
  }
226
- let fullLogs = (0, log_formatter_js_1.formatLogs)({ error: errorFormatted, steps, logs: testData.logs });
226
+ let fullLogs = (0, log_formatter_js_1.formatLogs)({ error: errorFormatted, logs: testData.logs });
227
227
  if (stackArtifactsEnabled && fullLogs?.trim()?.length > 0) {
228
228
  uploadedFiles.push(this.uploader.uploadFileAsBuffer(Buffer.from((0, log_formatter_js_1.stripColors)(fullLogs), 'utf8'), [
229
229
  this.runId,
@@ -308,18 +308,17 @@ class Client {
308
308
  *
309
309
  * Updates the status of the current test run and finishes the run.
310
310
  * @param {'passed' | 'failed' | 'skipped' | 'finished'} status - The status of the current test run.
311
- * @param {Partial<import('../types/types.js').RunData>} [params] - Additional run params (e.g. duration).
312
311
  * Must be one of "passed", "failed", or "finished"
313
312
  * @returns {Promise<any>} - A Promise that resolves when finishes the run.
314
313
  */
315
- async updateRunStatus(status, params = {}) {
314
+ async updateRunStatus(status) {
316
315
  this.pipes ||= await (0, index_js_1.pipesFactory)(this.paramsForPipesFactory || {}, this.pipeStore);
317
316
  this.runId ||= (0, utils_js_1.readLatestRunId)();
318
317
  debug('Updating run status...');
319
318
  // all pipes disabled, skipping
320
319
  if (!this.pipes?.filter(p => p.isEnabled).length)
321
320
  return Promise.resolve();
322
- const runParams = { ...params, status };
321
+ const runParams = { status };
323
322
  this.queue = this.queue
324
323
  .then(() => Promise.all(this.pipes.map(p => p.finishRun(runParams))))
325
324
  .then(() => {
@@ -9,6 +9,7 @@ const java_js_1 = __importDefault(require("./java.js"));
9
9
  const python_js_1 = __importDefault(require("./python.js"));
10
10
  const ruby_js_1 = __importDefault(require("./ruby.js"));
11
11
  const csharp_js_1 = __importDefault(require("./csharp.js"));
12
+ const kotlin_js_1 = __importDefault(require("./kotlin.js"));
12
13
  function AdapterFactory(lang, opts) {
13
14
  if (lang === 'java') {
14
15
  return new java_js_1.default(opts);
@@ -25,6 +26,9 @@ function AdapterFactory(lang, opts) {
25
26
  if (lang === 'c#' || lang === 'csharp') {
26
27
  return new csharp_js_1.default(opts);
27
28
  }
29
+ if (lang === 'kotlin') {
30
+ return new kotlin_js_1.default(opts);
31
+ }
28
32
  return new adapter_js_1.default(opts);
29
33
  }
30
34
  module.exports = AdapterFactory;
@@ -0,0 +1,5 @@
1
+ export default KotlinAdapter;
2
+ declare class KotlinAdapter extends Adapter {
3
+ getFilePath(t: any): string;
4
+ }
5
+ import Adapter from './adapter.js';
@@ -0,0 +1,46 @@
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 path_1 = __importDefault(require("path"));
7
+ const adapter_js_1 = __importDefault(require("./adapter.js"));
8
+ class KotlinAdapter extends adapter_js_1.default {
9
+ getFilePath(t) {
10
+ const fileName = namespaceToFileName(t.suite_title);
11
+ return this.opts.javaTests + path_1.default.sep + fileName;
12
+ }
13
+ formatTest(t) {
14
+ const fileParts = t.suite_title.split('.');
15
+ t.file = namespaceToFileName(t.suite_title);
16
+ t.title = t.title.split('(')[0];
17
+ // detect params
18
+ const paramMatches = t.title.match(/\[(.*?)\]/g);
19
+ if (paramMatches) {
20
+ const params = paramMatches.map((_match, index) => `param${index + 1}`);
21
+ if (params.length === 1)
22
+ params[0] = 'param';
23
+ let paramIndex = 0;
24
+ t.title = t.title.replace(/: \[(.*?)\]/g, () => {
25
+ if (params.length < 2)
26
+ return `\${param}`;
27
+ const paramName = params[paramIndex] || `param${paramIndex + 1}`;
28
+ paramIndex++;
29
+ return `\${${paramName}}`;
30
+ });
31
+ const example = {};
32
+ paramMatches.forEach((match, index) => {
33
+ example[params[index]] = match.replace(/[[\]]/g, '');
34
+ });
35
+ t.example = example;
36
+ }
37
+ t.suite_title = fileParts[fileParts.length - 1].replace(/\$/g, ' | ');
38
+ return t;
39
+ }
40
+ }
41
+ function namespaceToFileName(fileName) {
42
+ const fileParts = fileName.split('.');
43
+ fileParts[fileParts.length - 1] = fileParts[fileParts.length - 1]?.replace(/\$.*/, '');
44
+ return `${fileParts.join(path_1.default.sep)}.kt`;
45
+ }
46
+ module.exports = KotlinAdapter;
@@ -2,13 +2,13 @@
2
2
  * Returns the formatted stack including the stack trace, steps, and logs.
3
3
  * @param {Object} params - Parameters for formatting logs
4
4
  * @param {string} params.error - Error message
5
- * @param {Array|any} params.steps - Test steps (array or other types)
5
+ * @param {Array|any} [params.steps] - Test steps (array or other types)
6
6
  * @param {string} params.logs - Test logs
7
7
  * @returns {string}
8
8
  */
9
9
  export function formatLogs({ error, steps, logs }: {
10
10
  error: string;
11
- steps: any[] | any;
11
+ steps?: any[] | any;
12
12
  logs: string;
13
13
  }): string;
14
14
  /**
@@ -18,7 +18,7 @@ exports.stripColors = stripColors;
18
18
  * Returns the formatted stack including the stack trace, steps, and logs.
19
19
  * @param {Object} params - Parameters for formatting logs
20
20
  * @param {string} params.error - Error message
21
- * @param {Array|any} params.steps - Test steps (array or other types)
21
+ * @param {Array|any} [params.steps] - Test steps (array or other types)
22
22
  * @param {string} params.logs - Test logs
23
23
  * @returns {string}
24
24
  */
@@ -324,6 +324,15 @@ const fetchSourceCode = (contents, opts = {}) => {
324
324
  if (lineIndex === -1)
325
325
  lineIndex = lines.findIndex(l => l.includes(`${title}(`));
326
326
  }
327
+ else if (opts.lang === 'kotlin') {
328
+ lineIndex = lines.findIndex(l => l.includes(`fun test${title}`));
329
+ if (lineIndex === -1)
330
+ lineIndex = lines.findIndex(l => l.includes(`@DisplayName("${title}`));
331
+ if (lineIndex === -1)
332
+ lineIndex = lines.findIndex(l => l.includes(`fun ${title}`));
333
+ if (lineIndex === -1)
334
+ lineIndex = lines.findIndex(l => l.includes(`${title}(`));
335
+ }
327
336
  else if (opts.lang === 'csharp') {
328
337
  // Find the method declaration line
329
338
  let methodLineIndex = lines.findIndex(l => l.includes(`public void ${title}(`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "2.7.3-beta.1-vitest",
3
+ "version": "2.7.3-beta.3.allure",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "engines": {
6
6
  "node": ">=18"