testit-js-commons 5.0.4 → 5.0.5-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/adapters-api/dist/ApiClient.js +5 -6
- package/lib/adapters-api/dist/api/AttachmentsApi.js +5 -5
- package/lib/adapters-api/dist/api/AutoTestsApi.js +11 -11
- package/lib/adapters-api/dist/api/ConfigurationsApi.js +1 -1
- package/lib/adapters-api/dist/api/ParametersApi.js +3 -3
- package/lib/adapters-api/dist/api/ProjectAttributesApi.js +6 -6
- package/lib/adapters-api/dist/api/ProjectSectionsApi.js +1 -1
- package/lib/adapters-api/dist/api/ProjectWorkItemsApi.js +1 -1
- package/lib/adapters-api/dist/api/ProjectsApi.js +4 -4
- package/lib/adapters-api/dist/api/SectionsApi.js +2 -2
- package/lib/adapters-api/dist/api/TestResultsApi.js +3 -3
- package/lib/adapters-api/dist/api/TestRunsApi.js +8 -8
- package/lib/adapters-api/dist/api/WorkItemsApi.js +3 -3
- package/lib/adapters-api/dist/api/WorkflowsApi.js +1 -1
- package/lib/adapters-api/dist/index.js +3 -3
- package/lib/adapters-api/dist/model/AttachmentPutModelAutoTestStepResultsModel.js +1 -1
- package/lib/adapters-api/dist/model/AutoTestStepResult.js +1 -1
- package/lib/adapters-api/dist/model/AutoTestStepResultUpdateRequest.js +1 -1
- package/lib/adapters-api/dist/model/CreateEmptyTestRunApiModel.js +2 -2
- package/lib/adapters-api/dist/model/CustomAttributeApiResult.js +2 -2
- package/lib/adapters-api/dist/model/{CustomAttributeModel.js → CustomAttributeGetModel.js} +39 -89
- package/lib/adapters-api/dist/model/CustomAttributePutModel.js +1 -1
- package/lib/adapters-api/dist/model/LabelApiModel.js +15 -4
- package/lib/adapters-api/dist/model/TestResultResponse.js +4 -18
- package/lib/adapters-api/dist/model/UpdateEmptyTestRunApiModel.js +1 -1
- package/lib/adapters-api/index.d.ts +196 -40
- package/lib/common/utils/tms-load-test-run-debug.d.ts +0 -2
- package/lib/common/utils/tms-load-test-run-debug.js +0 -6
- package/lib/services/attachments/attachments.service.d.ts +1 -0
- package/lib/services/attachments/attachments.service.js +10 -2
- package/lib/services/syncstorage/syncstorage.runner.js +5 -6
- package/lib/services/syncstorage/syncstorage.runner.test.js +0 -16
- package/lib/services/testresults/testresults.converter.d.ts +5 -4
- package/lib/services/testresults/testresults.converter.js +8 -0
- package/lib/services/testresults/testresults.service.js +18 -1
- package/lib/services/testruns/testruns.converter.d.ts +3 -0
- package/lib/services/testruns/testruns.converter.js +12 -0
- package/lib/services/testruns/testruns.converter.test.d.ts +1 -0
- package/lib/services/testruns/testruns.converter.test.js +30 -0
- package/lib/services/testruns/testruns.handler.d.ts +2 -2
- package/lib/services/testruns/testruns.handler.js +2 -12
- package/lib/services/testruns/testruns.service.d.ts +5 -2
- package/lib/services/testruns/testruns.service.js +67 -46
- package/lib/services/testruns/testruns.service.test.d.ts +1 -0
- package/lib/services/testruns/testruns.service.test.js +83 -0
- package/lib/services/testruns/testruns.type.d.ts +2 -0
- package/lib/strategy/base.strategy.d.ts +1 -0
- package/lib/strategy/base.strategy.js +6 -0
- package/lib/strategy/strategy.type.d.ts +1 -0
- package/lib/strategy/zero.strategy.js +1 -1
- package/lib/sync-storage/dist/ApiClient.js +0 -3
- package/package.json +1 -1
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TestResultsConverter = void 0;
|
|
4
|
+
exports.isValidTestRunId = isValidTestRunId;
|
|
4
5
|
const common_1 = require("../../common");
|
|
6
|
+
const TEST_RUN_ID_GUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
7
|
+
function isValidTestRunId(value) {
|
|
8
|
+
return typeof value === "string" && TEST_RUN_ID_GUID.test(value);
|
|
9
|
+
}
|
|
5
10
|
class TestResultsConverter extends common_1.BaseConverter {
|
|
6
11
|
constructor(config) {
|
|
7
12
|
super(config);
|
|
8
13
|
}
|
|
9
14
|
buildRunFilter(statusTypes) {
|
|
15
|
+
if (!isValidTestRunId(this.config.testRunId)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
10
18
|
return {
|
|
11
19
|
testRunIds: [this.config.testRunId],
|
|
12
20
|
configurationIds: [this.config.configurationId],
|
|
@@ -8,12 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.TestResultsService = void 0;
|
|
13
16
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
17
|
const AdaptersApi = require("../../adapters-api/dist/index");
|
|
15
18
|
const common_1 = require("../../common");
|
|
16
19
|
const utils_1 = require("../../common/utils");
|
|
20
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
17
21
|
const testresults_handler_1 = require("./testresults.handler");
|
|
18
22
|
const testresults_converter_1 = require("./testresults.converter");
|
|
19
23
|
class TestResultsService extends common_1.BaseService {
|
|
@@ -26,9 +30,15 @@ class TestResultsService extends common_1.BaseService {
|
|
|
26
30
|
}
|
|
27
31
|
getExternalIdsForRun() {
|
|
28
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const model = this._converter.getTestResultsFilterApiModel();
|
|
34
|
+
if (!model) {
|
|
35
|
+
logger_1.default.warn("[testresults] skip search: testRunId is empty or not a GUID", {
|
|
36
|
+
testRunId: this.config.testRunId,
|
|
37
|
+
});
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
29
40
|
var skip = 0;
|
|
30
41
|
var externalIds = [];
|
|
31
|
-
const model = this._converter.getTestResultsFilterApiModel();
|
|
32
42
|
while (true) {
|
|
33
43
|
const testResults = yield this.getTestResults(skip, model);
|
|
34
44
|
if (testResults.length != 0) {
|
|
@@ -46,6 +56,13 @@ class TestResultsService extends common_1.BaseService {
|
|
|
46
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
57
|
var _a, _b;
|
|
48
58
|
const model = this._converter.getTestResultsFilterForRun();
|
|
59
|
+
if (!model) {
|
|
60
|
+
logger_1.default.warn("[testresults] skip search by externalId: testRunId is empty or not a GUID", {
|
|
61
|
+
externalId,
|
|
62
|
+
testRunId: this.config.testRunId,
|
|
63
|
+
});
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
49
66
|
let skip = 0;
|
|
50
67
|
while (true) {
|
|
51
68
|
const batch = yield this.getTestResults(skip, model);
|
|
@@ -8,6 +8,7 @@ export interface ITestRunConverter {
|
|
|
8
8
|
toOriginAutotestResult(autotest: AutotestResult): any;
|
|
9
9
|
toOriginAutotestResultInProgress(autotest: AutotestResult): any;
|
|
10
10
|
toOriginTestResultUpdate(autotest: AutotestResult): any;
|
|
11
|
+
toOriginSetupTeardownUpdate(autotest: AutotestResult): any;
|
|
11
12
|
}
|
|
12
13
|
export declare class TestRunConverter extends BaseConverter implements ITestRunConverter {
|
|
13
14
|
private autotestConverter;
|
|
@@ -18,5 +19,7 @@ export declare class TestRunConverter extends BaseConverter implements ITestRunC
|
|
|
18
19
|
toOriginAutotestResultInProgress(autotest: AutotestResult): any;
|
|
19
20
|
toOriginAutotestResult(autotest: AutotestResult): any;
|
|
20
21
|
toOriginTestResultUpdate(autotest: AutotestResult): any;
|
|
22
|
+
/** PUT body for fixture setup/teardown only — must not include stepResults or final status. */
|
|
23
|
+
toOriginSetupTeardownUpdate(autotest: AutotestResult): any;
|
|
21
24
|
toLocalTestRun(testRun: any): TestRunGet;
|
|
22
25
|
}
|
|
@@ -80,6 +80,18 @@ class TestRunConverter extends common_1.BaseConverter {
|
|
|
80
80
|
};
|
|
81
81
|
return model;
|
|
82
82
|
}
|
|
83
|
+
/** PUT body for fixture setup/teardown only — must not include stepResults or final status. */
|
|
84
|
+
toOriginSetupTeardownUpdate(autotest) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const model = {};
|
|
87
|
+
if ((_a = autotest.setupResults) === null || _a === void 0 ? void 0 : _a.length) {
|
|
88
|
+
model.setupResults = autotest.setupResults.map((step) => this.toOriginStep(step));
|
|
89
|
+
}
|
|
90
|
+
if ((_b = autotest.teardownResults) === null || _b === void 0 ? void 0 : _b.length) {
|
|
91
|
+
model.teardownResults = autotest.teardownResults.map((step) => this.toOriginStep(step));
|
|
92
|
+
}
|
|
93
|
+
return model;
|
|
94
|
+
}
|
|
83
95
|
toLocalTestRun(testRun) {
|
|
84
96
|
var _a, _b, _c, _d, _e, _f;
|
|
85
97
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testruns_converter_1 = require("./testruns.converter");
|
|
4
|
+
function makeConfig() {
|
|
5
|
+
return {
|
|
6
|
+
url: "http://localhost:8080",
|
|
7
|
+
privateToken: "token",
|
|
8
|
+
projectId: "11111111-1111-1111-1111-111111111111",
|
|
9
|
+
configurationId: "22222222-2222-2222-2222-222222222222",
|
|
10
|
+
testRunId: "33333333-3333-3333-3333-333333333333",
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
describe("TestRunConverter.toOriginSetupTeardownUpdate", () => {
|
|
14
|
+
it("includes only setupResults and teardownResults", () => {
|
|
15
|
+
const converter = new testruns_converter_1.TestRunConverter(makeConfig());
|
|
16
|
+
const model = converter.toOriginSetupTeardownUpdate({
|
|
17
|
+
autoTestExternalId: "ext-1",
|
|
18
|
+
outcome: "Passed",
|
|
19
|
+
stepResults: [{ title: "test step" }],
|
|
20
|
+
setupResults: [{ title: "setup" }],
|
|
21
|
+
teardownResults: [{ title: "teardown" }],
|
|
22
|
+
message: "ignored",
|
|
23
|
+
});
|
|
24
|
+
expect(model.setupResults).toHaveLength(1);
|
|
25
|
+
expect(model.teardownResults).toHaveLength(1);
|
|
26
|
+
expect(model.stepResults).toBeUndefined();
|
|
27
|
+
expect(model.outcome).toBeUndefined();
|
|
28
|
+
expect(model.message).toBeUndefined();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare class TestRunErrorHandler {
|
|
2
|
-
static handleErrorStartTestRun(err:
|
|
3
|
-
static handleErrorCompletedTestRun(err:
|
|
2
|
+
static handleErrorStartTestRun(err: any, message?: string): void;
|
|
3
|
+
static handleErrorCompletedTestRun(err: any, message?: string): void;
|
|
4
4
|
}
|
|
@@ -4,23 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TestRunErrorHandler = void 0;
|
|
7
|
-
const utils_1 = require("../../common/utils");
|
|
8
7
|
const logger_1 = __importDefault(require("../../logger"));
|
|
9
|
-
function logTestRunHttpError(action, err, message = "") {
|
|
10
|
-
var _a;
|
|
11
|
-
const e = (0, utils_1.unwrapHttpError)(err);
|
|
12
|
-
const status = e ? (0, utils_1.getHttpStatus)(e) : undefined;
|
|
13
|
-
const code = e ? (0, utils_1.getNetworkErrorCode)(e) : undefined;
|
|
14
|
-
const body = (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : e === null || e === void 0 ? void 0 : e.body;
|
|
15
|
-
const detail = message || (err instanceof Error ? err.message : String(err));
|
|
16
|
-
logger_1.default.error(`Failed ${action}. Message: ${detail}. status=${status !== null && status !== void 0 ? status : "n/a"} code=${code !== null && code !== void 0 ? code : "n/a"}`, body !== null && body !== void 0 ? body : err);
|
|
17
|
-
}
|
|
18
8
|
class TestRunErrorHandler {
|
|
19
9
|
static handleErrorStartTestRun(err, message = "") {
|
|
20
|
-
|
|
10
|
+
logger_1.default.error(`HttpError ${err.statusCode}. Failed start test run in system. Message: ${message}. Error body:\n`, err.body);
|
|
21
11
|
}
|
|
22
12
|
static handleErrorCompletedTestRun(err, message = "") {
|
|
23
|
-
|
|
13
|
+
logger_1.default.error(`HttpError ${err.statusCode}. Failed completed test run in system. Message: ${message}. Error body:\n`, err.body);
|
|
24
14
|
}
|
|
25
15
|
}
|
|
26
16
|
exports.TestRunErrorHandler = TestRunErrorHandler;
|
|
@@ -6,7 +6,9 @@ export declare class TestRunsService extends BaseService implements ITestRunsSer
|
|
|
6
6
|
protected _client: any;
|
|
7
7
|
protected _converter: ITestRunConverter;
|
|
8
8
|
private readonly _testResults;
|
|
9
|
-
/**
|
|
9
|
+
/** Finalized via POST setAutoTestResults in this process (skip duplicate bulk send). */
|
|
10
|
+
private readonly finalizedExternalIds;
|
|
11
|
+
/** testResultId by autoTestExternalId within current run (InProgress POST + final POST). */
|
|
10
12
|
private readonly testResultIdsByExternalId;
|
|
11
13
|
constructor(config: AdapterConfig);
|
|
12
14
|
createTestRun(): Promise<TestRunId>;
|
|
@@ -16,8 +18,9 @@ export declare class TestRunsService extends BaseService implements ITestRunsSer
|
|
|
16
18
|
completeTestRun(testRunId: TestRunId): Promise<void>;
|
|
17
19
|
postInProgressAutotestResult(testRunId: string, result: AutotestResult): Promise<void>;
|
|
18
20
|
loadAutotests(testRunId: string, results: Array<AutotestResult>): Promise<void>;
|
|
21
|
+
updateSetupTeardown(results: Array<AutotestResult>): Promise<void>;
|
|
19
22
|
private resolveExistingTestResultId;
|
|
20
23
|
private rememberCreatedTestResultId;
|
|
21
24
|
private sendAutotestResultWithRetry;
|
|
22
|
-
private
|
|
25
|
+
private updateSetupTeardownWithRetry;
|
|
23
26
|
}
|
|
@@ -25,7 +25,9 @@ class TestRunsService extends common_1.BaseService {
|
|
|
25
25
|
constructor(config) {
|
|
26
26
|
super(config);
|
|
27
27
|
this.config = config;
|
|
28
|
-
/**
|
|
28
|
+
/** Finalized via POST setAutoTestResults in this process (skip duplicate bulk send). */
|
|
29
|
+
this.finalizedExternalIds = new Set();
|
|
30
|
+
/** testResultId by autoTestExternalId within current run (InProgress POST + final POST). */
|
|
29
31
|
this.testResultIdsByExternalId = new Map();
|
|
30
32
|
this._client = new AdaptersApi.TestRunsApi(AdaptersApi.ApiClient.instance);
|
|
31
33
|
this._converter = new testruns_converter_1.TestRunConverter(config);
|
|
@@ -71,12 +73,15 @@ class TestRunsService extends common_1.BaseService {
|
|
|
71
73
|
}
|
|
72
74
|
getTestRun(testRunId) {
|
|
73
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
return yield
|
|
75
|
-
|
|
76
|
+
return yield this._client
|
|
77
|
+
.adaptersTestRunsIdGet(testRunId)
|
|
76
78
|
// @ts-ignore
|
|
79
|
+
.then((response) => {
|
|
77
80
|
const data = (response === null || response === void 0 ? void 0 : response.body) || response;
|
|
78
|
-
return
|
|
79
|
-
})
|
|
81
|
+
return data;
|
|
82
|
+
})
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
.then((run) => this._converter.toLocalTestRun(run));
|
|
80
85
|
});
|
|
81
86
|
}
|
|
82
87
|
updateTestRun(testRun) {
|
|
@@ -118,24 +123,8 @@ class TestRunsService extends common_1.BaseService {
|
|
|
118
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
124
|
try {
|
|
120
125
|
const testRun = yield this.getTestRun(testRunId);
|
|
121
|
-
if (testRun.stateName
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
try {
|
|
125
|
-
yield (0, utils_1.withHttpRetry)(() => this._client.adaptersTestRunsIdStartPost(testRunId), {
|
|
126
|
-
label: `startTestRun:${testRunId}`,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
const refreshed = yield this.getTestRun(testRunId);
|
|
131
|
-
if (refreshed.stateName !== "NotStarted") {
|
|
132
|
-
logger_1.default.debug("[testruns] startTestRun skipped: run already started", {
|
|
133
|
-
testRunId,
|
|
134
|
-
stateName: refreshed.stateName,
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
throw err;
|
|
126
|
+
if (testRun.stateName === "NotStarted") {
|
|
127
|
+
yield this._client.adaptersTestRunsIdStartPost(testRunId);
|
|
139
128
|
}
|
|
140
129
|
}
|
|
141
130
|
catch (err) {
|
|
@@ -175,26 +164,13 @@ class TestRunsService extends common_1.BaseService {
|
|
|
175
164
|
}
|
|
176
165
|
loadAutotests(testRunId, results) {
|
|
177
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
var _a, _b
|
|
167
|
+
var _a, _b;
|
|
179
168
|
for (const result of results) {
|
|
180
169
|
const externalId = result.autoTestExternalId;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
(0, utils_1.logTmsLoadTestRun)("PUT updateTestResult (final)", {
|
|
170
|
+
if (this.finalizedExternalIds.has(externalId)) {
|
|
171
|
+
(0, utils_1.logTmsLoadTestRun)("Bulk import: skip sendTestResults (already finalized)", {
|
|
184
172
|
testRunId,
|
|
185
173
|
autoTestExternalId: externalId,
|
|
186
|
-
testResultId: existingId,
|
|
187
|
-
stepCount: (_b = (_a = result.stepResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
|
|
188
|
-
});
|
|
189
|
-
yield this.updateAutotestResultWithRetry(existingId, result).catch((err) => {
|
|
190
|
-
var _a, _b;
|
|
191
|
-
const normalized = (_b = (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : err === null || err === void 0 ? void 0 : err.error) !== null && _b !== void 0 ? _b : err;
|
|
192
|
-
logger_1.default.error("[testit-js-commons:loadTestRun] FAILED to update final result", {
|
|
193
|
-
testRunId,
|
|
194
|
-
autoTestExternalId: externalId,
|
|
195
|
-
testResultId: existingId,
|
|
196
|
-
error: normalized,
|
|
197
|
-
});
|
|
198
174
|
});
|
|
199
175
|
continue;
|
|
200
176
|
}
|
|
@@ -205,9 +181,18 @@ class TestRunsService extends common_1.BaseService {
|
|
|
205
181
|
autoTestExternalId: autotestResult.autoTestExternalId,
|
|
206
182
|
statusType: autotestResult.statusType,
|
|
207
183
|
statusCode: autotestResult.statusCode,
|
|
208
|
-
stepCount: (
|
|
184
|
+
stepCount: (_b = (_a = autotestResult.stepResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
|
|
209
185
|
});
|
|
210
|
-
yield this.sendAutotestResultWithRetry(testRunId, autotestResult)
|
|
186
|
+
yield this.sendAutotestResultWithRetry(testRunId, autotestResult)
|
|
187
|
+
.then(() => {
|
|
188
|
+
this.finalizedExternalIds.add(externalId);
|
|
189
|
+
(0, utils_1.logTmsLoadTestRun)("Finalized test result via sendTestResults", {
|
|
190
|
+
testRunId,
|
|
191
|
+
autoTestExternalId: externalId,
|
|
192
|
+
testResultId: this.testResultIdsByExternalId.get(externalId),
|
|
193
|
+
});
|
|
194
|
+
})
|
|
195
|
+
.catch((err) => {
|
|
211
196
|
var _a, _b;
|
|
212
197
|
const normalized = (_b = (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : err === null || err === void 0 ? void 0 : err.error) !== null && _b !== void 0 ? _b : err;
|
|
213
198
|
logger_1.default.error("[testit-js-commons:loadTestRun] FAILED to post final result", {
|
|
@@ -219,6 +204,44 @@ class TestRunsService extends common_1.BaseService {
|
|
|
219
204
|
}
|
|
220
205
|
});
|
|
221
206
|
}
|
|
207
|
+
updateSetupTeardown(results) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
210
|
+
for (const result of results) {
|
|
211
|
+
const hasSetup = Boolean((_a = result.setupResults) === null || _a === void 0 ? void 0 : _a.length);
|
|
212
|
+
const hasTeardown = Boolean((_b = result.teardownResults) === null || _b === void 0 ? void 0 : _b.length);
|
|
213
|
+
if (!hasSetup && !hasTeardown) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const testResultId = yield this.resolveExistingTestResultId(result.autoTestExternalId);
|
|
217
|
+
if (!testResultId) {
|
|
218
|
+
logger_1.default.warn("[testruns] skip setup/teardown PUT: test result id not found", {
|
|
219
|
+
autoTestExternalId: result.autoTestExternalId,
|
|
220
|
+
});
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const model = this._converter.toOriginSetupTeardownUpdate(result);
|
|
224
|
+
if (!((_c = model.setupResults) === null || _c === void 0 ? void 0 : _c.length) && !((_d = model.teardownResults) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
(0, utils_1.escapeHtmlInObject)(model);
|
|
228
|
+
(0, utils_1.logTmsLoadTestRun)("PUT updateTestResult (setup/teardown only)", {
|
|
229
|
+
autoTestExternalId: result.autoTestExternalId,
|
|
230
|
+
testResultId,
|
|
231
|
+
setupCount: (_f = (_e = model.setupResults) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0,
|
|
232
|
+
teardownCount: (_h = (_g = model.teardownResults) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0,
|
|
233
|
+
});
|
|
234
|
+
yield this.updateSetupTeardownWithRetry(testResultId, result, model).catch((err) => {
|
|
235
|
+
var _a;
|
|
236
|
+
logger_1.default.error("[testit-js-commons:loadTestRun] FAILED to update setup/teardown", {
|
|
237
|
+
autoTestExternalId: result.autoTestExternalId,
|
|
238
|
+
testResultId,
|
|
239
|
+
error: (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : err,
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
222
245
|
resolveExistingTestResultId(externalId) {
|
|
223
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
224
247
|
const cached = this.testResultIdsByExternalId.get(externalId);
|
|
@@ -260,12 +283,10 @@ class TestRunsService extends common_1.BaseService {
|
|
|
260
283
|
});
|
|
261
284
|
});
|
|
262
285
|
}
|
|
263
|
-
|
|
286
|
+
updateSetupTeardownWithRetry(testResultId, result, model) {
|
|
264
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
-
|
|
266
|
-
(
|
|
267
|
-
yield (0, utils_1.withHttpRetry)(() => this._testResults.updateTestResult(testResultId, model), { label: `updateTestResult:${result.autoTestExternalId}` });
|
|
268
|
-
logger_1.default.debug("[testruns] updateTestResult ok", {
|
|
288
|
+
yield (0, utils_1.withHttpRetry)(() => this._testResults.updateTestResult(testResultId, model), { label: `updateSetupTeardown:${result.autoTestExternalId}` });
|
|
289
|
+
logger_1.default.debug("[testruns] updateSetupTeardown ok", {
|
|
269
290
|
testResultId,
|
|
270
291
|
autoTestExternalId: result.autoTestExternalId,
|
|
271
292
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const testruns_service_1 = require("./testruns.service");
|
|
13
|
+
jest.mock("../../adapters-api/dist/index", () => ({
|
|
14
|
+
ApiClient: {
|
|
15
|
+
instance: {
|
|
16
|
+
basePath: "",
|
|
17
|
+
authentications: {
|
|
18
|
+
PrivateToken: { apiKeyPrefix: "", apiKey: "" },
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
TestRunsApi: jest.fn().mockImplementation(() => ({
|
|
23
|
+
adaptersTestRunsIdTestResultsPost: jest.fn().mockResolvedValue(["result-id-1"]),
|
|
24
|
+
})),
|
|
25
|
+
}));
|
|
26
|
+
jest.mock("../testresults/testresults.service", () => ({
|
|
27
|
+
TestResultsService: jest.fn().mockImplementation(() => ({
|
|
28
|
+
findTestResultIdByExternalId: jest.fn().mockResolvedValue("existing-inprogress-id"),
|
|
29
|
+
updateTestResult: jest.fn().mockResolvedValue(undefined),
|
|
30
|
+
})),
|
|
31
|
+
}));
|
|
32
|
+
function makeConfig() {
|
|
33
|
+
return {
|
|
34
|
+
url: "http://localhost:8080",
|
|
35
|
+
privateToken: "token",
|
|
36
|
+
projectId: "11111111-1111-1111-1111-111111111111",
|
|
37
|
+
configurationId: "22222222-2222-2222-2222-222222222222",
|
|
38
|
+
testRunId: "33333333-3333-3333-3333-333333333333",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function makeResult(overrides = {}) {
|
|
42
|
+
return Object.assign({ autoTestExternalId: "ext-1", outcome: "Passed", stepResults: [{ title: "step-1" }] }, overrides);
|
|
43
|
+
}
|
|
44
|
+
describe("TestRunsService.loadAutotests", () => {
|
|
45
|
+
it("always POST final result even when in-progress id exists in cache", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const service = new testruns_service_1.TestRunsService(makeConfig());
|
|
47
|
+
const internal = service;
|
|
48
|
+
internal.testResultIdsByExternalId.set("ext-1", "existing-inprogress-id");
|
|
49
|
+
yield service.loadAutotests("run-1", [makeResult()]);
|
|
50
|
+
expect(internal._client.adaptersTestRunsIdTestResultsPost).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(internal._testResults.updateTestResult).not.toHaveBeenCalled();
|
|
52
|
+
expect(internal.finalizedExternalIds.has("ext-1")).toBe(true);
|
|
53
|
+
}));
|
|
54
|
+
it("skips duplicate POST for already finalized externalId", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const service = new testruns_service_1.TestRunsService(makeConfig());
|
|
56
|
+
const internal = service;
|
|
57
|
+
internal.finalizedExternalIds.add("ext-1");
|
|
58
|
+
yield service.loadAutotests("run-1", [makeResult()]);
|
|
59
|
+
expect(internal._client.adaptersTestRunsIdTestResultsPost).not.toHaveBeenCalled();
|
|
60
|
+
}));
|
|
61
|
+
});
|
|
62
|
+
describe("TestRunsService.updateSetupTeardown", () => {
|
|
63
|
+
it("PUT only setup/teardown fields", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const service = new testruns_service_1.TestRunsService(makeConfig());
|
|
65
|
+
const internal = service;
|
|
66
|
+
internal.testResultIdsByExternalId.set("ext-1", "result-id-1");
|
|
67
|
+
yield service.updateSetupTeardown([
|
|
68
|
+
makeResult({
|
|
69
|
+
setupResults: [{ title: "beforeAll" }],
|
|
70
|
+
teardownResults: [{ title: "afterAll" }],
|
|
71
|
+
stepResults: [{ title: "must-not-put" }],
|
|
72
|
+
}),
|
|
73
|
+
]);
|
|
74
|
+
expect(internal._testResults.updateTestResult).toHaveBeenCalledWith("result-id-1", expect.objectContaining({
|
|
75
|
+
setupResults: expect.any(Array),
|
|
76
|
+
teardownResults: expect.any(Array),
|
|
77
|
+
}));
|
|
78
|
+
const putBody = internal._testResults.updateTestResult.mock.calls[0][1];
|
|
79
|
+
expect(putBody.stepResults).toBeUndefined();
|
|
80
|
+
expect(putBody.outcome).toBeUndefined();
|
|
81
|
+
expect(putBody.statusType).toBeUndefined();
|
|
82
|
+
}));
|
|
83
|
+
});
|
|
@@ -63,5 +63,7 @@ export interface ITestRunsService {
|
|
|
63
63
|
/** First TMS write as InProgress (mirrors Python realtime in-progress before final load). */
|
|
64
64
|
postInProgressAutotestResult(testRunId: string, result: AutotestResult): Promise<void>;
|
|
65
65
|
loadAutotests(testRunId: string, autotests: Array<AutotestResult>): Promise<void>;
|
|
66
|
+
/** PUT setup/teardown fixture steps onto an already finalized result (importRealtime session end). */
|
|
67
|
+
updateSetupTeardown(results: Array<AutotestResult>): Promise<void>;
|
|
66
68
|
}
|
|
67
69
|
export {};
|
|
@@ -14,6 +14,7 @@ export declare class BaseStrategy implements IStrategy {
|
|
|
14
14
|
loadAutotest(autotest: AutotestPost, status: string): Promise<void>;
|
|
15
15
|
private updateTestLinkToWorkItems;
|
|
16
16
|
loadTestRun(autotests: AutotestResult[]): Promise<void>;
|
|
17
|
+
updateSetupTeardown(autotests: AutotestResult[]): Promise<void>;
|
|
17
18
|
private tryStartSyncStorage;
|
|
18
19
|
protected updateTestRun(config: AdapterConfig): Promise<void>;
|
|
19
20
|
private getInProgressFirstGraceMs;
|
|
@@ -156,6 +156,12 @@ class BaseStrategy {
|
|
|
156
156
|
yield this.client.testRuns.loadAutotests(testRunId, autotests);
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
|
+
updateSetupTeardown(autotests) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
yield this.testRunId;
|
|
162
|
+
yield this.client.testRuns.updateSetupTeardown(autotests);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
159
165
|
tryStartSyncStorage(testRunId) {
|
|
160
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
167
|
if (!this.config.syncStorageEnabled) {
|
|
@@ -7,7 +7,7 @@ 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.testsInRun = this.client.testResults.getExternalIdsForRun();
|
|
10
|
+
this.testsInRun = this.testRunId.then(() => this.client.testResults.getExternalIdsForRun());
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.ZeroStrategy = ZeroStrategy;
|
|
@@ -289,9 +289,6 @@ class ApiClient {
|
|
|
289
289
|
applyAuthToRequest(request, authNames) {
|
|
290
290
|
authNames.forEach(authName => {
|
|
291
291
|
var auth = this.authentications[authName];
|
|
292
|
-
if (!auth) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
292
|
switch (auth.type) {
|
|
296
293
|
case 'basic':
|
|
297
294
|
if (auth.username || auth.password) {
|