@visual-regression-tracker/sdk-js 5.4.0 → 5.5.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.
@@ -0,0 +1,5 @@
1
+ import { TestRunResponse } from "../types";
2
+ export declare const testRunUnresolvedResponse: TestRunResponse;
3
+ export declare const testRunOkResponse: TestRunResponse;
4
+ export declare const testRunNewResponse: TestRunResponse;
5
+ export declare const testRunAutoApprovedResponse: TestRunResponse;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testRunAutoApprovedResponse = exports.testRunNewResponse = exports.testRunOkResponse = exports.testRunUnresolvedResponse = void 0;
4
+ const types_1 = require("../types");
5
+ exports.testRunUnresolvedResponse = {
6
+ url: "url",
7
+ status: types_1.TestStatus.unresolved,
8
+ pixelMisMatchCount: 12,
9
+ diffPercent: 0.12,
10
+ diffTollerancePercent: 0,
11
+ id: "some id",
12
+ imageName: "imageName",
13
+ merge: false,
14
+ };
15
+ exports.testRunOkResponse = {
16
+ url: "url",
17
+ status: types_1.TestStatus.ok,
18
+ diffPercent: 0,
19
+ diffTollerancePercent: 0,
20
+ id: "some id",
21
+ imageName: "imageName",
22
+ merge: false,
23
+ };
24
+ exports.testRunNewResponse = {
25
+ url: "url",
26
+ status: types_1.TestStatus.new,
27
+ pixelMisMatchCount: 0,
28
+ diffPercent: 0,
29
+ diffTollerancePercent: 0,
30
+ id: "some id",
31
+ imageName: "imageName",
32
+ merge: false,
33
+ };
34
+ exports.testRunAutoApprovedResponse = {
35
+ url: "url",
36
+ status: types_1.TestStatus.autoApproved,
37
+ pixelMisMatchCount: 0,
38
+ diffPercent: 0,
39
+ diffTollerancePercent: 0,
40
+ id: "some id",
41
+ imageName: "imageName",
42
+ merge: false,
43
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./config.helper";
2
2
  export * from "./type.helper";
3
3
  export * from "./dto.helper";
4
+ export * from "./track.helper";
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./config.helper"), exports);
18
18
  __exportStar(require("./type.helper"), exports);
19
19
  __exportStar(require("./dto.helper"), exports);
20
+ __exportStar(require("./track.helper"), exports);
@@ -0,0 +1,4 @@
1
+ import { TestRunResponse } from "../types";
2
+ export declare const processTestRun: (testRunResponse: TestRunResponse, enableSoftAssert?: boolean | undefined) => void;
3
+ export declare const shouldStopRetry: (result: TestRunResponse) => boolean;
4
+ export declare const trackWithRetry: (trackFn: () => Promise<TestRunResponse>, retryLimit: number, enableSoftAssert?: boolean | undefined) => Promise<TestRunResponse>;
@@ -0,0 +1,49 @@
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
+ exports.trackWithRetry = exports.shouldStopRetry = exports.processTestRun = void 0;
13
+ const types_1 = require("../types");
14
+ const getErrorMessage = (testRunResponse) => {
15
+ switch (testRunResponse.status) {
16
+ case types_1.TestStatus.new: {
17
+ return `No baseline: ${testRunResponse.url}`;
18
+ }
19
+ case types_1.TestStatus.unresolved: {
20
+ return `Difference found: ${testRunResponse.url}`;
21
+ }
22
+ }
23
+ };
24
+ const processTestRun = (testRunResponse, enableSoftAssert) => {
25
+ const errorMessage = getErrorMessage(testRunResponse);
26
+ if (errorMessage) {
27
+ if (enableSoftAssert) {
28
+ // eslint-disable-next-line no-console
29
+ console.error(errorMessage);
30
+ }
31
+ else {
32
+ throw new Error(errorMessage);
33
+ }
34
+ }
35
+ };
36
+ exports.processTestRun = processTestRun;
37
+ const shouldStopRetry = (result) => result.status !== types_1.TestStatus.unresolved;
38
+ exports.shouldStopRetry = shouldStopRetry;
39
+ const trackWithRetry = (trackFn, retryLimit, enableSoftAssert) => __awaiter(void 0, void 0, void 0, function* () {
40
+ const result = yield trackFn();
41
+ if (retryLimit <= 0 || (0, exports.shouldStopRetry)(result)) {
42
+ (0, exports.processTestRun)(result, enableSoftAssert);
43
+ return result;
44
+ }
45
+ // eslint-disable-next-line no-console
46
+ console.info(`Diff found... Remaining retry attempts **${retryLimit}**`);
47
+ return (0, exports.trackWithRetry)(trackFn, retryLimit - 1, enableSoftAssert);
48
+ });
49
+ exports.trackWithRetry = trackWithRetry;
@@ -13,6 +13,12 @@ export declare class VisualRegressionTracker {
13
13
  private submitTestRunMultipart;
14
14
  private handleResponse;
15
15
  private handleException;
16
- track(test: TestRunBase64 | TestRunMultipart | TestRunBuffer): Promise<TestRunResult>;
17
- private processTestRun;
16
+ /**
17
+ * Submit test data to external VRT service
18
+ *
19
+ * @param test Test data to track
20
+ * @param retryCount Retry count, default is 2
21
+ * @returns
22
+ */
23
+ track(test: TestRunBase64 | TestRunMultipart | TestRunBuffer, retryCount?: number): Promise<TestRunResult>;
18
24
  }
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.VisualRegressionTracker = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
- const types_1 = require("./types");
18
17
  const testRunResult_1 = __importDefault(require("./testRunResult"));
19
18
  const helpers_1 = require("./helpers");
20
19
  class VisualRegressionTracker {
@@ -116,14 +115,21 @@ class VisualRegressionTracker {
116
115
  }
117
116
  });
118
117
  }
119
- track(test) {
118
+ /**
119
+ * Submit test data to external VRT service
120
+ *
121
+ * @param test Test data to track
122
+ * @param retryCount Retry count, default is 2
123
+ * @returns
124
+ */
125
+ track(test, retryCount = 2) {
120
126
  return __awaiter(this, void 0, void 0, function* () {
121
127
  if (!this.isStarted()) {
122
128
  throw new Error("Visual Regression Tracker has not been started");
123
129
  }
124
130
  let testRunResponse;
125
131
  if ((0, helpers_1.instanceOfTestRunBase64)(test)) {
126
- testRunResponse = yield this.submitTestRunBase64(test);
132
+ testRunResponse = yield (0, helpers_1.trackWithRetry)(() => this.submitTestRunBase64(test), retryCount, this.config.enableSoftAssert);
127
133
  }
128
134
  else {
129
135
  let formData;
@@ -133,33 +139,10 @@ class VisualRegressionTracker {
133
139
  else {
134
140
  formData = (0, helpers_1.multipartDtoToFormData)(Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName }, test));
135
141
  }
136
- testRunResponse = yield this.submitTestRunMultipart(formData);
142
+ testRunResponse = yield (0, helpers_1.trackWithRetry)(() => this.submitTestRunMultipart(formData), retryCount, this.config.enableSoftAssert);
137
143
  }
138
- this.processTestRun(testRunResponse);
139
144
  return new testRunResult_1.default(testRunResponse, this.config.apiUrl);
140
145
  });
141
146
  }
142
- processTestRun(testRunResponse) {
143
- let errorMessage;
144
- switch (testRunResponse.status) {
145
- case types_1.TestStatus.new: {
146
- errorMessage = `No baseline: ${testRunResponse.url}`;
147
- break;
148
- }
149
- case types_1.TestStatus.unresolved: {
150
- errorMessage = `Difference found: ${testRunResponse.url}`;
151
- break;
152
- }
153
- }
154
- if (errorMessage) {
155
- if (this.config.enableSoftAssert) {
156
- // eslint-disable-next-line no-console
157
- console.error(errorMessage);
158
- }
159
- else {
160
- throw new Error(errorMessage);
161
- }
162
- }
163
- }
164
147
  }
165
148
  exports.VisualRegressionTracker = VisualRegressionTracker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visual-regression-tracker/sdk-js",
3
- "version": "5.4.0",
3
+ "version": "5.5.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",