@testomatio/reporter 2.9.0 → 2.9.1-beta.2-allure-tms-link
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/README.md +4 -2
- package/lib/allureReader.d.ts +93 -0
- package/lib/allureReader.js +547 -0
- package/lib/bin/cli.js +28 -0
- package/lib/junit-adapter/index.js +4 -0
- package/lib/junit-adapter/kotlin.d.ts +5 -0
- package/lib/junit-adapter/kotlin.js +46 -0
- package/lib/utils/pipe_utils.d.ts +17 -0
- package/lib/utils/pipe_utils.js +45 -0
- package/lib/utils/utils.js +9 -0
- package/lib/xmlReader.d.ts +0 -1
- package/lib/xmlReader.js +2 -38
- package/package.json +1 -1
- package/src/allureReader.js +635 -0
- package/src/bin/cli.js +35 -0
- package/src/junit-adapter/index.js +4 -0
- package/src/junit-adapter/kotlin.js +48 -0
- package/src/utils/pipe_utils.js +49 -0
- package/src/utils/utils.js +5 -0
- package/src/xmlReader.js +2 -47
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");
|
|
@@ -318,6 +319,33 @@ program
|
|
|
318
319
|
if (timeoutTimer)
|
|
319
320
|
clearTimeout(timeoutTimer);
|
|
320
321
|
});
|
|
322
|
+
program
|
|
323
|
+
.command('allure')
|
|
324
|
+
.description('Parse Allure result files and upload to Testomat.io')
|
|
325
|
+
.argument('<pattern>', 'Allure result directory pattern')
|
|
326
|
+
.option('-d, --dir <dir>', 'Project directory')
|
|
327
|
+
.option('--timelimit <time>', 'default time limit in seconds to kill a stuck process')
|
|
328
|
+
.option('--with-package', 'Keep full package path in file names (default: strip package prefix)')
|
|
329
|
+
.action(async (pattern, opts) => {
|
|
330
|
+
const runReader = new allureReader_js_1.default({ withPackage: opts.withPackage });
|
|
331
|
+
let timeoutTimer;
|
|
332
|
+
if (opts.timelimit) {
|
|
333
|
+
timeoutTimer = setTimeout(() => {
|
|
334
|
+
console.log(`⚠️ Reached timeout of ${opts.timelimit}s. Exiting... (Exit code is 0 to not fail the pipeline)`);
|
|
335
|
+
process.exit(0);
|
|
336
|
+
}, parseInt(opts.timelimit, 10) * 1000);
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
await runReader.parse(pattern);
|
|
340
|
+
await runReader.createRun();
|
|
341
|
+
await runReader.uploadData();
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
console.log(constants_js_1.APP_PREFIX, 'Error uploading Allure results:', err);
|
|
345
|
+
}
|
|
346
|
+
if (timeoutTimer)
|
|
347
|
+
clearTimeout(timeoutTimer);
|
|
348
|
+
});
|
|
321
349
|
program
|
|
322
350
|
.command('upload-artifacts')
|
|
323
351
|
.description('Upload artifacts to Testomat.io')
|
|
@@ -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,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;
|
|
@@ -64,3 +64,20 @@ export function parsePipeOptions(optionsStr?: string): any;
|
|
|
64
64
|
* @returns {string} Empty string if no ids; otherwise the formatted output.
|
|
65
65
|
*/
|
|
66
66
|
export function formatFilterListIds(ids: string[], format: "grep" | "json" | "newline" | "ids"): string;
|
|
67
|
+
/**
|
|
68
|
+
* Calculate the approximate size of data in bytes (JSON stringified, UTF-8 encoded length).
|
|
69
|
+
* @param {Object} data - Data to measure
|
|
70
|
+
* @returns {number} Size in bytes
|
|
71
|
+
*/
|
|
72
|
+
export function getObjectSize(data: any): number;
|
|
73
|
+
/**
|
|
74
|
+
* Split a tests array into chunks bounded by serialized size.
|
|
75
|
+
* Used by the XML and Allure readers so both upload tests with identical batching:
|
|
76
|
+
* each chunk becomes a single batch request (manual batch mode), which keeps requests
|
|
77
|
+
* under the size limit and guarantees every test is sent exactly once.
|
|
78
|
+
*
|
|
79
|
+
* @param {Array} tests - Array of tests to split
|
|
80
|
+
* @param {number} [maxSizeBytes=1048576] - Maximum serialized size per chunk (default 1MB)
|
|
81
|
+
* @returns {Array<Array>} Array of test chunks
|
|
82
|
+
*/
|
|
83
|
+
export function splitTestsIntoChunks(tests: any[], maxSizeBytes?: number): Array<any[]>;
|
package/lib/utils/pipe_utils.js
CHANGED
|
@@ -8,6 +8,8 @@ exports.statusEmoji = statusEmoji;
|
|
|
8
8
|
exports.fullName = fullName;
|
|
9
9
|
exports.parsePipeOptions = parsePipeOptions;
|
|
10
10
|
exports.formatFilterListIds = formatFilterListIds;
|
|
11
|
+
exports.getObjectSize = getObjectSize;
|
|
12
|
+
exports.splitTestsIntoChunks = splitTestsIntoChunks;
|
|
11
13
|
const log_js_1 = require("./log.js");
|
|
12
14
|
/**
|
|
13
15
|
* Set S3 credentials from the provided artifacts object.
|
|
@@ -162,6 +164,45 @@ function parsePipeOptions(optionsStr) {
|
|
|
162
164
|
}
|
|
163
165
|
return options;
|
|
164
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Calculate the approximate size of data in bytes (JSON stringified, UTF-8 encoded length).
|
|
169
|
+
* @param {Object} data - Data to measure
|
|
170
|
+
* @returns {number} Size in bytes
|
|
171
|
+
*/
|
|
172
|
+
function getObjectSize(data) {
|
|
173
|
+
const body = JSON.stringify(data);
|
|
174
|
+
return new TextEncoder().encode(body).length;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Split a tests array into chunks bounded by serialized size.
|
|
178
|
+
* Used by the XML and Allure readers so both upload tests with identical batching:
|
|
179
|
+
* each chunk becomes a single batch request (manual batch mode), which keeps requests
|
|
180
|
+
* under the size limit and guarantees every test is sent exactly once.
|
|
181
|
+
*
|
|
182
|
+
* @param {Array} tests - Array of tests to split
|
|
183
|
+
* @param {number} [maxSizeBytes=1048576] - Maximum serialized size per chunk (default 1MB)
|
|
184
|
+
* @returns {Array<Array>} Array of test chunks
|
|
185
|
+
*/
|
|
186
|
+
function splitTestsIntoChunks(tests, maxSizeBytes = 1 * 1024 * 1024) {
|
|
187
|
+
const chunks = [];
|
|
188
|
+
let currentChunk = [];
|
|
189
|
+
let currentChunkSize = 0;
|
|
190
|
+
for (const test of tests) {
|
|
191
|
+
const testSize = getObjectSize(test);
|
|
192
|
+
const wouldExceedSize = currentChunkSize + testSize > maxSizeBytes;
|
|
193
|
+
if (wouldExceedSize && currentChunk.length > 0) {
|
|
194
|
+
chunks.push(currentChunk);
|
|
195
|
+
currentChunk = [];
|
|
196
|
+
currentChunkSize = 0;
|
|
197
|
+
}
|
|
198
|
+
currentChunk.push(test);
|
|
199
|
+
currentChunkSize += testSize;
|
|
200
|
+
}
|
|
201
|
+
if (currentChunk.length > 0) {
|
|
202
|
+
chunks.push(currentChunk);
|
|
203
|
+
}
|
|
204
|
+
return chunks;
|
|
205
|
+
}
|
|
165
206
|
/**
|
|
166
207
|
* Format a list of test IDs for `--filter-list` machine-readable output.
|
|
167
208
|
* Used when the CLI `--format` option is passed,
|
|
@@ -198,3 +239,7 @@ module.exports.fullName = fullName;
|
|
|
198
239
|
module.exports.parsePipeOptions = parsePipeOptions;
|
|
199
240
|
|
|
200
241
|
module.exports.formatFilterListIds = formatFilterListIds;
|
|
242
|
+
|
|
243
|
+
module.exports.getObjectSize = getObjectSize;
|
|
244
|
+
|
|
245
|
+
module.exports.splitTestsIntoChunks = splitTestsIntoChunks;
|
package/lib/utils/utils.js
CHANGED
|
@@ -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/lib/xmlReader.d.ts
CHANGED
package/lib/xmlReader.js
CHANGED
|
@@ -14,6 +14,7 @@ const url_1 = require("url");
|
|
|
14
14
|
const nunit_parser_js_1 = require("./junit-adapter/nunit-parser.js");
|
|
15
15
|
const utils_js_1 = require("./utils/utils.js");
|
|
16
16
|
const index_js_1 = require("./pipe/index.js");
|
|
17
|
+
const pipe_utils_js_1 = require("./utils/pipe_utils.js");
|
|
17
18
|
const index_js_2 = __importDefault(require("./junit-adapter/index.js"));
|
|
18
19
|
const config_js_1 = require("./config.js");
|
|
19
20
|
const uploader_js_1 = require("./uploader.js");
|
|
@@ -474,43 +475,6 @@ class XmlReader {
|
|
|
474
475
|
this.uploader.checkEnabled();
|
|
475
476
|
return run;
|
|
476
477
|
}
|
|
477
|
-
/**
|
|
478
|
-
* Calculate the approximate size of data in bytes (JSON stringified length)
|
|
479
|
-
* @param {Object} data - Data to measure
|
|
480
|
-
* @returns {number} Size in bytes
|
|
481
|
-
*/
|
|
482
|
-
#getObjectSize(data) {
|
|
483
|
-
const body = JSON.stringify(data);
|
|
484
|
-
return new TextEncoder().encode(body).length;
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Split tests array into chunks based on data size
|
|
488
|
-
* @param {Array} tests - Array of tests to split
|
|
489
|
-
* @returns {Array<Array>} Array of test chunks
|
|
490
|
-
*/
|
|
491
|
-
#splitTestsIntoChunks(tests) {
|
|
492
|
-
const maxSizeBytes = 1 * 1024 * 1024;
|
|
493
|
-
const chunks = [];
|
|
494
|
-
let currentChunk = [];
|
|
495
|
-
let currentChunkSize = 0;
|
|
496
|
-
for (const test of tests) {
|
|
497
|
-
const testSize = this.#getObjectSize(test);
|
|
498
|
-
const wouldExceedSize = currentChunkSize + testSize > maxSizeBytes;
|
|
499
|
-
if (wouldExceedSize) {
|
|
500
|
-
if (currentChunk.length > 0) {
|
|
501
|
-
chunks.push(currentChunk);
|
|
502
|
-
}
|
|
503
|
-
currentChunk = [];
|
|
504
|
-
currentChunkSize = 0;
|
|
505
|
-
}
|
|
506
|
-
currentChunk.push(test);
|
|
507
|
-
currentChunkSize += testSize;
|
|
508
|
-
}
|
|
509
|
-
if (currentChunk.length > 0) {
|
|
510
|
-
chunks.push(currentChunk);
|
|
511
|
-
}
|
|
512
|
-
return chunks;
|
|
513
|
-
}
|
|
514
478
|
async uploadData() {
|
|
515
479
|
await this.uploadArtifacts();
|
|
516
480
|
this.calculateStats();
|
|
@@ -531,7 +495,7 @@ class XmlReader {
|
|
|
531
495
|
};
|
|
532
496
|
return Promise.all(this.pipes.map(p => p.finishRun(finishData)));
|
|
533
497
|
}
|
|
534
|
-
const testChunks =
|
|
498
|
+
const testChunks = (0, pipe_utils_js_1.splitTestsIntoChunks)(this.tests);
|
|
535
499
|
const totalChunks = testChunks.length;
|
|
536
500
|
const totalTests = this.tests.length;
|
|
537
501
|
debug(`Split ${totalTests} tests into ${totalChunks} chunks (max 1MB per chunk)`);
|