testomatio-reporter-cli 2.10.1 → 2.12.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testomatio-reporter-cli",
3
- "version": "2.10.1",
3
+ "version": "2.12.0",
4
4
  "description": "Yarn Berry compatible standalone CLI for @testomatio/reporter",
5
5
  "type": "module",
6
6
  "bin": {
package/src/bin/cli.js CHANGED
@@ -8,7 +8,7 @@ import TestomatClient from '../client.js';
8
8
  import XmlReader from '../xmlReader.js';
9
9
  import AllureReader from '../allureReader.js';
10
10
  import { APP_PREFIX, STATUS, DEBUG_FILE, BATCH_MODE } from '../constants.js';
11
- import { cleanLatestRunId, getPackageVersion, applyFilter } from '../utils/utils.js';
11
+ import { cleanLatestRunId, getPackageVersion, applyFilter, transformEnvVarToBoolean } from '../utils/utils.js';
12
12
  import { config } from '../config.js';
13
13
  import { readLatestRunId } from '../utils/utils.js';
14
14
  import pc from 'picocolors';
@@ -87,6 +87,11 @@ program
87
87
  process.exit(1);
88
88
  }
89
89
 
90
+ // tests are executed later, so report the run as pending with the tests it was scoped to:
91
+ // pipes add their report now and replace it when the run is finished
92
+ const plannedTests = (client.pipeStore.preparedTestIds || []).map(id => ({ test_id: id, title: id }));
93
+ await client.updateRunStatus('pending', { tests: plannedTests });
94
+
90
95
  // stdout carries ONLY the run id so it can be captured: RUN_ID=$(reporter start)
91
96
  console.log(runId);
92
97
  process.exit(0);
@@ -107,8 +112,11 @@ program
107
112
  const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config.TESTOMATIO;
108
113
  const client = new TestomatClient({ apiKey });
109
114
 
115
+ const finishParams = {};
116
+ if (transformEnvVarToBoolean(process.env.TESTOMATIO_FINISH_SHARED_RUN)) finishParams.force_finish_shared_run = true;
117
+
110
118
  // @ts-ignore
111
- client.updateRunStatus(STATUS.FINISHED).then(() => {
119
+ client.updateRunStatus(STATUS.FINISHED, finishParams).then(() => {
112
120
  process.exit(0);
113
121
  });
114
122
  });
package/src/client.js CHANGED
@@ -206,9 +206,9 @@ class Client {
206
206
  suite_title: 'Unknown suite',
207
207
  };
208
208
 
209
- // Add timestamp if not already present (microseconds since Unix epoch)
209
+ // Add timestamp if not already present (Unix seconds)
210
210
  if (!testData.timestamp && !process.env.TESTOMATIO_NO_TIMESTAMP) {
211
- testData.timestamp = Math.floor((performance.timeOrigin + performance.now()) * 1000);
211
+ testData.timestamp = Math.floor((performance.timeOrigin + performance.now()) / 1000);
212
212
  }
213
213
 
214
214
  /**
@@ -371,7 +371,7 @@ class Client {
371
371
  /**
372
372
  *
373
373
  * Updates the status of the current test run and finishes the run.
374
- * @param {'passed' | 'failed' | 'skipped' | 'finished'} status - The status of the current test run.
374
+ * @param {'passed' | 'failed' | 'skipped' | 'finished' | 'pending'} status - The status of the current test run.
375
375
  * @param {Partial<import('../types/types.js').RunData>} [params] - Additional run params (e.g. duration).
376
376
  * Must be one of "passed", "failed", or "finished"
377
377
  * @returns {Promise<any>} - A Promise that resolves when finishes the run.
@@ -0,0 +1,103 @@
1
+ import path from 'path';
2
+ import Adapter from './adapter.js';
3
+
4
+ class DartAdapter extends Adapter {
5
+
6
+ getFilePath(t) {
7
+ if (t.title.startsWith('runDartTest[')) {
8
+ // Android: runDartTest[tests.path.to.test Test name]
9
+ const fileName = namespaceToFileName(t.title.split('[')[1].split(' ')[0]);
10
+ return fileName;
11
+ }
12
+ // iOS: RunnerUITests tests.path.to.test Test name
13
+ const parts = t.title.split(' ');
14
+ const pathToken = parts.length > 1 ? parts[1] : parts[0];
15
+ return namespaceToFileName(pathToken);
16
+ }
17
+
18
+ formatTest(t) {
19
+ if (t.title.startsWith('runDartTest[')) {
20
+ // Android: runDartTest[<path> <name>]
21
+ // First space is between the path and the test name; strip up to and including it, remove trailing ']'
22
+ const spaceIndex = t.title.indexOf(' ');
23
+ if (spaceIndex > -1) {
24
+ const pathToken = t.title.slice('runDartTest['.length, spaceIndex);
25
+ t.file = namespaceToFileName(pathToken);
26
+ t.title = t.title.slice(spaceIndex + 1).replace(/\]$/, '');
27
+ }
28
+ } else {
29
+ // iOS: <ClassName> <test.path> <test name>
30
+ // Skip both the classname token and the dot-separated test path token
31
+ const parts = t.title.split(' ');
32
+ if (parts.length > 2 && parts[1] && parts[1].includes('.')) {
33
+ t.file = namespaceToFileName(parts[1]);
34
+ t.title = parts.slice(2).join(' ');
35
+ } else {
36
+ const spaceIndex = t.title.indexOf(' ');
37
+ if (spaceIndex > -1) {
38
+ t.title = t.title.slice(spaceIndex + 1);
39
+ }
40
+ }
41
+ }
42
+
43
+ // classname: cut everything after the last dot (inclusive)
44
+ if (t.suite_title && t.suite_title.includes('.')) {
45
+ const lastDot = t.suite_title.lastIndexOf('.');
46
+ t.suite_title = t.suite_title.slice(0, lastDot);
47
+ }
48
+
49
+ if (!t.file) {
50
+ t.file = namespaceToFileName(t.suite_title || '');
51
+ }
52
+
53
+ // detect params
54
+ const paramMatches = t.title.match(/\[(.*?)\]/g);
55
+
56
+ if (paramMatches) {
57
+ const params = paramMatches.map((_match, index) => `param${index + 1}`);
58
+ if (params.length === 1) params[0] = 'param';
59
+ let paramIndex = 0;
60
+
61
+ t.title = t.title.replace(/\[(.*?)\]/g, () => {
62
+ if (params.length < 2) return `\${param}`;
63
+ const paramName = params[paramIndex] || `param${paramIndex + 1}`;
64
+ paramIndex++;
65
+ return `\${${paramName}}`;
66
+ });
67
+ const example = {};
68
+ paramMatches.forEach((match, index) => {
69
+ example[params[index]] = match.replace(/[[\]]/g, '');
70
+ });
71
+ t.example = example;
72
+ }
73
+
74
+ return t;
75
+ }
76
+ }
77
+
78
+ function namespaceToFileName(fileName) {
79
+ let testName = fileName;
80
+
81
+ // If it's already an extracted test name (contains dots but no runDartTest prefix)
82
+ if (fileName.includes('.') && !fileName.startsWith('runDartTest')) {
83
+ // Take only the first part before any spaces (the actual test path)
84
+ testName = fileName.split(' ')[0];
85
+ } else {
86
+ // Legacy handling for full runDartTest[...] format
87
+ const dartMatch = fileName.match(/runDartTest\[(.+?) /);
88
+ if (dartMatch) {
89
+ testName = dartMatch[1];
90
+ } else {
91
+ const parts = fileName.split(' ');
92
+ if (parts.length > 1) {
93
+ testName = parts[1];
94
+ }
95
+ }
96
+ }
97
+
98
+ const fileParts = testName.split('.');
99
+ fileParts[fileParts.length - 1] = fileParts[fileParts.length - 1]?.replace(/\$.*/, '');
100
+ return `${fileParts.join(path.sep)}.dart`;
101
+ }
102
+
103
+ export default DartAdapter;
@@ -5,6 +5,7 @@ import PythonAdapter from './python.js';
5
5
  import RubyAdapter from './ruby.js';
6
6
  import CSharpAdapter from './csharp.js';
7
7
  import KotlinAdapter from './kotlin.js';
8
+ import DartAdapter from './dart.js';
8
9
 
9
10
  function AdapterFactory(lang, opts) {
10
11
  if (lang === 'java') {
@@ -25,6 +26,9 @@ function AdapterFactory(lang, opts) {
25
26
  if (lang === 'kotlin') {
26
27
  return new KotlinAdapter(opts);
27
28
  }
29
+ if (lang === 'dart') {
30
+ return new DartAdapter(opts);
31
+ }
28
32
 
29
33
  return new Adapter(opts);
30
34
  }
package/src/pipe/html.js CHANGED
@@ -268,7 +268,7 @@ class HtmlPipe {
268
268
  executionTime: testExecutionSumTime(aggregatedTests),
269
269
  executionDate: getCurrentDateTimeFormatted(),
270
270
  description:
271
- [runParams.description || this.store.coverageDescription || this.store.description, this.description]
271
+ [this.description, runParams.description || this.store.coverageDescription || this.store.description]
272
272
  .filter(Boolean)
273
273
  .join('\n\n') || '',
274
274
  configuration: buildDisplayConfiguration(
@@ -140,7 +140,7 @@ class MarkdownPipe {
140
140
  executionTime: testExecutionSumTime(aggregated),
141
141
  executionDate: getCurrentDateTimeFormatted(),
142
142
  description:
143
- [runParams?.description || this.store.coverageDescription || this.store.description, this.description]
143
+ [this.description, runParams?.description || this.store.coverageDescription || this.store.description]
144
144
  .filter(Boolean)
145
145
  .join('\n\n') || '',
146
146
  configuration: this.configuration || this.store.configuration || runParams?.configuration || null,
@@ -167,6 +167,12 @@ class TestomatioPipe {
167
167
  // add test ID + run ID
168
168
  if (data.rid) data.rid = `${this.runId}-${data.rid}`;
169
169
 
170
+ // convert timestamp to seconds
171
+ if (data.timestamp > 1e11) {
172
+ if (data.timestamp > 1e14) data.timestamp = Math.floor(data.timestamp / 1e6); // convert microseconds
173
+ else if (data.timestamp > 1e11) data.timestamp = Math.floor(data.timestamp / 1e3); // convert milliseconds
174
+ }
175
+
170
176
  if (!process.env.TESTOMATIO_STACK_PASSED && data.status === STATUS.PASSED) {
171
177
  data.stack = null;
172
178
  }
@@ -273,8 +279,9 @@ class TestomatioPipe {
273
279
  suites: coverageConfiguration.suites?.map(id => id.replace(/^S/, '')) || [],
274
280
  };
275
281
  }
276
- // Run description: coverage-derived block (if any) with the user-provided TESTOMATIO_DESCRIPTION appended after it.
277
- const description = [coverageDescription, this.description].filter(Boolean).join('\n\n') || null;
282
+ // Run description: the user-provided TESTOMATIO_DESCRIPTION with the coverage-derived block
283
+ // (if any) added after it. Neither overrides the other.
284
+ const description = [this.description, coverageDescription].filter(Boolean).join('\n\n') || null;
278
285
 
279
286
  // Merge caller-supplied configuration (e.g. { exploratory: true }) into runParams.configuration.
280
287
  // Caller values win on key conflict; coverage-derived tests/suites lists are preserved when not overridden.
@@ -552,6 +559,9 @@ class TestomatioPipe {
552
559
 
553
560
  const { status } = params;
554
561
 
562
+ // a pending run was just created: nothing to update here, only other pipes report it
563
+ if (status === 'pending') return;
564
+
555
565
  let status_event;
556
566
 
557
567
  if (status === STATUS.FINISHED) status_event = 'finish';
@@ -569,6 +579,7 @@ class TestomatioPipe {
569
579
  status_event,
570
580
  detach: params.detach,
571
581
  tests: params.tests,
582
+ ...(params.force_finish_shared_run && { force_finish_shared_run: true }),
572
583
  },
573
584
  });
574
585
 
@@ -117,6 +117,7 @@ function statusEmoji(status) {
117
117
  if (status === 'passed') return '🟢';
118
118
  if (status === 'failed') return '🔴';
119
119
  if (status === 'skipped') return '🟡';
120
+ if (status === 'pending') return '🕐';
120
121
  return '';
121
122
  }
122
123
 
@@ -271,6 +271,26 @@ const fetchIdFromOutput = output => {
271
271
  return output.match(TID_FULL_PATTERN)?.[2];
272
272
  };
273
273
 
274
+ const findDartTestLine = (lines, expectedTitle) => {
275
+ const testFunctions = ['patrolTest', 'testWidgets'];
276
+ const quotedTitles = [`'${expectedTitle}',`, `"${expectedTitle}",`, `r'${expectedTitle}',`, `r"${expectedTitle}",`];
277
+
278
+ return lines.findIndex((_line, index) => {
279
+ const declaration = lines
280
+ .slice(index, index + 5)
281
+ .map(line => line.trim())
282
+ .join(' ');
283
+ const functionName = testFunctions.find(name => declaration.startsWith(name));
284
+ if (!functionName) return false;
285
+
286
+ const argumentsList = declaration.slice(functionName.length).trimStart();
287
+ if (!argumentsList.startsWith('(')) return false;
288
+
289
+ const firstArgument = argumentsList.slice(1).trimStart();
290
+ return quotedTitles.some(title => firstArgument.startsWith(title));
291
+ });
292
+ };
293
+
274
294
  const fetchSourceCode = (contents, opts = {}) => {
275
295
  if (!opts.title && !opts.line) return '';
276
296
 
@@ -354,6 +374,32 @@ const fetchSourceCode = (contents, opts = {}) => {
354
374
  }
355
375
  }
356
376
  }
377
+ } else if (opts.lang === 'dart') {
378
+ // For Dart, locate the specific patrolTest/testWidgets block by title first —
379
+ // otherwise every test sharing the same main() gets the same @T comment.
380
+ const rawTitle = opts.title || '';
381
+ let dartTestTitle = '';
382
+
383
+ if (rawTitle.startsWith('runDartTest[')) {
384
+ // Android: runDartTest[<path> <test name>]
385
+ const spaceIndex = rawTitle.indexOf(' ');
386
+ if (spaceIndex > -1) {
387
+ dartTestTitle = rawTitle.slice(spaceIndex + 1).replace(/\]$/, '');
388
+ }
389
+ } else {
390
+ // iOS: <ClassName> <test.path> <test name>
391
+ const parts = rawTitle.split(' ');
392
+ if (parts.length > 2 && parts[1] && parts[1].includes('.')) {
393
+ dartTestTitle = parts.slice(2).join(' ');
394
+ }
395
+ }
396
+
397
+ let testLineIndex = -1;
398
+ if (dartTestTitle) {
399
+ testLineIndex = findDartTestLine(lines, dartTestTitle);
400
+ }
401
+
402
+ lineIndex = testLineIndex;
357
403
  } else {
358
404
  lineIndex = lines.findIndex(l => l.includes(title));
359
405
  }
@@ -371,8 +417,8 @@ const fetchSourceCode = (contents, opts = {}) => {
371
417
  for (let i = lineIndex; i < lineIndex + limit; i++) {
372
418
  if (lines[i] === undefined) continue;
373
419
 
374
- // Track brace depth for C# to stop after method closes
375
- if (opts.lang === 'csharp') {
420
+ // Track brace depth for C# and Dart to stop after method/main closes
421
+ if (opts.lang === 'csharp' || opts.lang === 'dart') {
376
422
  const line = lines[i];
377
423
  // Count opening and closing braces
378
424
  const openBraces = (line.match(/\{/g) || []).length;
package/src/xmlReader.js CHANGED
@@ -472,6 +472,7 @@ class XmlReader {
472
472
  if (file.endsWith('.js')) this.stats.language = 'js';
473
473
  if (file.endsWith('.ts')) this.stats.language = 'ts';
474
474
  if (file.endsWith('.cs')) this.stats.language = 'csharp';
475
+ if (file.endsWith('.dart')) this.stats.language = 'dart';
475
476
  }
476
477
 
477
478
  if (!fs.existsSync(file)) {
package/types/types.d.ts CHANGED
@@ -274,6 +274,9 @@ export interface RunData {
274
274
  * An array of `TestData` objects representing the individual test cases in the test run.
275
275
  * Used for JUNit report when we don't send the tests in realtime but in a batch as a part of final result */
276
276
  tests?: TestData[];
277
+
278
+ /** Force-finish a shared run even if other participants haven't finished yet. Set via `TESTOMATIO_FINISH_SHARED_RUN`. */
279
+ force_finish_shared_run?: boolean;
277
280
  }
278
281
 
279
282
  export enum TestStatus {
@@ -286,6 +289,8 @@ export enum RunStatus {
286
289
  Passed = 'passed',
287
290
  Failed = 'failed',
288
291
  Finished = 'finished',
292
+ /** run created but not executed yet, reported by `reporter start` */
293
+ Pending = 'pending',
289
294
  }
290
295
 
291
296
  /** Batch upload strategy: