testit-js-commons 5.0.1 → 5.0.2-TMS-5.8
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/common/types/config.type.d.ts +11 -0
- package/lib/helpers/config/config.helper.d.ts +3 -0
- package/lib/helpers/config/config.helper.js +38 -2
- package/lib/helpers/config/test-run-metadata.util.d.ts +10 -0
- package/lib/helpers/config/test-run-metadata.util.js +122 -0
- package/lib/helpers/config/test-run-metadata.util.test.d.ts +1 -0
- package/lib/helpers/config/test-run-metadata.util.test.js +78 -0
- package/lib/services/testruns/testruns.converter.d.ts +2 -1
- package/lib/services/testruns/testruns.converter.js +2 -0
- package/lib/services/testruns/testruns.service.js +31 -1
- package/lib/services/testruns/testruns.type.d.ts +2 -0
- package/lib/strategy/base.strategy.js +49 -6
- package/lib/strategy/first.strategy.js +0 -1
- package/lib/strategy/zero.strategy.js +0 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Link } from "./common.type";
|
|
1
2
|
export type AdapterMode = 0 | 1 | 2;
|
|
2
3
|
export interface CliOptions {
|
|
3
4
|
tmsUrl: string;
|
|
@@ -13,6 +14,8 @@ export interface CliOptions {
|
|
|
13
14
|
tmsSyncStorageEnabled: boolean;
|
|
14
15
|
tmsSyncStoragePort: string;
|
|
15
16
|
tmsImportRealtime: boolean;
|
|
17
|
+
tmsTestRunTags: string;
|
|
18
|
+
tmsTestRunLinks: string;
|
|
16
19
|
}
|
|
17
20
|
export interface EnvironmentOptions {
|
|
18
21
|
TMS_URL: string;
|
|
@@ -29,6 +32,8 @@ export interface EnvironmentOptions {
|
|
|
29
32
|
TMS_SYNC_STORAGE_ENABLED: string;
|
|
30
33
|
TMS_SYNC_STORAGE_PORT: string;
|
|
31
34
|
TMS_IMPORT_REALTIME: string;
|
|
35
|
+
TMS_TEST_RUN_TAGS: string;
|
|
36
|
+
TMS_TEST_RUN_LINKS: string;
|
|
32
37
|
}
|
|
33
38
|
export interface ProcessEnvOptions {
|
|
34
39
|
TMS_URL?: string;
|
|
@@ -45,6 +50,8 @@ export interface ProcessEnvOptions {
|
|
|
45
50
|
TMS_SYNC_STORAGE_ENABLED?: string;
|
|
46
51
|
TMS_SYNC_STORAGE_PORT?: string;
|
|
47
52
|
TMS_IMPORT_REALTIME?: string;
|
|
53
|
+
TMS_TEST_RUN_TAGS?: string;
|
|
54
|
+
TMS_TEST_RUN_LINKS?: string;
|
|
48
55
|
}
|
|
49
56
|
export interface AdapterConfig {
|
|
50
57
|
url: string;
|
|
@@ -60,4 +67,8 @@ export interface AdapterConfig {
|
|
|
60
67
|
syncStorageEnabled?: boolean;
|
|
61
68
|
syncStoragePort?: string;
|
|
62
69
|
importRealtime?: boolean;
|
|
70
|
+
/** Test run tags (not autotest tags). */
|
|
71
|
+
testRunTags?: string[];
|
|
72
|
+
/** Test run links (e.g. CI job URL). */
|
|
73
|
+
testRunLinks?: Link[];
|
|
63
74
|
}
|
|
@@ -6,7 +6,10 @@ export declare class ConfigComposer implements IConfigComposer {
|
|
|
6
6
|
mergeAll(file: AdapterConfig, env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
|
|
7
7
|
merge(env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
|
|
8
8
|
mergeEnv(dotEnv?: Partial<EnvironmentOptions>, processEnv?: Partial<EnvironmentOptions>): Partial<EnvironmentOptions>;
|
|
9
|
+
private resolveTestRunTags;
|
|
10
|
+
private resolveTestRunLinks;
|
|
9
11
|
private resolveAllProperties;
|
|
10
12
|
private resolveProperties;
|
|
11
13
|
private validateConfig;
|
|
12
14
|
}
|
|
15
|
+
export { parseTestRunTags, parseTestRunLinks, mergeTagLists, mergeLinkLists } from "./test-run-metadata.util";
|
|
@@ -36,14 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ConfigComposer = exports.DEFAULT_CONFIG_FILE = void 0;
|
|
39
|
+
exports.mergeLinkLists = exports.mergeTagLists = exports.parseTestRunLinks = exports.parseTestRunTags = exports.ConfigComposer = exports.DEFAULT_CONFIG_FILE = void 0;
|
|
40
40
|
const dotenv = __importStar(require("dotenv"));
|
|
41
41
|
const common_1 = require("../../common");
|
|
42
|
+
const test_run_metadata_util_1 = require("./test-run-metadata.util");
|
|
42
43
|
const logger_1 = __importDefault(require("../../logger"));
|
|
43
44
|
exports.DEFAULT_CONFIG_FILE = "tms.config.json";
|
|
44
45
|
class ConfigComposer {
|
|
45
46
|
compose(base) {
|
|
46
|
-
var _a, _b;
|
|
47
|
+
var _a, _b, _c, _d, _e, _f;
|
|
47
48
|
const processEnvironment = parseProcessEnvConfig();
|
|
48
49
|
const dotEnvironment = parseDotEnvConfig();
|
|
49
50
|
const environment = this.mergeEnv(dotEnvironment, processEnvironment);
|
|
@@ -68,6 +69,8 @@ class ConfigComposer {
|
|
|
68
69
|
syncStorageEnabled: config.syncStorageEnabled,
|
|
69
70
|
hasTestRunId: Boolean(config.testRunId),
|
|
70
71
|
projectId: config.projectId,
|
|
72
|
+
testRunTags: (_d = (_c = config.testRunTags) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0,
|
|
73
|
+
testRunLinks: (_f = (_e = config.testRunLinks) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0,
|
|
71
74
|
});
|
|
72
75
|
return config;
|
|
73
76
|
}
|
|
@@ -87,6 +90,8 @@ class ConfigComposer {
|
|
|
87
90
|
syncStorageEnabled: (_q = (_p = (_o = file.syncStorageEnabled) !== null && _o !== void 0 ? _o : stringToBoolean(env === null || env === void 0 ? void 0 : env.TMS_SYNC_STORAGE_ENABLED)) !== null && _p !== void 0 ? _p : base === null || base === void 0 ? void 0 : base.syncStorageEnabled) !== null && _q !== void 0 ? _q : true,
|
|
88
91
|
syncStoragePort: this.resolveAllProperties(file.syncStoragePort, env === null || env === void 0 ? void 0 : env.TMS_SYNC_STORAGE_PORT, base === null || base === void 0 ? void 0 : base.syncStoragePort) || "49152",
|
|
89
92
|
importRealtime: (_t = (_s = (_r = file.importRealtime) !== null && _r !== void 0 ? _r : stringToBoolean(env === null || env === void 0 ? void 0 : env.TMS_IMPORT_REALTIME)) !== null && _s !== void 0 ? _s : base === null || base === void 0 ? void 0 : base.importRealtime) !== null && _t !== void 0 ? _t : false,
|
|
93
|
+
testRunTags: this.resolveTestRunTags(file.testRunTags, env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_TAGS, base === null || base === void 0 ? void 0 : base.testRunTags),
|
|
94
|
+
testRunLinks: this.resolveTestRunLinks(file.testRunLinks, env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_LINKS, base === null || base === void 0 ? void 0 : base.testRunLinks),
|
|
90
95
|
};
|
|
91
96
|
}
|
|
92
97
|
merge(env, base) {
|
|
@@ -105,6 +110,8 @@ class ConfigComposer {
|
|
|
105
110
|
syncStorageEnabled: (_k = (_j = stringToBoolean(env === null || env === void 0 ? void 0 : env.TMS_SYNC_STORAGE_ENABLED)) !== null && _j !== void 0 ? _j : base === null || base === void 0 ? void 0 : base.syncStorageEnabled) !== null && _k !== void 0 ? _k : true,
|
|
106
111
|
syncStoragePort: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_SYNC_STORAGE_PORT, base === null || base === void 0 ? void 0 : base.syncStoragePort) || "49152",
|
|
107
112
|
importRealtime: (_m = (_l = stringToBoolean(env === null || env === void 0 ? void 0 : env.TMS_IMPORT_REALTIME)) !== null && _l !== void 0 ? _l : base === null || base === void 0 ? void 0 : base.importRealtime) !== null && _m !== void 0 ? _m : false,
|
|
113
|
+
testRunTags: this.resolveTestRunTags(undefined, env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_TAGS, base === null || base === void 0 ? void 0 : base.testRunTags),
|
|
114
|
+
testRunLinks: this.resolveTestRunLinks(undefined, env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_LINKS, base === null || base === void 0 ? void 0 : base.testRunLinks),
|
|
108
115
|
};
|
|
109
116
|
}
|
|
110
117
|
mergeEnv(dotEnv, processEnv) {
|
|
@@ -123,8 +130,30 @@ class ConfigComposer {
|
|
|
123
130
|
TMS_SYNC_STORAGE_ENABLED: (_e = dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_SYNC_STORAGE_ENABLED) !== null && _e !== void 0 ? _e : processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_SYNC_STORAGE_ENABLED,
|
|
124
131
|
TMS_SYNC_STORAGE_PORT: this.resolveProperties(dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_SYNC_STORAGE_PORT, processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_SYNC_STORAGE_PORT),
|
|
125
132
|
TMS_IMPORT_REALTIME: (_f = dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_IMPORT_REALTIME) !== null && _f !== void 0 ? _f : processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_IMPORT_REALTIME,
|
|
133
|
+
TMS_TEST_RUN_TAGS: this.resolveProperties(dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_TEST_RUN_TAGS, processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_TEST_RUN_TAGS),
|
|
134
|
+
TMS_TEST_RUN_LINKS: this.resolveProperties(dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_TEST_RUN_LINKS, processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_TEST_RUN_LINKS),
|
|
126
135
|
};
|
|
127
136
|
}
|
|
137
|
+
resolveTestRunTags(file, env, base) {
|
|
138
|
+
if (base === null || base === void 0 ? void 0 : base.length) {
|
|
139
|
+
return base;
|
|
140
|
+
}
|
|
141
|
+
const fromEnv = (0, test_run_metadata_util_1.parseTestRunTags)(env);
|
|
142
|
+
if (fromEnv === null || fromEnv === void 0 ? void 0 : fromEnv.length) {
|
|
143
|
+
return fromEnv;
|
|
144
|
+
}
|
|
145
|
+
return (0, test_run_metadata_util_1.parseTestRunTags)(file);
|
|
146
|
+
}
|
|
147
|
+
resolveTestRunLinks(file, env, base) {
|
|
148
|
+
if (base === null || base === void 0 ? void 0 : base.length) {
|
|
149
|
+
return base;
|
|
150
|
+
}
|
|
151
|
+
const fromEnv = (0, test_run_metadata_util_1.parseTestRunLinks)(env);
|
|
152
|
+
if (fromEnv === null || fromEnv === void 0 ? void 0 : fromEnv.length) {
|
|
153
|
+
return fromEnv;
|
|
154
|
+
}
|
|
155
|
+
return (0, test_run_metadata_util_1.parseTestRunLinks)(file);
|
|
156
|
+
}
|
|
128
157
|
resolveAllProperties(file, env, base) {
|
|
129
158
|
if (base && base.trim()) {
|
|
130
159
|
return base;
|
|
@@ -204,6 +233,8 @@ function parseProcessEnvConfig() {
|
|
|
204
233
|
TMS_SYNC_STORAGE_ENABLED: process.env.TMS_SYNC_STORAGE_ENABLED,
|
|
205
234
|
TMS_SYNC_STORAGE_PORT: process.env.TMS_SYNC_STORAGE_PORT,
|
|
206
235
|
TMS_IMPORT_REALTIME: process.env.TMS_IMPORT_REALTIME,
|
|
236
|
+
TMS_TEST_RUN_TAGS: process.env.TMS_TEST_RUN_TAGS,
|
|
237
|
+
TMS_TEST_RUN_LINKS: process.env.TMS_TEST_RUN_LINKS,
|
|
207
238
|
};
|
|
208
239
|
}
|
|
209
240
|
function stringToAdapterMode(str) {
|
|
@@ -228,3 +259,8 @@ function stringToBoolean(str) {
|
|
|
228
259
|
return undefined;
|
|
229
260
|
}
|
|
230
261
|
}
|
|
262
|
+
var test_run_metadata_util_2 = require("./test-run-metadata.util");
|
|
263
|
+
Object.defineProperty(exports, "parseTestRunTags", { enumerable: true, get: function () { return test_run_metadata_util_2.parseTestRunTags; } });
|
|
264
|
+
Object.defineProperty(exports, "parseTestRunLinks", { enumerable: true, get: function () { return test_run_metadata_util_2.parseTestRunLinks; } });
|
|
265
|
+
Object.defineProperty(exports, "mergeTagLists", { enumerable: true, get: function () { return test_run_metadata_util_2.mergeTagLists; } });
|
|
266
|
+
Object.defineProperty(exports, "mergeLinkLists", { enumerable: true, get: function () { return test_run_metadata_util_2.mergeLinkLists; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Link } from "../../common";
|
|
2
|
+
/** Parse CSV or JSON array of tag strings. Empty / invalid → undefined. */
|
|
3
|
+
export declare function parseTestRunTags(raw?: string | string[] | null): string[] | undefined;
|
|
4
|
+
/** Parse JSON array of link objects. Empty / invalid → undefined. */
|
|
5
|
+
export declare function parseTestRunLinks(raw?: string | Link[] | null): Link[] | undefined;
|
|
6
|
+
export declare function mergeTagLists(existing: string[] | undefined, incoming: string[] | undefined): string[];
|
|
7
|
+
/** Merge by url (case-sensitive); keep existing link when URL already present. */
|
|
8
|
+
export declare function mergeLinkLists<T extends {
|
|
9
|
+
url: string;
|
|
10
|
+
}>(existing: T[] | undefined, incoming: T[] | undefined): T[];
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
exports.parseTestRunTags = parseTestRunTags;
|
|
7
|
+
exports.parseTestRunLinks = parseTestRunLinks;
|
|
8
|
+
exports.mergeTagLists = mergeTagLists;
|
|
9
|
+
exports.mergeLinkLists = mergeLinkLists;
|
|
10
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
11
|
+
const LINK_TYPES = new Set([
|
|
12
|
+
"Related",
|
|
13
|
+
"BlockedBy",
|
|
14
|
+
"Defect",
|
|
15
|
+
"Issue",
|
|
16
|
+
"Requirement",
|
|
17
|
+
"Repository",
|
|
18
|
+
]);
|
|
19
|
+
/** Parse CSV or JSON array of tag strings. Empty / invalid → undefined. */
|
|
20
|
+
function parseTestRunTags(raw) {
|
|
21
|
+
if (raw == null) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(raw)) {
|
|
25
|
+
const tags = raw.map((t) => String(t).trim()).filter(Boolean);
|
|
26
|
+
return tags.length ? tags : undefined;
|
|
27
|
+
}
|
|
28
|
+
const text = String(raw).trim();
|
|
29
|
+
if (!text) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (text.startsWith("[")) {
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(text);
|
|
35
|
+
if (!Array.isArray(parsed)) {
|
|
36
|
+
logger_1.default.warn("[config] TMS_TEST_RUN_TAGS JSON must be an array of strings");
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const tags = parsed.map((t) => String(t).trim()).filter(Boolean);
|
|
40
|
+
return tags.length ? tags : undefined;
|
|
41
|
+
}
|
|
42
|
+
catch (_a) {
|
|
43
|
+
logger_1.default.warn("[config] TMS_TEST_RUN_TAGS is invalid JSON");
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const tags = text.split(",").map((t) => t.trim()).filter(Boolean);
|
|
48
|
+
return tags.length ? tags : undefined;
|
|
49
|
+
}
|
|
50
|
+
/** Parse JSON array of link objects. Empty / invalid → undefined. */
|
|
51
|
+
function parseTestRunLinks(raw) {
|
|
52
|
+
if (raw == null) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(raw)) {
|
|
56
|
+
return normalizeLinks(raw);
|
|
57
|
+
}
|
|
58
|
+
const text = String(raw).trim();
|
|
59
|
+
if (!text) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const parsed = JSON.parse(text);
|
|
64
|
+
if (!Array.isArray(parsed)) {
|
|
65
|
+
logger_1.default.warn("[config] TMS_TEST_RUN_LINKS JSON must be an array");
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
return normalizeLinks(parsed);
|
|
69
|
+
}
|
|
70
|
+
catch (_a) {
|
|
71
|
+
logger_1.default.warn("[config] TMS_TEST_RUN_LINKS is invalid JSON");
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function normalizeLinks(items) {
|
|
76
|
+
const links = [];
|
|
77
|
+
for (const item of items) {
|
|
78
|
+
if (!item || typeof item !== "object") {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const obj = item;
|
|
82
|
+
const url = typeof obj.url === "string" ? obj.url.trim() : "";
|
|
83
|
+
if (!url) {
|
|
84
|
+
logger_1.default.warn("[config] test run link skipped: empty url");
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const typeRaw = typeof obj.type === "string" ? obj.type : undefined;
|
|
88
|
+
const type = typeRaw && LINK_TYPES.has(typeRaw) ? typeRaw : "Related";
|
|
89
|
+
links.push({
|
|
90
|
+
url,
|
|
91
|
+
title: typeof obj.title === "string" && obj.title.trim() ? obj.title.trim() : url,
|
|
92
|
+
description: typeof obj.description === "string" ? obj.description : undefined,
|
|
93
|
+
type,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return links.length ? links : undefined;
|
|
97
|
+
}
|
|
98
|
+
function mergeTagLists(existing, incoming) {
|
|
99
|
+
const result = [];
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
for (const tag of [...(existing !== null && existing !== void 0 ? existing : []), ...(incoming !== null && incoming !== void 0 ? incoming : [])]) {
|
|
102
|
+
if (!tag || seen.has(tag)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
seen.add(tag);
|
|
106
|
+
result.push(tag);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/** Merge by url (case-sensitive); keep existing link when URL already present. */
|
|
111
|
+
function mergeLinkLists(existing, incoming) {
|
|
112
|
+
const result = [...(existing !== null && existing !== void 0 ? existing : [])];
|
|
113
|
+
const seen = new Set(result.map((l) => l.url));
|
|
114
|
+
for (const link of incoming !== null && incoming !== void 0 ? incoming : []) {
|
|
115
|
+
if (!(link === null || link === void 0 ? void 0 : link.url) || seen.has(link.url)) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
seen.add(link.url);
|
|
119
|
+
result.push(link);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_run_metadata_util_1 = require("./test-run-metadata.util");
|
|
4
|
+
const config_helper_1 = require("./config.helper");
|
|
5
|
+
describe("parseTestRunTags", () => {
|
|
6
|
+
it("parses comma-separated tags", () => {
|
|
7
|
+
expect((0, test_run_metadata_util_1.parseTestRunTags)("smoke, nightly")).toEqual(["smoke", "nightly"]);
|
|
8
|
+
});
|
|
9
|
+
it("parses JSON array tags", () => {
|
|
10
|
+
expect((0, test_run_metadata_util_1.parseTestRunTags)('["smoke","nightly"]')).toEqual(["smoke", "nightly"]);
|
|
11
|
+
});
|
|
12
|
+
it("returns undefined for empty / invalid", () => {
|
|
13
|
+
expect((0, test_run_metadata_util_1.parseTestRunTags)("")).toBeUndefined();
|
|
14
|
+
expect((0, test_run_metadata_util_1.parseTestRunTags)(" ")).toBeUndefined();
|
|
15
|
+
expect((0, test_run_metadata_util_1.parseTestRunTags)("[not-json]")).toBeUndefined();
|
|
16
|
+
expect((0, test_run_metadata_util_1.parseTestRunTags)('{"a":1}')).toEqual(['{"a":1}']);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe("parseTestRunLinks", () => {
|
|
20
|
+
it("parses JSON links and defaults type/title", () => {
|
|
21
|
+
expect((0, test_run_metadata_util_1.parseTestRunLinks)('[{"url":"https://ci.example/job/1","title":"CI Job","type":"Related"}]')).toEqual([
|
|
22
|
+
{
|
|
23
|
+
url: "https://ci.example/job/1",
|
|
24
|
+
title: "CI Job",
|
|
25
|
+
description: undefined,
|
|
26
|
+
type: "Related",
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
it("skips links without url and invalid JSON", () => {
|
|
31
|
+
expect((0, test_run_metadata_util_1.parseTestRunLinks)('[{"title":"no-url"}]')).toBeUndefined();
|
|
32
|
+
expect((0, test_run_metadata_util_1.parseTestRunLinks)("not-json")).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("mergeTagLists / mergeLinkLists", () => {
|
|
36
|
+
it("merges tags without duplicates", () => {
|
|
37
|
+
expect((0, test_run_metadata_util_1.mergeTagLists)(["smoke"], ["smoke", "nightly"])).toEqual(["smoke", "nightly"]);
|
|
38
|
+
});
|
|
39
|
+
it("merges links by url keeping existing", () => {
|
|
40
|
+
const existing = [{ url: "https://a", title: "A" }];
|
|
41
|
+
const incoming = [
|
|
42
|
+
{ url: "https://a", title: "A-new" },
|
|
43
|
+
{ url: "https://b", title: "B" },
|
|
44
|
+
];
|
|
45
|
+
expect((0, test_run_metadata_util_1.mergeLinkLists)(existing, incoming)).toEqual([
|
|
46
|
+
{ url: "https://a", title: "A" },
|
|
47
|
+
{ url: "https://b", title: "B" },
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe("ConfigComposer test run metadata", () => {
|
|
52
|
+
const base = {
|
|
53
|
+
url: "http://localhost:8080",
|
|
54
|
+
privateToken: "token",
|
|
55
|
+
projectId: "11111111-1111-1111-1111-111111111111",
|
|
56
|
+
configurationId: "22222222-2222-2222-2222-222222222222",
|
|
57
|
+
testRunId: "33333333-3333-3333-3333-333333333333",
|
|
58
|
+
};
|
|
59
|
+
it("reads tags and links from env", () => {
|
|
60
|
+
const config = new config_helper_1.ConfigComposer().merge({
|
|
61
|
+
TMS_TEST_RUN_TAGS: "smoke,nightly",
|
|
62
|
+
TMS_TEST_RUN_LINKS: '[{"url":"https://gitlab.example.com/jobs/1","title":"CI Job","type":"Related"}]',
|
|
63
|
+
}, base);
|
|
64
|
+
expect(config.testRunTags).toEqual(["smoke", "nightly"]);
|
|
65
|
+
expect(config.testRunLinks).toEqual([
|
|
66
|
+
{
|
|
67
|
+
url: "https://gitlab.example.com/jobs/1",
|
|
68
|
+
title: "CI Job",
|
|
69
|
+
description: undefined,
|
|
70
|
+
type: "Related",
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
it("prefers base over env", () => {
|
|
75
|
+
const config = new config_helper_1.ConfigComposer().merge({ TMS_TEST_RUN_TAGS: "from-env" }, Object.assign(Object.assign({}, base), { testRunTags: ["from-base"] }));
|
|
76
|
+
expect(config.testRunTags).toEqual(["from-base"]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BaseConverter, AdapterConfig, Outcome } from "../../common";
|
|
1
|
+
import { BaseConverter, AdapterConfig, Link, Outcome } from "../../common";
|
|
2
2
|
import { AutotestResult, RunState, TestRunGet } from "./testruns.type";
|
|
3
3
|
export interface ITestRunConverter {
|
|
4
4
|
toOriginState(state: RunState): any;
|
|
5
5
|
toLocalState(state: any): RunState;
|
|
6
6
|
toLocalTestRun(testRun: any): TestRunGet;
|
|
7
|
+
toOriginLink(link: Link): any;
|
|
7
8
|
toOriginAutotestResult(autotest: AutotestResult): any;
|
|
8
9
|
toOriginAutotestResultInProgress(autotest: AutotestResult): any;
|
|
9
10
|
toOriginTestResultUpdate(autotest: AutotestResult): any;
|
|
@@ -95,6 +95,7 @@ class TestRunConverter extends common_1.BaseConverter {
|
|
|
95
95
|
launchSource: (_d = testRun.launchSource) !== null && _d !== void 0 ? _d : undefined,
|
|
96
96
|
stateName: this.toLocalState(testRun.stateName),
|
|
97
97
|
attachments: (_e = testRun.attachments) === null || _e === void 0 ? void 0 : _e.map((a) => ({ id: a.id })),
|
|
98
|
+
tags: Array.isArray(testRun.tags) ? testRun.tags.map((t) => String(t)) : undefined,
|
|
98
99
|
links: (_f = testRun.links) === null || _f === void 0 ? void 0 : _f.map((link) => {
|
|
99
100
|
var _a;
|
|
100
101
|
return ({
|
|
@@ -102,6 +103,7 @@ class TestRunConverter extends common_1.BaseConverter {
|
|
|
102
103
|
id: link.id,
|
|
103
104
|
title: link.title,
|
|
104
105
|
description: link.description,
|
|
106
|
+
type: link.type,
|
|
105
107
|
hasInfo: (_a = link.hasInfo) !== null && _a !== void 0 ? _a : true,
|
|
106
108
|
});
|
|
107
109
|
}),
|
|
@@ -33,10 +33,19 @@ class TestRunsService extends common_1.BaseService {
|
|
|
33
33
|
}
|
|
34
34
|
createTestRun() {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
var _a;
|
|
37
|
+
const tags = this.config.testRunTags;
|
|
38
|
+
const links = (_a = this.config.testRunLinks) === null || _a === void 0 ? void 0 : _a.map((link) => this._converter.toOriginLink(link));
|
|
36
39
|
const createRequest = {
|
|
37
40
|
projectId: this.config.projectId,
|
|
38
41
|
name: this.config.testRunName,
|
|
39
42
|
};
|
|
43
|
+
if (tags === null || tags === void 0 ? void 0 : tags.length) {
|
|
44
|
+
createRequest.tags = tags;
|
|
45
|
+
}
|
|
46
|
+
if (links === null || links === void 0 ? void 0 : links.length) {
|
|
47
|
+
createRequest.links = links;
|
|
48
|
+
}
|
|
40
49
|
return yield this._client
|
|
41
50
|
.adaptersTestRunsPost({ createEmptyTestRunApiModel: (0, utils_1.escapeHtmlInObject)(createRequest) })
|
|
42
51
|
// @ts-ignore
|
|
@@ -49,6 +58,9 @@ class TestRunsService extends common_1.BaseService {
|
|
|
49
58
|
throw new Error("API response missing 'id' field: " + JSON.stringify(data));
|
|
50
59
|
}
|
|
51
60
|
this.config.testRunId = data.id;
|
|
61
|
+
logger_1.default.log(`Create test run "${data.id}"` +
|
|
62
|
+
((tags === null || tags === void 0 ? void 0 : tags.length) ? ` tags=[${tags.join(",")}]` : "") +
|
|
63
|
+
((links === null || links === void 0 ? void 0 : links.length) ? ` links=${links.length}` : ""));
|
|
52
64
|
return data.id;
|
|
53
65
|
})
|
|
54
66
|
.catch((err) => {
|
|
@@ -72,8 +84,26 @@ class TestRunsService extends common_1.BaseService {
|
|
|
72
84
|
}
|
|
73
85
|
updateTestRun(testRun) {
|
|
74
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const updateModel = {
|
|
89
|
+
id: testRun.id,
|
|
90
|
+
name: testRun.name,
|
|
91
|
+
description: testRun.description,
|
|
92
|
+
launchSource: testRun.launchSource,
|
|
93
|
+
attachments: (_a = testRun.attachments) === null || _a === void 0 ? void 0 : _a.map((a) => ({ id: a.id })),
|
|
94
|
+
tags: testRun.tags,
|
|
95
|
+
links: (_b = testRun.links) === null || _b === void 0 ? void 0 : _b.map((link) => {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
return this._converter.toOriginLink({
|
|
98
|
+
url: link.url,
|
|
99
|
+
title: (_a = link.title) !== null && _a !== void 0 ? _a : link.url,
|
|
100
|
+
description: (_b = link.description) !== null && _b !== void 0 ? _b : undefined,
|
|
101
|
+
type: link.type,
|
|
102
|
+
});
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
75
105
|
yield this._client
|
|
76
|
-
.adaptersTestRunsPut({ updateEmptyTestRunApiModel:
|
|
106
|
+
.adaptersTestRunsPut({ updateEmptyTestRunApiModel: (0, utils_1.escapeHtmlInObject)(updateModel) })
|
|
77
107
|
// @ts-ignore
|
|
78
108
|
.then((response) => {
|
|
79
109
|
logger_1.default.log("Full response from adaptersTestRunsPut:", response);
|
|
@@ -12,12 +12,14 @@ export interface TestRunGet {
|
|
|
12
12
|
stateName: RunState;
|
|
13
13
|
attachments?: Array<Attachment>;
|
|
14
14
|
links?: Array<LinkGet>;
|
|
15
|
+
tags?: string[];
|
|
15
16
|
}
|
|
16
17
|
export interface LinkGet {
|
|
17
18
|
url: string;
|
|
18
19
|
id?: string | null;
|
|
19
20
|
title?: string | null;
|
|
20
21
|
description?: string | null;
|
|
22
|
+
type?: string | null;
|
|
21
23
|
hasInfo: boolean;
|
|
22
24
|
}
|
|
23
25
|
interface AutotestResultBase {
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.BaseStrategy = void 0;
|
|
16
16
|
const client_1 = require("../client");
|
|
17
17
|
const utils_1 = require("../common/utils");
|
|
18
|
+
const test_run_metadata_util_1 = require("../helpers/config/test-run-metadata.util");
|
|
18
19
|
const syncstorage_1 = require("../services/syncstorage");
|
|
19
20
|
const logger_1 = __importDefault(require("../logger"));
|
|
20
21
|
class BaseStrategy {
|
|
@@ -27,6 +28,7 @@ class BaseStrategy {
|
|
|
27
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
29
|
var _a;
|
|
29
30
|
const testRunId = yield this.testRunId;
|
|
31
|
+
yield this.updateTestRun(this.config);
|
|
30
32
|
yield this.tryStartSyncStorage(testRunId);
|
|
31
33
|
yield ((_a = this.syncStorageRunner) === null || _a === void 0 ? void 0 : _a.setWorkerStatus("in_progress"));
|
|
32
34
|
yield this.client.testRuns.startTestRun(testRunId);
|
|
@@ -169,16 +171,57 @@ class BaseStrategy {
|
|
|
169
171
|
}
|
|
170
172
|
updateTestRun(config) {
|
|
171
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
175
|
+
const testRunId = config.testRunId || (yield this.testRunId);
|
|
176
|
+
if (!testRunId) {
|
|
174
177
|
return;
|
|
175
178
|
}
|
|
176
|
-
const
|
|
177
|
-
|
|
179
|
+
const hasName = config.testRunName != undefined;
|
|
180
|
+
const hasTags = Boolean((_a = config.testRunTags) === null || _a === void 0 ? void 0 : _a.length);
|
|
181
|
+
const hasLinks = Boolean((_b = config.testRunLinks) === null || _b === void 0 ? void 0 : _b.length);
|
|
182
|
+
if (!hasName && !hasTags && !hasLinks) {
|
|
178
183
|
return;
|
|
179
184
|
}
|
|
180
|
-
|
|
181
|
-
|
|
185
|
+
try {
|
|
186
|
+
const testRun = yield this.client.testRuns.getTestRun(testRunId);
|
|
187
|
+
let changed = false;
|
|
188
|
+
if (hasName && config.testRunName !== testRun.name) {
|
|
189
|
+
testRun.name = config.testRunName;
|
|
190
|
+
changed = true;
|
|
191
|
+
}
|
|
192
|
+
if (hasTags) {
|
|
193
|
+
const merged = (0, test_run_metadata_util_1.mergeTagLists)(testRun.tags, config.testRunTags);
|
|
194
|
+
if (merged.length !== ((_d = (_c = testRun.tags) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) || merged.some((t, i) => { var _a; return t !== ((_a = testRun.tags) === null || _a === void 0 ? void 0 : _a[i]); })) {
|
|
195
|
+
testRun.tags = merged;
|
|
196
|
+
changed = true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (hasLinks) {
|
|
200
|
+
const existing = (_e = testRun.links) !== null && _e !== void 0 ? _e : [];
|
|
201
|
+
const incoming = config.testRunLinks.map((link) => ({
|
|
202
|
+
url: link.url,
|
|
203
|
+
title: link.title,
|
|
204
|
+
description: link.description,
|
|
205
|
+
type: link.type,
|
|
206
|
+
hasInfo: true,
|
|
207
|
+
}));
|
|
208
|
+
const merged = (0, test_run_metadata_util_1.mergeLinkLists)(existing, incoming);
|
|
209
|
+
if (merged.length !== existing.length) {
|
|
210
|
+
testRun.links = merged;
|
|
211
|
+
changed = true;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!changed) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
yield this.client.testRuns.updateTestRun(testRun);
|
|
218
|
+
logger_1.default.log(`Updated test run "${testRunId}"` +
|
|
219
|
+
(hasTags ? ` tags=[${((_f = testRun.tags) !== null && _f !== void 0 ? _f : []).join(",")}]` : "") +
|
|
220
|
+
(hasLinks ? ` links=${(_h = (_g = testRun.links) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0}` : ""));
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
logger_1.default.error(`Failed to apply test run tags/links for "${testRunId}"`, err);
|
|
224
|
+
}
|
|
182
225
|
});
|
|
183
226
|
}
|
|
184
227
|
getInProgressFirstGraceMs() {
|
|
@@ -7,7 +7,6 @@ class ZeroStrategy extends base_strategy_1.BaseStrategy {
|
|
|
7
7
|
super(config);
|
|
8
8
|
if (!config.testRunId)
|
|
9
9
|
throw new Error("testRunId is required when mode is 0");
|
|
10
|
-
this.updateTestRun(config);
|
|
11
10
|
this.testsInRun = this.client.testResults.getExternalIdsForRun();
|
|
12
11
|
}
|
|
13
12
|
}
|