@testomatio/reporter 2.9.3-beta.2-allure-improv → 2.9.3-beta.4-allure-links
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/lib/allureReader.d.ts +56 -17
- package/lib/allureReader.js +141 -62
- package/lib/bin/cli.js +1 -1
- package/package.json +1 -1
- package/src/allureReader.js +136 -57
- package/src/bin/cli.js +1 -1
package/lib/allureReader.d.ts
CHANGED
|
@@ -66,17 +66,35 @@ declare class AllureReader {
|
|
|
66
66
|
label: string;
|
|
67
67
|
}[];
|
|
68
68
|
/**
|
|
69
|
-
* Extract
|
|
69
|
+
* Extract all Testomat.io test ids from Allure links so reported results match
|
|
70
70
|
* existing cases instead of creating duplicates.
|
|
71
71
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* accepted. The link `name` is used as
|
|
72
|
+
* A test may carry several `@TmsLink`s (e.g. `@TmsLinks(@TmsLink("…"), @TmsLink("…"))`),
|
|
73
|
+
* each producing a link with `type: "tms"`. Some exporters omit the type but still point
|
|
74
|
+
* the link URL at a Testomat.io test page; both are accepted. The link `name` is used as
|
|
75
|
+
* the id (falling back to the id segment of a Testomat.io URL). Ids are normalized and
|
|
76
|
+
* de-duplicated, preserving order so the first one stays the primary `test_id`.
|
|
75
77
|
*
|
|
76
78
|
* @param {object} result - Parsed Allure result JSON
|
|
77
|
-
* @returns {string
|
|
79
|
+
* @returns {string[]} Normalized test ids (possibly empty)
|
|
80
|
+
*/
|
|
81
|
+
extractTmsIds(result: object): string[];
|
|
82
|
+
/**
|
|
83
|
+
* The primary Testomat.io test id (the first `@TmsLink`), or null when there is none.
|
|
84
|
+
*
|
|
85
|
+
* @param {object} result - Parsed Allure result JSON
|
|
86
|
+
* @returns {string|null}
|
|
78
87
|
*/
|
|
79
88
|
extractTestId(result: object): string | null;
|
|
89
|
+
/**
|
|
90
|
+
* Attach additional linked test cases to a reported test as `{ test: id }` link entries
|
|
91
|
+
* (the same shape `linkTest()` uses), so a single result updates every case it is linked
|
|
92
|
+
* to — not just the primary `test_id`. Existing links are preserved; duplicates skipped.
|
|
93
|
+
*
|
|
94
|
+
* @param {object} test - converted test
|
|
95
|
+
* @param {string[]} ids - additional test ids to link
|
|
96
|
+
*/
|
|
97
|
+
addLinkedTestIds(test: object, ids: string[]): void;
|
|
80
98
|
/**
|
|
81
99
|
* Normalize a value into a Testomat.io test id.
|
|
82
100
|
*
|
|
@@ -101,14 +119,24 @@ declare class AllureReader {
|
|
|
101
119
|
* the server create a duplicate case. The id still lives in the source, on the test
|
|
102
120
|
* method, so we read it from there as a fallback.
|
|
103
121
|
*
|
|
104
|
-
* The lookup is method-scoped: we locate the test method declaration by name,
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
122
|
+
* The lookup is method-scoped: we locate the test method declaration by name, collect
|
|
123
|
+
* its annotation/comment block (the lines directly above it, up to the previous code
|
|
124
|
+
* construct) and read every `@TmsLink` from it — so an unrelated method's annotation can
|
|
125
|
+
* never be picked up. Both `@TmsLink("…")` and the container forms
|
|
126
|
+
* `@TmsLinks(@TmsLink("…"), @TmsLink("…"))` (single- or multi-line) are supported.
|
|
108
127
|
*
|
|
109
128
|
* @param {string} contents - full source file
|
|
110
129
|
* @param {object} test - converted test (uses `title`)
|
|
111
|
-
* @returns {string
|
|
130
|
+
* @returns {string[]} normalized 8-char ids in source order (possibly empty)
|
|
131
|
+
*/
|
|
132
|
+
extractTmsIdsFromSource(contents: string, test: object): string[];
|
|
133
|
+
/**
|
|
134
|
+
* The primary `@TmsLink` id for a test method in source, or null. Convenience wrapper
|
|
135
|
+
* around {@link extractTmsIdsFromSource}.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} contents - full source file
|
|
138
|
+
* @param {object} test - converted test (uses `title`)
|
|
139
|
+
* @returns {string|null}
|
|
112
140
|
*/
|
|
113
141
|
extractTmsIdFromSource(contents: string, test: object): string | null;
|
|
114
142
|
convertSteps(steps: any, depth?: number): any;
|
|
@@ -143,15 +171,26 @@ declare class AllureReader {
|
|
|
143
171
|
fetchSourceCode(): void;
|
|
144
172
|
getLanguage(): any;
|
|
145
173
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* Allure results drop the `@TmsLink` link and would otherwise create duplicate
|
|
174
|
+
* Link tests to their Testomat.io cases by reading `@TmsLink` from source for tests that
|
|
175
|
+
* carry no `{ test: … }` link yet. This rescues skipped (`@Ignore` / `@Disabled`) tests,
|
|
176
|
+
* whose Allure results drop the `@TmsLink` link and would otherwise create duplicate
|
|
177
|
+
* cases. Every `@TmsLink` on the method is linked (consistent with executed tests); the
|
|
178
|
+
* `test_id` is left untouched — links and test_id are separate concerns.
|
|
179
|
+
*
|
|
180
|
+
* Opt-in: only runs when `--java-tests` (a source root) is provided. The source files are
|
|
181
|
+
* indexed once by basename; for each not-yet-linked test we read the candidate file(s)
|
|
182
|
+
* matching its `testFile` / class name and parse the method's `@TmsLink`(s).
|
|
183
|
+
*/
|
|
184
|
+
recoverTmsLinksFromSource(): void;
|
|
185
|
+
/**
|
|
186
|
+
* Fallback: when a test has no `test_id`, adopt the first linked case (`@TmsLink`) as its
|
|
187
|
+
* `test_id` so it matches an existing case instead of creating a method-named duplicate.
|
|
149
188
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
189
|
+
* Runs after `fetchSourceCode`, so a native Testomat.io id parsed from source always wins.
|
|
190
|
+
* The id stays in `links` as well — every linked case is still updated; this only gives the
|
|
191
|
+
* test a primary identity to match on.
|
|
153
192
|
*/
|
|
154
|
-
|
|
193
|
+
applyPrimaryTestIdFromLinks(): void;
|
|
155
194
|
/**
|
|
156
195
|
* Build (and cache) a basename -> [absolute paths] index of source files under `root`.
|
|
157
196
|
* Walks synchronously, skipping common build/dependency directories.
|
package/lib/allureReader.js
CHANGED
|
@@ -169,12 +169,12 @@ class AllureReader {
|
|
|
169
169
|
create: true,
|
|
170
170
|
overwrite: true,
|
|
171
171
|
};
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
// @TmsLink references link the result to existing Testomat.io cases. Add EVERY id as
|
|
173
|
+
// a linked case ({ test: id }) so all of them are updated from this one result, with
|
|
174
|
+
// consistent behaviour whether the test has one or many @TmsLink. The test_id is kept
|
|
175
|
+
// a SEPARATE concern — it is never derived from @TmsLink; it is only set from a native
|
|
176
|
+
// Testomat.io id found in source (see fetchSourceCode / fetchIdFromCode).
|
|
177
|
+
this.addLinkedTestIds(test, this.extractTmsIds(result));
|
|
178
178
|
// Add description if present
|
|
179
179
|
if (result.description) {
|
|
180
180
|
test.description = result.description;
|
|
@@ -325,33 +325,67 @@ class AllureReader {
|
|
|
325
325
|
return links.length > 0 ? links : undefined;
|
|
326
326
|
}
|
|
327
327
|
/**
|
|
328
|
-
* Extract
|
|
328
|
+
* Extract all Testomat.io test ids from Allure links so reported results match
|
|
329
329
|
* existing cases instead of creating duplicates.
|
|
330
330
|
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
* accepted. The link `name` is used as
|
|
331
|
+
* A test may carry several `@TmsLink`s (e.g. `@TmsLinks(@TmsLink("…"), @TmsLink("…"))`),
|
|
332
|
+
* each producing a link with `type: "tms"`. Some exporters omit the type but still point
|
|
333
|
+
* the link URL at a Testomat.io test page; both are accepted. The link `name` is used as
|
|
334
|
+
* the id (falling back to the id segment of a Testomat.io URL). Ids are normalized and
|
|
335
|
+
* de-duplicated, preserving order so the first one stays the primary `test_id`.
|
|
334
336
|
*
|
|
335
337
|
* @param {object} result - Parsed Allure result JSON
|
|
336
|
-
* @returns {string
|
|
338
|
+
* @returns {string[]} Normalized test ids (possibly empty)
|
|
337
339
|
*/
|
|
338
|
-
|
|
340
|
+
extractTmsIds(result) {
|
|
339
341
|
const links = result.links || [];
|
|
340
342
|
if (!links.length)
|
|
341
|
-
return
|
|
343
|
+
return [];
|
|
342
344
|
const isTmsLink = l => typeof l?.type === 'string' && l.type.toLowerCase() === 'tms';
|
|
343
345
|
const isTestomatioLink = l => typeof l?.url === 'string' && /testomat\.io\/[^\s]*\/test\//i.test(l.url);
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
346
|
+
const ids = [];
|
|
347
|
+
for (const link of links) {
|
|
348
|
+
if (!isTmsLink(link) && !isTestomatioLink(link))
|
|
349
|
+
continue;
|
|
350
|
+
// Prefer the explicit link name; fall back to the id segment of a Testomat.io URL.
|
|
351
|
+
let id = this.normalizeTestId(link.name);
|
|
352
|
+
if (!id && typeof link.url === 'string') {
|
|
353
|
+
const fromUrl = link.url.match(/\/test\/([\w\d]{8})(?=$|[/?#])/i);
|
|
354
|
+
if (fromUrl)
|
|
355
|
+
id = fromUrl[1];
|
|
356
|
+
}
|
|
357
|
+
if (id && !ids.includes(id))
|
|
358
|
+
ids.push(id);
|
|
359
|
+
}
|
|
360
|
+
return ids;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* The primary Testomat.io test id (the first `@TmsLink`), or null when there is none.
|
|
364
|
+
*
|
|
365
|
+
* @param {object} result - Parsed Allure result JSON
|
|
366
|
+
* @returns {string|null}
|
|
367
|
+
*/
|
|
368
|
+
extractTestId(result) {
|
|
369
|
+
return this.extractTmsIds(result)[0] || null;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Attach additional linked test cases to a reported test as `{ test: id }` link entries
|
|
373
|
+
* (the same shape `linkTest()` uses), so a single result updates every case it is linked
|
|
374
|
+
* to — not just the primary `test_id`. Existing links are preserved; duplicates skipped.
|
|
375
|
+
*
|
|
376
|
+
* @param {object} test - converted test
|
|
377
|
+
* @param {string[]} ids - additional test ids to link
|
|
378
|
+
*/
|
|
379
|
+
addLinkedTestIds(test, ids) {
|
|
380
|
+
if (!ids || !ids.length)
|
|
381
|
+
return;
|
|
382
|
+
if (!Array.isArray(test.links))
|
|
383
|
+
test.links = [];
|
|
384
|
+
for (const id of ids) {
|
|
385
|
+
if (!test.links.some(l => l && l.test === id)) {
|
|
386
|
+
test.links.push({ test: id });
|
|
387
|
+
}
|
|
353
388
|
}
|
|
354
|
-
return id;
|
|
355
389
|
}
|
|
356
390
|
/**
|
|
357
391
|
* Normalize a value into a Testomat.io test id.
|
|
@@ -382,22 +416,23 @@ class AllureReader {
|
|
|
382
416
|
* the server create a duplicate case. The id still lives in the source, on the test
|
|
383
417
|
* method, so we read it from there as a fallback.
|
|
384
418
|
*
|
|
385
|
-
* The lookup is method-scoped: we locate the test method declaration by name,
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
419
|
+
* The lookup is method-scoped: we locate the test method declaration by name, collect
|
|
420
|
+
* its annotation/comment block (the lines directly above it, up to the previous code
|
|
421
|
+
* construct) and read every `@TmsLink` from it — so an unrelated method's annotation can
|
|
422
|
+
* never be picked up. Both `@TmsLink("…")` and the container forms
|
|
423
|
+
* `@TmsLinks(@TmsLink("…"), @TmsLink("…"))` (single- or multi-line) are supported.
|
|
389
424
|
*
|
|
390
425
|
* @param {string} contents - full source file
|
|
391
426
|
* @param {object} test - converted test (uses `title`)
|
|
392
|
-
* @returns {string
|
|
427
|
+
* @returns {string[]} normalized 8-char ids in source order (possibly empty)
|
|
393
428
|
*/
|
|
394
|
-
|
|
429
|
+
extractTmsIdsFromSource(contents, test) {
|
|
395
430
|
if (!contents || !test || !test.title)
|
|
396
|
-
return
|
|
431
|
+
return [];
|
|
397
432
|
const lines = contents.split('\n');
|
|
398
433
|
const title = test.title.replace(/[([].*$/, '').trim();
|
|
399
434
|
if (!title)
|
|
400
|
-
return
|
|
435
|
+
return [];
|
|
401
436
|
const escaped = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
402
437
|
// Locate the test method declaration (Kotlin `fun name(`, then a typed declaration,
|
|
403
438
|
// then a generic `name(` fallback for other JVM languages).
|
|
@@ -407,21 +442,42 @@ class AllureReader {
|
|
|
407
442
|
if (idx === -1)
|
|
408
443
|
idx = lines.findIndex(l => new RegExp(`\\b${escaped}\\s*\\(`).test(l));
|
|
409
444
|
if (idx === -1)
|
|
410
|
-
return
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
if (
|
|
419
|
-
break;
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
445
|
+
return [];
|
|
446
|
+
// Collect the annotation/comment block above the declaration. Stop at the previous
|
|
447
|
+
// code construct (a line ending in `{`/`}` or another method declaration) so we never
|
|
448
|
+
// read into a sibling method. Multi-line `@TmsLinks(...)` continuation lines (e.g. a
|
|
449
|
+
// lone `@TmsLink("…"),` or a closing `)`) are kept because they aren't boundaries.
|
|
450
|
+
const block = [];
|
|
451
|
+
for (let i = idx - 1, scanned = 0; i >= 0 && scanned < 60; i--, scanned++) {
|
|
452
|
+
const trimmed = lines[i].trim();
|
|
453
|
+
if (trimmed.endsWith('{') || trimmed.endsWith('}'))
|
|
454
|
+
break;
|
|
455
|
+
if (/\bfun\s+\w+\s*\(/.test(trimmed))
|
|
456
|
+
break;
|
|
457
|
+
block.push(lines[i]);
|
|
458
|
+
}
|
|
459
|
+
const ids = [];
|
|
460
|
+
const tmsRe = /\bTmsLink\s*\(\s*["']([^"']+)["']/g;
|
|
461
|
+
let match;
|
|
462
|
+
// block was collected bottom-up; reverse so ids come out in source order
|
|
463
|
+
const text = block.reverse().join('\n');
|
|
464
|
+
while ((match = tmsRe.exec(text)) !== null) {
|
|
465
|
+
const id = this.normalizeTestId(match[1]);
|
|
466
|
+
if (id && !ids.includes(id))
|
|
467
|
+
ids.push(id);
|
|
468
|
+
}
|
|
469
|
+
return ids;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* The primary `@TmsLink` id for a test method in source, or null. Convenience wrapper
|
|
473
|
+
* around {@link extractTmsIdsFromSource}.
|
|
474
|
+
*
|
|
475
|
+
* @param {string} contents - full source file
|
|
476
|
+
* @param {object} test - converted test (uses `title`)
|
|
477
|
+
* @returns {string|null}
|
|
478
|
+
*/
|
|
479
|
+
extractTmsIdFromSource(contents, test) {
|
|
480
|
+
return this.extractTmsIdsFromSource(contents, test)[0] || null;
|
|
425
481
|
}
|
|
426
482
|
convertSteps(steps, depth = 0) {
|
|
427
483
|
if (depth >= 10)
|
|
@@ -610,20 +666,23 @@ class AllureReader {
|
|
|
610
666
|
return this._tests[0].meta?.language || this.opts.lang;
|
|
611
667
|
}
|
|
612
668
|
/**
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* Allure results drop the `@TmsLink` link and would otherwise create duplicate
|
|
669
|
+
* Link tests to their Testomat.io cases by reading `@TmsLink` from source for tests that
|
|
670
|
+
* carry no `{ test: … }` link yet. This rescues skipped (`@Ignore` / `@Disabled`) tests,
|
|
671
|
+
* whose Allure results drop the `@TmsLink` link and would otherwise create duplicate
|
|
672
|
+
* cases. Every `@TmsLink` on the method is linked (consistent with executed tests); the
|
|
673
|
+
* `test_id` is left untouched — links and test_id are separate concerns.
|
|
616
674
|
*
|
|
617
|
-
* Opt-in: only runs when `--java-tests` (a source root) is provided. The source
|
|
618
|
-
*
|
|
619
|
-
*
|
|
675
|
+
* Opt-in: only runs when `--java-tests` (a source root) is provided. The source files are
|
|
676
|
+
* indexed once by basename; for each not-yet-linked test we read the candidate file(s)
|
|
677
|
+
* matching its `testFile` / class name and parse the method's `@TmsLink`(s).
|
|
620
678
|
*/
|
|
621
|
-
|
|
679
|
+
recoverTmsLinksFromSource() {
|
|
622
680
|
const root = this.opts.javaTests;
|
|
623
681
|
if (!root)
|
|
624
682
|
return;
|
|
625
|
-
const
|
|
626
|
-
|
|
683
|
+
const hasTestLink = t => Array.isArray(t.links) && t.links.some(l => l && l.test);
|
|
684
|
+
const unlinked = this._tests.filter(t => !hasTestLink(t));
|
|
685
|
+
if (!unlinked.length)
|
|
627
686
|
return;
|
|
628
687
|
if (!fs_1.default.existsSync(root)) {
|
|
629
688
|
debug('java-tests source root not found: %s', root);
|
|
@@ -631,7 +690,7 @@ class AllureReader {
|
|
|
631
690
|
}
|
|
632
691
|
const index = this.indexSourceFiles(root);
|
|
633
692
|
let recovered = 0;
|
|
634
|
-
for (const t of
|
|
693
|
+
for (const t of unlinked) {
|
|
635
694
|
for (const filePath of this.sourceCandidatesForTest(t, index)) {
|
|
636
695
|
let contents;
|
|
637
696
|
try {
|
|
@@ -641,17 +700,36 @@ class AllureReader {
|
|
|
641
700
|
debug('Failed to read source %s: %s', filePath, err.message);
|
|
642
701
|
continue;
|
|
643
702
|
}
|
|
644
|
-
const
|
|
645
|
-
if (
|
|
646
|
-
t
|
|
703
|
+
const ids = this.extractTmsIdsFromSource(contents, t);
|
|
704
|
+
if (ids.length) {
|
|
705
|
+
this.addLinkedTestIds(t, ids);
|
|
647
706
|
recovered++;
|
|
648
|
-
debug('
|
|
707
|
+
debug('Linked %s to case(s) %s from @TmsLink in %s', t.title, ids.join(', '), filePath);
|
|
649
708
|
break;
|
|
650
709
|
}
|
|
651
710
|
}
|
|
652
711
|
}
|
|
653
712
|
if (recovered) {
|
|
654
|
-
console.log(constants_js_1.APP_PREFIX, `🔗
|
|
713
|
+
console.log(constants_js_1.APP_PREFIX, `🔗 Linked ${picocolors_1.default.bold(recovered)} test(s) to cases from @TmsLink in source`);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Fallback: when a test has no `test_id`, adopt the first linked case (`@TmsLink`) as its
|
|
718
|
+
* `test_id` so it matches an existing case instead of creating a method-named duplicate.
|
|
719
|
+
*
|
|
720
|
+
* Runs after `fetchSourceCode`, so a native Testomat.io id parsed from source always wins.
|
|
721
|
+
* The id stays in `links` as well — every linked case is still updated; this only gives the
|
|
722
|
+
* test a primary identity to match on.
|
|
723
|
+
*/
|
|
724
|
+
applyPrimaryTestIdFromLinks() {
|
|
725
|
+
for (const t of this._tests) {
|
|
726
|
+
if (t.test_id)
|
|
727
|
+
continue;
|
|
728
|
+
const firstTestLink = Array.isArray(t.links) ? t.links.find(l => l && l.test) : null;
|
|
729
|
+
if (firstTestLink) {
|
|
730
|
+
t.test_id = firstTestLink.test;
|
|
731
|
+
debug('Using first linked case %s as test_id for %s', firstTestLink.test, t.title);
|
|
732
|
+
}
|
|
655
733
|
}
|
|
656
734
|
}
|
|
657
735
|
/**
|
|
@@ -735,7 +813,8 @@ class AllureReader {
|
|
|
735
813
|
await this.uploadArtifacts();
|
|
736
814
|
this.calculateStats();
|
|
737
815
|
this.fetchSourceCode();
|
|
738
|
-
this.
|
|
816
|
+
this.recoverTmsLinksFromSource();
|
|
817
|
+
this.applyPrimaryTestIdFromLinks();
|
|
739
818
|
this.pipes = this.pipes || (await this.pipesPromise);
|
|
740
819
|
const finishData = {
|
|
741
820
|
api_key: this.requestParams.apiKey,
|
package/lib/bin/cli.js
CHANGED
|
@@ -326,7 +326,7 @@ program
|
|
|
326
326
|
.option('-d, --dir <dir>', 'Project directory')
|
|
327
327
|
.option('--timelimit <time>', 'default time limit in seconds to kill a stuck process')
|
|
328
328
|
.option('--with-package', 'Keep full package path in file names (default: strip package prefix)')
|
|
329
|
-
.option('--java-tests [path]', 'Path to test sources;
|
|
329
|
+
.option('--java-tests [path]', 'Path to test sources; links cases from @TmsLink in source for skipped tests (default: src/test)')
|
|
330
330
|
.option('--lang <lang>', 'Language used (java, kotlin, ...)')
|
|
331
331
|
.action(async (pattern, opts) => {
|
|
332
332
|
let javaTests = opts.javaTests;
|
package/package.json
CHANGED
package/src/allureReader.js
CHANGED
|
@@ -193,12 +193,12 @@ class AllureReader {
|
|
|
193
193
|
overwrite: true,
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
196
|
+
// @TmsLink references link the result to existing Testomat.io cases. Add EVERY id as
|
|
197
|
+
// a linked case ({ test: id }) so all of them are updated from this one result, with
|
|
198
|
+
// consistent behaviour whether the test has one or many @TmsLink. The test_id is kept
|
|
199
|
+
// a SEPARATE concern — it is never derived from @TmsLink; it is only set from a native
|
|
200
|
+
// Testomat.io id found in source (see fetchSourceCode / fetchIdFromCode).
|
|
201
|
+
this.addLinkedTestIds(test, this.extractTmsIds(result));
|
|
202
202
|
|
|
203
203
|
// Add description if present
|
|
204
204
|
if (result.description) {
|
|
@@ -377,34 +377,67 @@ class AllureReader {
|
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
/**
|
|
380
|
-
* Extract
|
|
380
|
+
* Extract all Testomat.io test ids from Allure links so reported results match
|
|
381
381
|
* existing cases instead of creating duplicates.
|
|
382
382
|
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
* accepted. The link `name` is used as
|
|
383
|
+
* A test may carry several `@TmsLink`s (e.g. `@TmsLinks(@TmsLink("…"), @TmsLink("…"))`),
|
|
384
|
+
* each producing a link with `type: "tms"`. Some exporters omit the type but still point
|
|
385
|
+
* the link URL at a Testomat.io test page; both are accepted. The link `name` is used as
|
|
386
|
+
* the id (falling back to the id segment of a Testomat.io URL). Ids are normalized and
|
|
387
|
+
* de-duplicated, preserving order so the first one stays the primary `test_id`.
|
|
386
388
|
*
|
|
387
389
|
* @param {object} result - Parsed Allure result JSON
|
|
388
|
-
* @returns {string
|
|
390
|
+
* @returns {string[]} Normalized test ids (possibly empty)
|
|
389
391
|
*/
|
|
390
|
-
|
|
392
|
+
extractTmsIds(result) {
|
|
391
393
|
const links = result.links || [];
|
|
392
|
-
if (!links.length) return
|
|
394
|
+
if (!links.length) return [];
|
|
393
395
|
|
|
394
396
|
const isTmsLink = l => typeof l?.type === 'string' && l.type.toLowerCase() === 'tms';
|
|
395
397
|
const isTestomatioLink = l => typeof l?.url === 'string' && /testomat\.io\/[^\s]*\/test\//i.test(l.url);
|
|
396
398
|
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
+
const ids = [];
|
|
400
|
+
for (const link of links) {
|
|
401
|
+
if (!isTmsLink(link) && !isTestomatioLink(link)) continue;
|
|
399
402
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
403
|
+
// Prefer the explicit link name; fall back to the id segment of a Testomat.io URL.
|
|
404
|
+
let id = this.normalizeTestId(link.name);
|
|
405
|
+
if (!id && typeof link.url === 'string') {
|
|
406
|
+
const fromUrl = link.url.match(/\/test\/([\w\d]{8})(?=$|[/?#])/i);
|
|
407
|
+
if (fromUrl) id = fromUrl[1];
|
|
408
|
+
}
|
|
409
|
+
if (id && !ids.includes(id)) ids.push(id);
|
|
405
410
|
}
|
|
406
411
|
|
|
407
|
-
return
|
|
412
|
+
return ids;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* The primary Testomat.io test id (the first `@TmsLink`), or null when there is none.
|
|
417
|
+
*
|
|
418
|
+
* @param {object} result - Parsed Allure result JSON
|
|
419
|
+
* @returns {string|null}
|
|
420
|
+
*/
|
|
421
|
+
extractTestId(result) {
|
|
422
|
+
return this.extractTmsIds(result)[0] || null;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Attach additional linked test cases to a reported test as `{ test: id }` link entries
|
|
427
|
+
* (the same shape `linkTest()` uses), so a single result updates every case it is linked
|
|
428
|
+
* to — not just the primary `test_id`. Existing links are preserved; duplicates skipped.
|
|
429
|
+
*
|
|
430
|
+
* @param {object} test - converted test
|
|
431
|
+
* @param {string[]} ids - additional test ids to link
|
|
432
|
+
*/
|
|
433
|
+
addLinkedTestIds(test, ids) {
|
|
434
|
+
if (!ids || !ids.length) return;
|
|
435
|
+
if (!Array.isArray(test.links)) test.links = [];
|
|
436
|
+
for (const id of ids) {
|
|
437
|
+
if (!test.links.some(l => l && l.test === id)) {
|
|
438
|
+
test.links.push({ test: id });
|
|
439
|
+
}
|
|
440
|
+
}
|
|
408
441
|
}
|
|
409
442
|
|
|
410
443
|
/**
|
|
@@ -436,21 +469,22 @@ class AllureReader {
|
|
|
436
469
|
* the server create a duplicate case. The id still lives in the source, on the test
|
|
437
470
|
* method, so we read it from there as a fallback.
|
|
438
471
|
*
|
|
439
|
-
* The lookup is method-scoped: we locate the test method declaration by name,
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
472
|
+
* The lookup is method-scoped: we locate the test method declaration by name, collect
|
|
473
|
+
* its annotation/comment block (the lines directly above it, up to the previous code
|
|
474
|
+
* construct) and read every `@TmsLink` from it — so an unrelated method's annotation can
|
|
475
|
+
* never be picked up. Both `@TmsLink("…")` and the container forms
|
|
476
|
+
* `@TmsLinks(@TmsLink("…"), @TmsLink("…"))` (single- or multi-line) are supported.
|
|
443
477
|
*
|
|
444
478
|
* @param {string} contents - full source file
|
|
445
479
|
* @param {object} test - converted test (uses `title`)
|
|
446
|
-
* @returns {string
|
|
480
|
+
* @returns {string[]} normalized 8-char ids in source order (possibly empty)
|
|
447
481
|
*/
|
|
448
|
-
|
|
449
|
-
if (!contents || !test || !test.title) return
|
|
482
|
+
extractTmsIdsFromSource(contents, test) {
|
|
483
|
+
if (!contents || !test || !test.title) return [];
|
|
450
484
|
|
|
451
485
|
const lines = contents.split('\n');
|
|
452
486
|
const title = test.title.replace(/[([].*$/, '').trim();
|
|
453
|
-
if (!title) return
|
|
487
|
+
if (!title) return [];
|
|
454
488
|
const escaped = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
455
489
|
|
|
456
490
|
// Locate the test method declaration (Kotlin `fun name(`, then a typed declaration,
|
|
@@ -458,21 +492,43 @@ class AllureReader {
|
|
|
458
492
|
let idx = lines.findIndex(l => new RegExp(`\\bfun\\s+${escaped}\\s*\\(`).test(l));
|
|
459
493
|
if (idx === -1) idx = lines.findIndex(l => new RegExp(`\\b[\\w.<>\\[\\]]+\\s+${escaped}\\s*\\(`).test(l));
|
|
460
494
|
if (idx === -1) idx = lines.findIndex(l => new RegExp(`\\b${escaped}\\s*\\(`).test(l));
|
|
461
|
-
if (idx === -1) return
|
|
495
|
+
if (idx === -1) return [];
|
|
462
496
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
-
|
|
497
|
+
// Collect the annotation/comment block above the declaration. Stop at the previous
|
|
498
|
+
// code construct (a line ending in `{`/`}` or another method declaration) so we never
|
|
499
|
+
// read into a sibling method. Multi-line `@TmsLinks(...)` continuation lines (e.g. a
|
|
500
|
+
// lone `@TmsLink("…"),` or a closing `)`) are kept because they aren't boundaries.
|
|
501
|
+
const block = [];
|
|
502
|
+
for (let i = idx - 1, scanned = 0; i >= 0 && scanned < 60; i--, scanned++) {
|
|
503
|
+
const trimmed = lines[i].trim();
|
|
504
|
+
if (trimmed.endsWith('{') || trimmed.endsWith('}')) break;
|
|
505
|
+
if (/\bfun\s+\w+\s*\(/.test(trimmed)) break;
|
|
506
|
+
block.push(lines[i]);
|
|
473
507
|
}
|
|
474
508
|
|
|
475
|
-
|
|
509
|
+
const ids = [];
|
|
510
|
+
const tmsRe = /\bTmsLink\s*\(\s*["']([^"']+)["']/g;
|
|
511
|
+
let match;
|
|
512
|
+
// block was collected bottom-up; reverse so ids come out in source order
|
|
513
|
+
const text = block.reverse().join('\n');
|
|
514
|
+
while ((match = tmsRe.exec(text)) !== null) {
|
|
515
|
+
const id = this.normalizeTestId(match[1]);
|
|
516
|
+
if (id && !ids.includes(id)) ids.push(id);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return ids;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* The primary `@TmsLink` id for a test method in source, or null. Convenience wrapper
|
|
524
|
+
* around {@link extractTmsIdsFromSource}.
|
|
525
|
+
*
|
|
526
|
+
* @param {string} contents - full source file
|
|
527
|
+
* @param {object} test - converted test (uses `title`)
|
|
528
|
+
* @returns {string|null}
|
|
529
|
+
*/
|
|
530
|
+
extractTmsIdFromSource(contents, test) {
|
|
531
|
+
return this.extractTmsIdsFromSource(contents, test)[0] || null;
|
|
476
532
|
}
|
|
477
533
|
|
|
478
534
|
convertSteps(steps, depth = 0) {
|
|
@@ -684,20 +740,23 @@ class AllureReader {
|
|
|
684
740
|
}
|
|
685
741
|
|
|
686
742
|
/**
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
* Allure results drop the `@TmsLink` link and would otherwise create duplicate
|
|
743
|
+
* Link tests to their Testomat.io cases by reading `@TmsLink` from source for tests that
|
|
744
|
+
* carry no `{ test: … }` link yet. This rescues skipped (`@Ignore` / `@Disabled`) tests,
|
|
745
|
+
* whose Allure results drop the `@TmsLink` link and would otherwise create duplicate
|
|
746
|
+
* cases. Every `@TmsLink` on the method is linked (consistent with executed tests); the
|
|
747
|
+
* `test_id` is left untouched — links and test_id are separate concerns.
|
|
690
748
|
*
|
|
691
|
-
* Opt-in: only runs when `--java-tests` (a source root) is provided. The source
|
|
692
|
-
*
|
|
693
|
-
*
|
|
749
|
+
* Opt-in: only runs when `--java-tests` (a source root) is provided. The source files are
|
|
750
|
+
* indexed once by basename; for each not-yet-linked test we read the candidate file(s)
|
|
751
|
+
* matching its `testFile` / class name and parse the method's `@TmsLink`(s).
|
|
694
752
|
*/
|
|
695
|
-
|
|
753
|
+
recoverTmsLinksFromSource() {
|
|
696
754
|
const root = this.opts.javaTests;
|
|
697
755
|
if (!root) return;
|
|
698
756
|
|
|
699
|
-
const
|
|
700
|
-
|
|
757
|
+
const hasTestLink = t => Array.isArray(t.links) && t.links.some(l => l && l.test);
|
|
758
|
+
const unlinked = this._tests.filter(t => !hasTestLink(t));
|
|
759
|
+
if (!unlinked.length) return;
|
|
701
760
|
|
|
702
761
|
if (!fs.existsSync(root)) {
|
|
703
762
|
debug('java-tests source root not found: %s', root);
|
|
@@ -707,7 +766,7 @@ class AllureReader {
|
|
|
707
766
|
const index = this.indexSourceFiles(root);
|
|
708
767
|
let recovered = 0;
|
|
709
768
|
|
|
710
|
-
for (const t of
|
|
769
|
+
for (const t of unlinked) {
|
|
711
770
|
for (const filePath of this.sourceCandidatesForTest(t, index)) {
|
|
712
771
|
let contents;
|
|
713
772
|
try {
|
|
@@ -716,18 +775,37 @@ class AllureReader {
|
|
|
716
775
|
debug('Failed to read source %s: %s', filePath, err.message);
|
|
717
776
|
continue;
|
|
718
777
|
}
|
|
719
|
-
const
|
|
720
|
-
if (
|
|
721
|
-
t
|
|
778
|
+
const ids = this.extractTmsIdsFromSource(contents, t);
|
|
779
|
+
if (ids.length) {
|
|
780
|
+
this.addLinkedTestIds(t, ids);
|
|
722
781
|
recovered++;
|
|
723
|
-
debug('
|
|
782
|
+
debug('Linked %s to case(s) %s from @TmsLink in %s', t.title, ids.join(', '), filePath);
|
|
724
783
|
break;
|
|
725
784
|
}
|
|
726
785
|
}
|
|
727
786
|
}
|
|
728
787
|
|
|
729
788
|
if (recovered) {
|
|
730
|
-
console.log(APP_PREFIX, `🔗
|
|
789
|
+
console.log(APP_PREFIX, `🔗 Linked ${pc.bold(recovered)} test(s) to cases from @TmsLink in source`);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Fallback: when a test has no `test_id`, adopt the first linked case (`@TmsLink`) as its
|
|
795
|
+
* `test_id` so it matches an existing case instead of creating a method-named duplicate.
|
|
796
|
+
*
|
|
797
|
+
* Runs after `fetchSourceCode`, so a native Testomat.io id parsed from source always wins.
|
|
798
|
+
* The id stays in `links` as well — every linked case is still updated; this only gives the
|
|
799
|
+
* test a primary identity to match on.
|
|
800
|
+
*/
|
|
801
|
+
applyPrimaryTestIdFromLinks() {
|
|
802
|
+
for (const t of this._tests) {
|
|
803
|
+
if (t.test_id) continue;
|
|
804
|
+
const firstTestLink = Array.isArray(t.links) ? t.links.find(l => l && l.test) : null;
|
|
805
|
+
if (firstTestLink) {
|
|
806
|
+
t.test_id = firstTestLink.test;
|
|
807
|
+
debug('Using first linked case %s as test_id for %s', firstTestLink.test, t.title);
|
|
808
|
+
}
|
|
731
809
|
}
|
|
732
810
|
}
|
|
733
811
|
|
|
@@ -816,7 +894,8 @@ class AllureReader {
|
|
|
816
894
|
await this.uploadArtifacts();
|
|
817
895
|
this.calculateStats();
|
|
818
896
|
this.fetchSourceCode();
|
|
819
|
-
this.
|
|
897
|
+
this.recoverTmsLinksFromSource();
|
|
898
|
+
this.applyPrimaryTestIdFromLinks();
|
|
820
899
|
|
|
821
900
|
this.pipes = this.pipes || (await this.pipesPromise);
|
|
822
901
|
|
package/src/bin/cli.js
CHANGED
|
@@ -361,7 +361,7 @@ program
|
|
|
361
361
|
.option('--with-package', 'Keep full package path in file names (default: strip package prefix)')
|
|
362
362
|
.option(
|
|
363
363
|
'--java-tests [path]',
|
|
364
|
-
'Path to test sources;
|
|
364
|
+
'Path to test sources; links cases from @TmsLink in source for skipped tests (default: src/test)',
|
|
365
365
|
)
|
|
366
366
|
.option('--lang <lang>', 'Language used (java, kotlin, ...)')
|
|
367
367
|
.action(async (pattern, opts) => {
|