@testomatio/reporter 2.9.0 → 2.9.1-beta.1-allure-chunking

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.
@@ -161,6 +161,53 @@ function parsePipeOptions(optionsStr) {
161
161
  return options;
162
162
  }
163
163
 
164
+ /**
165
+ * Calculate the approximate size of data in bytes (JSON stringified, UTF-8 encoded length).
166
+ * @param {Object} data - Data to measure
167
+ * @returns {number} Size in bytes
168
+ */
169
+ function getObjectSize(data) {
170
+ const body = JSON.stringify(data);
171
+ return new TextEncoder().encode(body).length;
172
+ }
173
+
174
+ /**
175
+ * Split a tests array into chunks bounded by serialized size.
176
+ * Used by the XML and Allure readers so both upload tests with identical batching:
177
+ * each chunk becomes a single batch request (manual batch mode), which keeps requests
178
+ * under the size limit and guarantees every test is sent exactly once.
179
+ *
180
+ * @param {Array} tests - Array of tests to split
181
+ * @param {number} [maxSizeBytes=1048576] - Maximum serialized size per chunk (default 1MB)
182
+ * @returns {Array<Array>} Array of test chunks
183
+ */
184
+ function splitTestsIntoChunks(tests, maxSizeBytes = 1 * 1024 * 1024) {
185
+ const chunks = [];
186
+ let currentChunk = [];
187
+ let currentChunkSize = 0;
188
+
189
+ for (const test of tests) {
190
+ const testSize = getObjectSize(test);
191
+
192
+ const wouldExceedSize = currentChunkSize + testSize > maxSizeBytes;
193
+
194
+ if (wouldExceedSize && currentChunk.length > 0) {
195
+ chunks.push(currentChunk);
196
+ currentChunk = [];
197
+ currentChunkSize = 0;
198
+ }
199
+
200
+ currentChunk.push(test);
201
+ currentChunkSize += testSize;
202
+ }
203
+
204
+ if (currentChunk.length > 0) {
205
+ chunks.push(currentChunk);
206
+ }
207
+
208
+ return chunks;
209
+ }
210
+
164
211
  /**
165
212
  * Format a list of test IDs for `--filter-list` machine-readable output.
166
213
  * Used when the CLI `--format` option is passed,
@@ -190,4 +237,6 @@ export {
190
237
  fullName,
191
238
  parsePipeOptions,
192
239
  formatFilterListIds,
240
+ getObjectSize,
241
+ splitTestsIntoChunks,
193
242
  };
@@ -289,6 +289,11 @@ const fetchSourceCode = (contents, opts = {}) => {
289
289
  if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`@DisplayName("${title}`));
290
290
  if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`public void ${title}`));
291
291
  if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`${title}(`));
292
+ } else if (opts.lang === 'kotlin') {
293
+ lineIndex = lines.findIndex(l => l.includes(`fun test${title}`));
294
+ if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`@DisplayName("${title}`));
295
+ if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`fun ${title}`));
296
+ if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`${title}(`));
292
297
  } else if (opts.lang === 'csharp') {
293
298
  // Find the method declaration line
294
299
  let methodLineIndex = lines.findIndex(l => l.includes(`public void ${title}(`));
package/src/xmlReader.js CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  transformEnvVarToBoolean,
19
19
  } from './utils/utils.js';
20
20
  import { pipesFactory } from './pipe/index.js';
21
+ import { splitTestsIntoChunks } from './utils/pipe_utils.js';
21
22
  import adapterFactory from './junit-adapter/index.js';
22
23
  import { config } from './config.js';
23
24
  import { S3Uploader } from './uploader.js';
@@ -553,52 +554,6 @@ class XmlReader {
553
554
  return run;
554
555
  }
555
556
 
556
- /**
557
- * Calculate the approximate size of data in bytes (JSON stringified length)
558
- * @param {Object} data - Data to measure
559
- * @returns {number} Size in bytes
560
- */
561
- #getObjectSize(data) {
562
- const body = JSON.stringify(data);
563
- return new TextEncoder().encode(body).length;
564
- }
565
-
566
- /**
567
- * Split tests array into chunks based on data size
568
- * @param {Array} tests - Array of tests to split
569
- * @returns {Array<Array>} Array of test chunks
570
- */
571
- #splitTestsIntoChunks(tests) {
572
- const maxSizeBytes = 1 * 1024 * 1024;
573
-
574
- const chunks = [];
575
- let currentChunk = [];
576
- let currentChunkSize = 0;
577
-
578
- for (const test of tests) {
579
- const testSize = this.#getObjectSize(test);
580
-
581
- const wouldExceedSize = currentChunkSize + testSize > maxSizeBytes;
582
-
583
- if (wouldExceedSize) {
584
- if (currentChunk.length > 0) {
585
- chunks.push(currentChunk);
586
- }
587
- currentChunk = [];
588
- currentChunkSize = 0;
589
- }
590
-
591
- currentChunk.push(test);
592
- currentChunkSize += testSize;
593
- }
594
-
595
- if (currentChunk.length > 0) {
596
- chunks.push(currentChunk);
597
- }
598
-
599
- return chunks;
600
- }
601
-
602
557
  async uploadData() {
603
558
  await this.uploadArtifacts();
604
559
  this.calculateStats();
@@ -623,7 +578,7 @@ class XmlReader {
623
578
  return Promise.all(this.pipes.map(p => p.finishRun(finishData)));
624
579
  }
625
580
 
626
- const testChunks = this.#splitTestsIntoChunks(this.tests);
581
+ const testChunks = splitTestsIntoChunks(this.tests);
627
582
 
628
583
  const totalChunks = testChunks.length;
629
584
  const totalTests = this.tests.length;