testit-js-commons 5.0.3 → 5.0.4-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.
@@ -353,7 +353,7 @@ class SyncStorageRunner {
353
353
  }
354
354
  }
355
355
  exports.SyncStorageRunner = SyncStorageRunner;
356
- SyncStorageRunner.VERSION = "v0.3.6-tms-5.7";
356
+ SyncStorageRunner.VERSION = "v0.3.10-tms-5.8";
357
357
  SyncStorageRunner.STARTUP_TIMEOUT_MS = 30000;
358
358
  SyncStorageRunner.STARTUP_POLL_MS = 1000;
359
359
  SyncStorageRunner.PROCESS_WARMUP_MS = 2000;
@@ -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
+ });
@@ -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
- /** testResultId by autoTestExternalId within current run (InProgress POST + search). */
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 updateAutotestResultWithRetry;
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
- /** testResultId by autoTestExternalId within current run (InProgress POST + search). */
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);
@@ -162,26 +164,13 @@ class TestRunsService extends common_1.BaseService {
162
164
  }
163
165
  loadAutotests(testRunId, results) {
164
166
  return __awaiter(this, void 0, void 0, function* () {
165
- var _a, _b, _c, _d;
167
+ var _a, _b;
166
168
  for (const result of results) {
167
169
  const externalId = result.autoTestExternalId;
168
- const existingId = yield this.resolveExistingTestResultId(externalId);
169
- if (existingId) {
170
- (0, utils_1.logTmsLoadTestRun)("PUT updateTestResult (final)", {
170
+ if (this.finalizedExternalIds.has(externalId)) {
171
+ (0, utils_1.logTmsLoadTestRun)("Bulk import: skip sendTestResults (already finalized)", {
171
172
  testRunId,
172
173
  autoTestExternalId: externalId,
173
- testResultId: existingId,
174
- stepCount: (_b = (_a = result.stepResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
175
- });
176
- yield this.updateAutotestResultWithRetry(existingId, result).catch((err) => {
177
- var _a, _b;
178
- 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;
179
- logger_1.default.error("[testit-js-commons:loadTestRun] FAILED to update final result", {
180
- testRunId,
181
- autoTestExternalId: externalId,
182
- testResultId: existingId,
183
- error: normalized,
184
- });
185
174
  });
186
175
  continue;
187
176
  }
@@ -192,9 +181,18 @@ class TestRunsService extends common_1.BaseService {
192
181
  autoTestExternalId: autotestResult.autoTestExternalId,
193
182
  statusType: autotestResult.statusType,
194
183
  statusCode: autotestResult.statusCode,
195
- stepCount: (_d = (_c = autotestResult.stepResults) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0,
184
+ stepCount: (_b = (_a = autotestResult.stepResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
196
185
  });
197
- yield this.sendAutotestResultWithRetry(testRunId, autotestResult).catch((err) => {
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) => {
198
196
  var _a, _b;
199
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;
200
198
  logger_1.default.error("[testit-js-commons:loadTestRun] FAILED to post final result", {
@@ -206,6 +204,44 @@ class TestRunsService extends common_1.BaseService {
206
204
  }
207
205
  });
208
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
+ }
209
245
  resolveExistingTestResultId(externalId) {
210
246
  return __awaiter(this, void 0, void 0, function* () {
211
247
  const cached = this.testResultIdsByExternalId.get(externalId);
@@ -247,12 +283,10 @@ class TestRunsService extends common_1.BaseService {
247
283
  });
248
284
  });
249
285
  }
250
- updateAutotestResultWithRetry(testResultId, result) {
286
+ updateSetupTeardownWithRetry(testResultId, result, model) {
251
287
  return __awaiter(this, void 0, void 0, function* () {
252
- const model = this._converter.toOriginTestResultUpdate(result);
253
- (0, utils_1.escapeHtmlInObject)(model);
254
- yield (0, utils_1.withHttpRetry)(() => this._testResults.updateTestResult(testResultId, model), { label: `updateTestResult:${result.autoTestExternalId}` });
255
- 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", {
256
290
  testResultId,
257
291
  autoTestExternalId: result.autoTestExternalId,
258
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,11 @@ 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.client.testRuns.updateSetupTeardown(autotests);
162
+ });
163
+ }
159
164
  tryStartSyncStorage(testRunId) {
160
165
  return __awaiter(this, void 0, void 0, function* () {
161
166
  if (!this.config.syncStorageEnabled) {
@@ -6,4 +6,5 @@ export interface IStrategy {
6
6
  teardown(): Promise<void>;
7
7
  loadAutotest(autotest: AutotestPost, status: string): Promise<void>;
8
8
  loadTestRun(autotests: AutotestResult[]): Promise<void>;
9
+ updateSetupTeardown(autotests: AutotestResult[]): Promise<void>;
9
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "5.0.3",
3
+ "version": "5.0.4-TMS-5.8",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",