testit-js-commons 5.0.4 → 5.0.6

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.
Files changed (46) hide show
  1. package/lib/adapters-api/dist/api/CustomAttributesApi.js +201 -0
  2. package/lib/adapters-api/dist/index.js +77 -0
  3. package/lib/adapters-api/dist/model/AutoTestApiResult.js +15 -0
  4. package/lib/adapters-api/dist/model/AutoTestCreateApiModel.js +15 -0
  5. package/lib/adapters-api/dist/model/AutoTestUpdateApiModel.js +30 -4
  6. package/lib/adapters-api/dist/model/CustomAttributeApiResult.js +54 -4
  7. package/lib/adapters-api/dist/model/CustomAttributeOptionPostApiModel.js +98 -0
  8. package/lib/adapters-api/dist/model/CustomAttributeOptionUpdateApiModel.js +124 -0
  9. package/lib/adapters-api/dist/model/CustomAttributeSearchApiModel.js +137 -0
  10. package/lib/adapters-api/dist/model/CustomAttributeSearchApiResult.js +281 -0
  11. package/lib/adapters-api/dist/model/GlobalCustomAttributePostApiModel.js +141 -0
  12. package/lib/adapters-api/dist/model/GlobalCustomAttributeUpdateApiModel.js +129 -0
  13. package/lib/adapters-api/dist/model/LayerApiModel.js +102 -0
  14. package/lib/adapters-api/dist/model/LayerApiResult.js +102 -0
  15. package/lib/adapters-api/dist/model/LayerSource.js +61 -0
  16. package/lib/adapters-api/dist/model/ProjectShortestApiResult.js +138 -0
  17. package/lib/adapters-api/dist/model/ProjectsFilterModel.js +13 -13
  18. package/lib/adapters-api/dist/model/TestResultShortResponse.js +15 -4
  19. package/lib/adapters-api/dist/model/TestResultsFilterApiModel.js +14 -0
  20. package/lib/adapters-api/dist/model/TestRunApiResult.js +45 -4
  21. package/lib/adapters-api/index.d.ts +718 -8
  22. package/lib/common/index.d.ts +1 -0
  23. package/lib/common/index.js +1 -0
  24. package/lib/common/test-layers.d.ts +11 -0
  25. package/lib/common/test-layers.js +13 -0
  26. package/lib/common/types/common.type.d.ts +2 -0
  27. package/lib/services/autotests/autotests.converter.d.ts +6 -2
  28. package/lib/services/autotests/autotests.converter.js +41 -16
  29. package/lib/services/autotests/autotests.converter.test.d.ts +1 -0
  30. package/lib/services/autotests/autotests.converter.test.js +39 -0
  31. package/lib/services/autotests/autotests.service.js +3 -3
  32. package/lib/services/autotests/autotests.type.d.ts +2 -0
  33. package/lib/services/syncstorage/syncstorage.runner.js +1 -1
  34. package/lib/services/testruns/testruns.converter.d.ts +3 -0
  35. package/lib/services/testruns/testruns.converter.js +12 -0
  36. package/lib/services/testruns/testruns.converter.test.d.ts +1 -0
  37. package/lib/services/testruns/testruns.converter.test.js +30 -0
  38. package/lib/services/testruns/testruns.service.d.ts +5 -2
  39. package/lib/services/testruns/testruns.service.js +58 -24
  40. package/lib/services/testruns/testruns.service.test.d.ts +1 -0
  41. package/lib/services/testruns/testruns.service.test.js +83 -0
  42. package/lib/services/testruns/testruns.type.d.ts +2 -0
  43. package/lib/strategy/base.strategy.d.ts +1 -0
  44. package/lib/strategy/base.strategy.js +5 -0
  45. package/lib/strategy/strategy.type.d.ts +1 -0
  46. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  export * from "./types";
2
2
  export * from "./utils";
3
+ export * from "./test-layers";
3
4
  export * from "./base.converter";
4
5
  export * from "./base.service";
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
18
  __exportStar(require("./utils"), exports);
19
+ __exportStar(require("./test-layers"), exports);
19
20
  __exportStar(require("./base.converter"), exports);
20
21
  __exportStar(require("./base.service"), exports);
@@ -0,0 +1,11 @@
1
+ /** Recommended autotest pyramid layer names (not enforced). */
2
+ export declare const TestLayers: {
3
+ readonly E2E: "E2E";
4
+ readonly UI: "UI";
5
+ readonly API: "API";
6
+ readonly CONTRACT: "Contract";
7
+ readonly INTEGRATION: "Integration";
8
+ readonly COMPONENT: "Component";
9
+ readonly UNIT: "Unit";
10
+ };
11
+ export type TestLayerName = (typeof TestLayers)[keyof typeof TestLayers] | string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestLayers = void 0;
4
+ /** Recommended autotest pyramid layer names (not enforced). */
5
+ exports.TestLayers = {
6
+ E2E: "E2E",
7
+ UI: "UI",
8
+ API: "API",
9
+ CONTRACT: "Contract",
10
+ INTEGRATION: "Integration",
11
+ COMPONENT: "Component",
12
+ UNIT: "Unit",
13
+ };
@@ -41,6 +41,8 @@ export interface Metadata {
41
41
  workItemsIds?: string[];
42
42
  links?: Link[];
43
43
  labels?: string[];
44
+ /** Test pyramid layer declared in test code. */
45
+ layer?: string;
44
46
  classname?: string;
45
47
  namespace?: string;
46
48
  properties?: {
@@ -1,11 +1,15 @@
1
1
  import { BaseConverter, AdapterConfig } from "../../common";
2
2
  import { AutotestGet, AutotestPost } from "./autotests.type";
3
3
  export interface IAutotestConverter {
4
- toOriginAutotest(autotest: AutotestPost): any;
4
+ toOriginAutotestCreate(autotest: AutotestPost): any;
5
+ toOriginAutotestUpdate(autotest: AutotestPost): any;
5
6
  toLocalAutotest(autotest: any): AutotestGet;
6
7
  }
7
8
  export declare class AutotestConverter extends BaseConverter implements IAutotestConverter {
8
9
  constructor(config: AdapterConfig);
9
- toOriginAutotest(autotest: AutotestPost): any;
10
+ toOriginAutotestCreate(autotest: AutotestPost): any;
11
+ toOriginAutotestUpdate(autotest: AutotestPost): any;
10
12
  toLocalAutotest(autotest: any): AutotestGet;
13
+ private baseAutotestFields;
14
+ private layerToApiModel;
11
15
  }
@@ -2,11 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AutotestConverter = void 0;
4
4
  const common_1 = require("../../common");
5
+ const LAYER_SOURCE_RUN = "Run";
5
6
  class AutotestConverter extends common_1.BaseConverter {
6
7
  constructor(config) {
7
8
  super(config);
8
9
  }
9
- toOriginAutotest(autotest) {
10
+ toOriginAutotestCreate(autotest) {
11
+ const model = this.baseAutotestFields(autotest);
12
+ const layer = this.layerToApiModel(autotest.layer);
13
+ if (layer) {
14
+ model.layer = layer;
15
+ }
16
+ return model;
17
+ }
18
+ toOriginAutotestUpdate(autotest) {
19
+ const model = Object.assign(Object.assign({}, this.baseAutotestFields(autotest)), { resetLayer: false });
20
+ const layer = this.layerToApiModel(autotest.layer);
21
+ if (layer) {
22
+ model.layer = layer;
23
+ }
24
+ return model;
25
+ }
26
+ toLocalAutotest(autotest) {
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
28
+ return {
29
+ id: autotest.id,
30
+ name: (_a = autotest.name) !== null && _a !== void 0 ? _a : undefined,
31
+ externalId: (_b = autotest.externalId) !== null && _b !== void 0 ? _b : undefined,
32
+ links: (_c = autotest.links) === null || _c === void 0 ? void 0 : _c.map((link) => this.toLocalLink(link)),
33
+ namespace: (_d = autotest.namespace) !== null && _d !== void 0 ? _d : undefined,
34
+ classname: (_e = autotest.classname) !== null && _e !== void 0 ? _e : undefined,
35
+ steps: (_f = autotest.steps) === null || _f === void 0 ? void 0 : _f.map((step) => this.toLocalShortStep(step)),
36
+ setup: (_g = autotest.setup) === null || _g === void 0 ? void 0 : _g.map((step) => this.toLocalShortStep(step)),
37
+ teardown: (_h = autotest.teardown) === null || _h === void 0 ? void 0 : _h.map((step) => this.toLocalShortStep(step)),
38
+ labels: (_j = autotest.labels) !== null && _j !== void 0 ? _j : undefined,
39
+ tags: (_k = autotest.tags) !== null && _k !== void 0 ? _k : undefined,
40
+ layer: (_m = (_l = autotest.layer) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : undefined,
41
+ };
42
+ }
43
+ baseAutotestFields(autotest) {
10
44
  return {
11
45
  externalId: autotest.externalId,
12
46
  name: autotest.name,
@@ -26,21 +60,12 @@ class AutotestConverter extends common_1.BaseConverter {
26
60
  shouldCreateWorkItem: this.config.automaticCreationTestCases,
27
61
  };
28
62
  }
29
- toLocalAutotest(autotest) {
30
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
31
- return {
32
- id: autotest.id,
33
- name: (_a = autotest.name) !== null && _a !== void 0 ? _a : undefined,
34
- externalId: (_b = autotest.externalId) !== null && _b !== void 0 ? _b : undefined,
35
- links: (_c = autotest.links) === null || _c === void 0 ? void 0 : _c.map((link) => this.toLocalLink(link)),
36
- namespace: (_d = autotest.namespace) !== null && _d !== void 0 ? _d : undefined,
37
- classname: (_e = autotest.classname) !== null && _e !== void 0 ? _e : undefined,
38
- steps: (_f = autotest.steps) === null || _f === void 0 ? void 0 : _f.map((step) => this.toLocalShortStep(step)),
39
- setup: (_g = autotest.setup) === null || _g === void 0 ? void 0 : _g.map((step) => this.toLocalShortStep(step)),
40
- teardown: (_h = autotest.teardown) === null || _h === void 0 ? void 0 : _h.map((step) => this.toLocalShortStep(step)),
41
- labels: (_j = autotest.labels) !== null && _j !== void 0 ? _j : undefined,
42
- tags: (_k = autotest.tags) !== null && _k !== void 0 ? _k : undefined,
43
- };
63
+ layerToApiModel(layer) {
64
+ const name = layer === null || layer === void 0 ? void 0 : layer.trim();
65
+ if (!name) {
66
+ return undefined;
67
+ }
68
+ return { name, source: LAYER_SOURCE_RUN };
44
69
  }
45
70
  }
46
71
  exports.AutotestConverter = AutotestConverter;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const autotests_converter_1 = require("./autotests.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
+ function makeAutotest(overrides = {}) {
14
+ return Object.assign({ externalId: "ext-1", name: "test name" }, overrides);
15
+ }
16
+ describe("AutotestConverter layer", () => {
17
+ const converter = new autotests_converter_1.AutotestConverter(makeConfig());
18
+ it("create: includes layer when set", () => {
19
+ const model = converter.toOriginAutotestCreate(makeAutotest({ layer: "API" }));
20
+ expect(model.layer).toEqual({ name: "API", source: "Run" });
21
+ expect(model.resetLayer).toBeUndefined();
22
+ });
23
+ it("create: omits layer when not set", () => {
24
+ const model = converter.toOriginAutotestCreate(makeAutotest());
25
+ expect(model.layer).toBeUndefined();
26
+ });
27
+ it("create: accepts custom layer string", () => {
28
+ const model = converter.toOriginAutotestCreate(makeAutotest({ layer: "my-custom-layer" }));
29
+ expect(model.layer).toEqual({ name: "my-custom-layer", source: "Run" });
30
+ });
31
+ it("update: always resetLayer false, layer only when set", () => {
32
+ const withLayer = converter.toOriginAutotestUpdate(makeAutotest({ layer: "E2E" }));
33
+ expect(withLayer.resetLayer).toBe(false);
34
+ expect(withLayer.layer).toEqual({ name: "E2E", source: "Run" });
35
+ const withoutLayer = converter.toOriginAutotestUpdate(makeAutotest());
36
+ expect(withoutLayer.resetLayer).toBe(false);
37
+ expect(withoutLayer.layer).toBeUndefined();
38
+ });
39
+ });
@@ -28,7 +28,7 @@ class AutotestsService extends common_1.BaseService {
28
28
  }
29
29
  createAutotest(autotest) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
- const autotestPost = this._converter.toOriginAutotest(autotest);
31
+ const autotestPost = this._converter.toOriginAutotestCreate(autotest);
32
32
  (0, common_1.escapeHtmlInObject)(autotestPost);
33
33
  logger_1.default.debug("[autotests] createAutoTest", { externalId: autotest.externalId, name: autotest.name });
34
34
  try {
@@ -51,7 +51,7 @@ class AutotestsService extends common_1.BaseService {
51
51
  }
52
52
  updateAutotest(autotest) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- const autotestPost = this._converter.toOriginAutotest(autotest);
54
+ const autotestPost = this._converter.toOriginAutotestUpdate(autotest);
55
55
  (0, common_1.escapeHtmlInObject)(autotestPost);
56
56
  logger_1.default.debug("[autotests] updateAutoTest", { externalId: autotest.externalId, name: autotest.name });
57
57
  yield (0, common_1.withHttpRetry)(() => this._client
@@ -103,7 +103,7 @@ class AutotestsService extends common_1.BaseService {
103
103
  updateAutotestFromFailed(originAutotest, autotest) {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  var _a, _b, _c, _d;
106
- yield this.updateAutotest(Object.assign(Object.assign({}, originAutotest), { externalId: (_a = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.externalId) !== null && _a !== void 0 ? _a : autotest.externalId, name: (_b = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.name) !== null && _b !== void 0 ? _b : autotest.name, links: autotest.links, externalKey: autotest.externalKey, steps: autotest.steps, setup: autotest.setup, teardown: autotest.teardown, title: autotest.title, description: autotest.description, namespace: (_c = autotest.namespace) !== null && _c !== void 0 ? _c : originAutotest.namespace, classname: (_d = autotest.classname) !== null && _d !== void 0 ? _d : originAutotest.classname, labels: autotest.labels, tags: autotest.tags, workItemIds: autotest.workItemIds, isFlaky: autotest.isFlaky, shouldCreateWorkItem: autotest.shouldCreateWorkItem }));
106
+ yield this.updateAutotest(Object.assign(Object.assign({}, originAutotest), { externalId: (_a = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.externalId) !== null && _a !== void 0 ? _a : autotest.externalId, name: (_b = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.name) !== null && _b !== void 0 ? _b : autotest.name, links: autotest.links, externalKey: autotest.externalKey, steps: autotest.steps, setup: autotest.setup, teardown: autotest.teardown, title: autotest.title, description: autotest.description, namespace: (_c = autotest.namespace) !== null && _c !== void 0 ? _c : originAutotest.namespace, classname: (_d = autotest.classname) !== null && _d !== void 0 ? _d : originAutotest.classname, labels: autotest.labels, tags: autotest.tags, layer: autotest.layer, workItemIds: autotest.workItemIds, isFlaky: autotest.isFlaky, shouldCreateWorkItem: autotest.shouldCreateWorkItem }));
107
107
  });
108
108
  }
109
109
  linkToWorkItems(internalId, workItemIds) {
@@ -25,6 +25,8 @@ interface AutotestBase {
25
25
  labels?: Array<Label>;
26
26
  tags?: Array<string>;
27
27
  externalKey?: string;
28
+ /** Test pyramid layer name from test code annotation (source Run is set by converter). */
29
+ layer?: string;
28
30
  }
29
31
  export interface AutotestPost extends AutotestBase {
30
32
  externalId: string;
@@ -354,7 +354,7 @@ class SyncStorageRunner {
354
354
  }
355
355
  }
356
356
  exports.SyncStorageRunner = SyncStorageRunner;
357
- SyncStorageRunner.VERSION = "v0.3.6-tms-5.7";
357
+ SyncStorageRunner.VERSION = "v0.3.10";
358
358
  SyncStorageRunner.STARTUP_TIMEOUT_MS = 30000;
359
359
  SyncStorageRunner.STARTUP_POLL_MS = 1000;
360
360
  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);
@@ -175,26 +177,13 @@ class TestRunsService extends common_1.BaseService {
175
177
  }
176
178
  loadAutotests(testRunId, results) {
177
179
  return __awaiter(this, void 0, void 0, function* () {
178
- var _a, _b, _c, _d;
180
+ var _a, _b;
179
181
  for (const result of results) {
180
182
  const externalId = result.autoTestExternalId;
181
- const existingId = yield this.resolveExistingTestResultId(externalId);
182
- if (existingId) {
183
- (0, utils_1.logTmsLoadTestRun)("PUT updateTestResult (final)", {
183
+ if (this.finalizedExternalIds.has(externalId)) {
184
+ (0, utils_1.logTmsLoadTestRun)("Bulk import: skip sendTestResults (already finalized)", {
184
185
  testRunId,
185
186
  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
187
  });
199
188
  continue;
200
189
  }
@@ -205,9 +194,18 @@ class TestRunsService extends common_1.BaseService {
205
194
  autoTestExternalId: autotestResult.autoTestExternalId,
206
195
  statusType: autotestResult.statusType,
207
196
  statusCode: autotestResult.statusCode,
208
- stepCount: (_d = (_c = autotestResult.stepResults) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0,
197
+ stepCount: (_b = (_a = autotestResult.stepResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
209
198
  });
210
- yield this.sendAutotestResultWithRetry(testRunId, autotestResult).catch((err) => {
199
+ yield this.sendAutotestResultWithRetry(testRunId, autotestResult)
200
+ .then(() => {
201
+ this.finalizedExternalIds.add(externalId);
202
+ (0, utils_1.logTmsLoadTestRun)("Finalized test result via sendTestResults", {
203
+ testRunId,
204
+ autoTestExternalId: externalId,
205
+ testResultId: this.testResultIdsByExternalId.get(externalId),
206
+ });
207
+ })
208
+ .catch((err) => {
211
209
  var _a, _b;
212
210
  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
211
  logger_1.default.error("[testit-js-commons:loadTestRun] FAILED to post final result", {
@@ -219,6 +217,44 @@ class TestRunsService extends common_1.BaseService {
219
217
  }
220
218
  });
221
219
  }
220
+ updateSetupTeardown(results) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ var _a, _b, _c, _d, _e, _f, _g, _h;
223
+ for (const result of results) {
224
+ const hasSetup = Boolean((_a = result.setupResults) === null || _a === void 0 ? void 0 : _a.length);
225
+ const hasTeardown = Boolean((_b = result.teardownResults) === null || _b === void 0 ? void 0 : _b.length);
226
+ if (!hasSetup && !hasTeardown) {
227
+ continue;
228
+ }
229
+ const testResultId = yield this.resolveExistingTestResultId(result.autoTestExternalId);
230
+ if (!testResultId) {
231
+ logger_1.default.warn("[testruns] skip setup/teardown PUT: test result id not found", {
232
+ autoTestExternalId: result.autoTestExternalId,
233
+ });
234
+ continue;
235
+ }
236
+ const model = this._converter.toOriginSetupTeardownUpdate(result);
237
+ if (!((_c = model.setupResults) === null || _c === void 0 ? void 0 : _c.length) && !((_d = model.teardownResults) === null || _d === void 0 ? void 0 : _d.length)) {
238
+ continue;
239
+ }
240
+ (0, utils_1.escapeHtmlInObject)(model);
241
+ (0, utils_1.logTmsLoadTestRun)("PUT updateTestResult (setup/teardown only)", {
242
+ autoTestExternalId: result.autoTestExternalId,
243
+ testResultId,
244
+ setupCount: (_f = (_e = model.setupResults) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0,
245
+ teardownCount: (_h = (_g = model.teardownResults) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0,
246
+ });
247
+ yield this.updateSetupTeardownWithRetry(testResultId, result, model).catch((err) => {
248
+ var _a;
249
+ logger_1.default.error("[testit-js-commons:loadTestRun] FAILED to update setup/teardown", {
250
+ autoTestExternalId: result.autoTestExternalId,
251
+ testResultId,
252
+ error: (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : err,
253
+ });
254
+ });
255
+ }
256
+ });
257
+ }
222
258
  resolveExistingTestResultId(externalId) {
223
259
  return __awaiter(this, void 0, void 0, function* () {
224
260
  const cached = this.testResultIdsByExternalId.get(externalId);
@@ -260,12 +296,10 @@ class TestRunsService extends common_1.BaseService {
260
296
  });
261
297
  });
262
298
  }
263
- updateAutotestResultWithRetry(testResultId, result) {
299
+ updateSetupTeardownWithRetry(testResultId, result, model) {
264
300
  return __awaiter(this, void 0, void 0, function* () {
265
- const model = this._converter.toOriginTestResultUpdate(result);
266
- (0, utils_1.escapeHtmlInObject)(model);
267
- yield (0, utils_1.withHttpRetry)(() => this._testResults.updateTestResult(testResultId, model), { label: `updateTestResult:${result.autoTestExternalId}` });
268
- logger_1.default.debug("[testruns] updateTestResult ok", {
301
+ yield (0, utils_1.withHttpRetry)(() => this._testResults.updateTestResult(testResultId, model), { label: `updateSetupTeardown:${result.autoTestExternalId}` });
302
+ logger_1.default.debug("[testruns] updateSetupTeardown ok", {
269
303
  testResultId,
270
304
  autoTestExternalId: result.autoTestExternalId,
271
305
  });
@@ -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.4",
3
+ "version": "5.0.6",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",