@visual-regression-tracker/sdk-js 5.5.0 → 5.6.0

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.
@@ -12,6 +12,9 @@ const readConfigFromFile = (config) => {
12
12
  if (fileConfig.branchName) {
13
13
  config.branchName = fileConfig.branchName;
14
14
  }
15
+ if (fileConfig.baselineBranchName) {
16
+ config.baselineBranchName = fileConfig.baselineBranchName;
17
+ }
15
18
  if (fileConfig.project) {
16
19
  config.project = fileConfig.project;
17
20
  }
@@ -35,6 +38,9 @@ const readConfigFromEnv = (config) => {
35
38
  if (process.env["VRT_BRANCHNAME"]) {
36
39
  config.branchName = process.env["VRT_BRANCHNAME"];
37
40
  }
41
+ if (process.env["VRT_BASELINEBRANCHNAME"]) {
42
+ config.baselineBranchName = process.env["VRT_BASELINEBRANCHNAME"];
43
+ }
38
44
  if (process.env["VRT_PROJECT"]) {
39
45
  config.project = process.env["VRT_PROJECT"];
40
46
  }
@@ -11,6 +11,7 @@ const multipartDtoToFormData = (dto) => {
11
11
  data.append("buildId", dto.buildId);
12
12
  data.append("projectId", dto.projectId);
13
13
  data.append("branchName", dto.branchName);
14
+ dto.baselineBranchName && data.append("baselineBranchName", dto.baselineBranchName);
14
15
  data.append("name", dto.name);
15
16
  data.append("image", fs_1.default.createReadStream(dto.imagePath), {
16
17
  knownLength: fs_1.default.statSync(dto.imagePath).size,
@@ -33,6 +34,7 @@ const bufferDtoToFormData = (dto) => {
33
34
  data.append("buildId", dto.buildId);
34
35
  data.append("projectId", dto.projectId);
35
36
  data.append("branchName", dto.branchName);
37
+ dto.baselineBranchName && data.append("baselineBranchName", dto.baselineBranchName);
36
38
  data.append("name", dto.name);
37
39
  data.append("image", dto.imageBuffer, { filename: "image.png" });
38
40
  dto.os && data.append("os", dto.os);
@@ -1,4 +1,4 @@
1
1
  import { TestRunResponse } from "../types";
2
2
  export declare const processTestRun: (testRunResponse: TestRunResponse, enableSoftAssert?: boolean | undefined) => void;
3
3
  export declare const shouldStopRetry: (result: TestRunResponse) => boolean;
4
- export declare const trackWithRetry: (trackFn: () => Promise<TestRunResponse>, retryLimit: number, enableSoftAssert?: boolean | undefined) => Promise<TestRunResponse>;
4
+ export declare const trackWithRetry: (trackFn: () => Promise<TestRunResponse>, retryLimit?: number, enableSoftAssert?: boolean | undefined) => Promise<TestRunResponse>;
@@ -36,7 +36,7 @@ const processTestRun = (testRunResponse, enableSoftAssert) => {
36
36
  exports.processTestRun = processTestRun;
37
37
  const shouldStopRetry = (result) => result.status !== types_1.TestStatus.unresolved;
38
38
  exports.shouldStopRetry = shouldStopRetry;
39
- const trackWithRetry = (trackFn, retryLimit, enableSoftAssert) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const trackWithRetry = (trackFn, retryLimit = 2, enableSoftAssert) => __awaiter(void 0, void 0, void 0, function* () {
40
40
  const result = yield trackFn();
41
41
  if (retryLimit <= 0 || (0, exports.shouldStopRetry)(result)) {
42
42
  (0, exports.processTestRun)(result, enableSoftAssert);
@@ -1,3 +1,4 @@
1
- import { TestRunBase64, TestRunBuffer } from "../types";
1
+ import { TestRunBase64, TestRunBuffer, TestRunMultipart } from "../types";
2
2
  export declare function instanceOfTestRunBase64(object: any): object is TestRunBase64;
3
3
  export declare function instanceOfTestRunBuffer(object: any): object is TestRunBuffer;
4
+ export declare function instanceOfTestRunMultipart(object: any): object is TestRunMultipart;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instanceOfTestRunBuffer = exports.instanceOfTestRunBase64 = void 0;
3
+ exports.instanceOfTestRunMultipart = exports.instanceOfTestRunBuffer = exports.instanceOfTestRunBase64 = void 0;
4
4
  function instanceOfTestRunBase64(object) {
5
5
  return "imageBase64" in object;
6
6
  }
@@ -9,3 +9,7 @@ function instanceOfTestRunBuffer(object) {
9
9
  return "imageBuffer" in object;
10
10
  }
11
11
  exports.instanceOfTestRunBuffer = instanceOfTestRunBuffer;
12
+ function instanceOfTestRunMultipart(object) {
13
+ return "imagePath" in object;
14
+ }
15
+ exports.instanceOfTestRunMultipart = instanceOfTestRunMultipart;
@@ -1,6 +1,7 @@
1
1
  export interface Config extends Record<string, any> {
2
2
  apiUrl: string;
3
3
  branchName: string;
4
+ baselineBranchName?: string;
4
5
  project: string;
5
6
  apiKey: string;
6
7
  enableSoftAssert?: boolean;
@@ -7,6 +7,7 @@ export interface TestRunDto {
7
7
  device?: string;
8
8
  customTags?: string;
9
9
  branchName: string;
10
+ baselineBranchName?: string;
10
11
  buildId: string;
11
12
  projectId: string;
12
13
  diffTollerancePercent?: number;
@@ -13,6 +13,7 @@ export declare class VisualRegressionTracker {
13
13
  private submitTestRunMultipart;
14
14
  private handleResponse;
15
15
  private handleException;
16
+ private getFormData;
16
17
  /**
17
18
  * Submit test data to external VRT service
18
19
  *
@@ -48,6 +48,7 @@ class VisualRegressionTracker {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
49
  const data = {
50
50
  branchName: this.config.branchName,
51
+ baselineBranchName: this.config.baselineBranchName,
51
52
  project: this.config.project,
52
53
  ciBuildId: this.config.ciBuildId,
53
54
  };
@@ -75,7 +76,7 @@ class VisualRegressionTracker {
75
76
  }
76
77
  submitTestRunBase64(test) {
77
78
  return __awaiter(this, void 0, void 0, function* () {
78
- const data = Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName }, test);
79
+ const data = Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName, baselineBranchName: this.config.baselineBranchName }, test);
79
80
  return axios_1.default
80
81
  .post(`${this.config.apiUrl}/test-runs`, data, this.axiosConfig)
81
82
  .then(this.handleResponse)
@@ -115,6 +116,15 @@ class VisualRegressionTracker {
115
116
  }
116
117
  });
117
118
  }
119
+ getFormData(test) {
120
+ if ((0, helpers_1.instanceOfTestRunBuffer)(test)) {
121
+ return (0, helpers_1.bufferDtoToFormData)(Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName, baselineBranchName: this.config.baselineBranchName }, test));
122
+ }
123
+ else if ((0, helpers_1.instanceOfTestRunMultipart)(test)) {
124
+ return (0, helpers_1.multipartDtoToFormData)(Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName, baselineBranchName: this.config.baselineBranchName }, test));
125
+ }
126
+ throw new Error("Invalid test run data");
127
+ }
118
128
  /**
119
129
  * Submit test data to external VRT service
120
130
  *
@@ -132,14 +142,7 @@ class VisualRegressionTracker {
132
142
  testRunResponse = yield (0, helpers_1.trackWithRetry)(() => this.submitTestRunBase64(test), retryCount, this.config.enableSoftAssert);
133
143
  }
134
144
  else {
135
- let formData;
136
- if ((0, helpers_1.instanceOfTestRunBuffer)(test)) {
137
- formData = (0, helpers_1.bufferDtoToFormData)(Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName }, test));
138
- }
139
- else {
140
- formData = (0, helpers_1.multipartDtoToFormData)(Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName }, test));
141
- }
142
- testRunResponse = yield (0, helpers_1.trackWithRetry)(() => this.submitTestRunMultipart(formData), retryCount, this.config.enableSoftAssert);
145
+ testRunResponse = yield (0, helpers_1.trackWithRetry)(() => this.submitTestRunMultipart(this.getFormData(test)), retryCount, this.config.enableSoftAssert);
143
146
  }
144
147
  return new testRunResult_1.default(testRunResponse, this.config.apiUrl);
145
148
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visual-regression-tracker/sdk-js",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",