@visual-regression-tracker/sdk-js 5.4.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.
- package/dist/__data__/index.d.ts +5 -0
- package/dist/__data__/index.js +43 -0
- package/dist/helpers/config.helper.js +6 -0
- package/dist/helpers/dto.helper.js +2 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/track.helper.d.ts +4 -0
- package/dist/helpers/track.helper.js +49 -0
- package/dist/helpers/type.helper.d.ts +2 -1
- package/dist/helpers/type.helper.js +5 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/request/testRun.dto.d.ts +1 -0
- package/dist/visualRegressionTracker.d.ts +9 -2
- package/dist/visualRegressionTracker.js +21 -35
- package/package.json +1 -1
|
@@ -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
|
+
};
|
|
@@ -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);
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -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 = 2, 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;
|
|
@@ -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;
|
package/dist/types/config.d.ts
CHANGED
|
@@ -13,6 +13,13 @@ export declare class VisualRegressionTracker {
|
|
|
13
13
|
private submitTestRunMultipart;
|
|
14
14
|
private handleResponse;
|
|
15
15
|
private handleException;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
private getFormData;
|
|
17
|
+
/**
|
|
18
|
+
* Submit test data to external VRT service
|
|
19
|
+
*
|
|
20
|
+
* @param test Test data to track
|
|
21
|
+
* @param retryCount Retry count, default is 2
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
track(test: TestRunBase64 | TestRunMultipart | TestRunBuffer, retryCount?: number): Promise<TestRunResult>;
|
|
18
25
|
}
|
|
@@ -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 {
|
|
@@ -49,6 +48,7 @@ class VisualRegressionTracker {
|
|
|
49
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
49
|
const data = {
|
|
51
50
|
branchName: this.config.branchName,
|
|
51
|
+
baselineBranchName: this.config.baselineBranchName,
|
|
52
52
|
project: this.config.project,
|
|
53
53
|
ciBuildId: this.config.ciBuildId,
|
|
54
54
|
};
|
|
@@ -76,7 +76,7 @@ class VisualRegressionTracker {
|
|
|
76
76
|
}
|
|
77
77
|
submitTestRunBase64(test) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
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);
|
|
80
80
|
return axios_1.default
|
|
81
81
|
.post(`${this.config.apiUrl}/test-runs`, data, this.axiosConfig)
|
|
82
82
|
.then(this.handleResponse)
|
|
@@ -116,50 +116,36 @@ class VisualRegressionTracker {
|
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
|
|
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
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Submit test data to external VRT service
|
|
130
|
+
*
|
|
131
|
+
* @param test Test data to track
|
|
132
|
+
* @param retryCount Retry count, default is 2
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
track(test, retryCount = 2) {
|
|
120
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
137
|
if (!this.isStarted()) {
|
|
122
138
|
throw new Error("Visual Regression Tracker has not been started");
|
|
123
139
|
}
|
|
124
140
|
let testRunResponse;
|
|
125
141
|
if ((0, helpers_1.instanceOfTestRunBase64)(test)) {
|
|
126
|
-
testRunResponse = yield this.submitTestRunBase64(test);
|
|
142
|
+
testRunResponse = yield (0, helpers_1.trackWithRetry)(() => this.submitTestRunBase64(test), retryCount, this.config.enableSoftAssert);
|
|
127
143
|
}
|
|
128
144
|
else {
|
|
129
|
-
|
|
130
|
-
if ((0, helpers_1.instanceOfTestRunBuffer)(test)) {
|
|
131
|
-
formData = (0, helpers_1.bufferDtoToFormData)(Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName }, test));
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
formData = (0, helpers_1.multipartDtoToFormData)(Object.assign({ buildId: this.buildId, projectId: this.projectId, branchName: this.config.branchName }, test));
|
|
135
|
-
}
|
|
136
|
-
testRunResponse = yield this.submitTestRunMultipart(formData);
|
|
145
|
+
testRunResponse = yield (0, helpers_1.trackWithRetry)(() => this.submitTestRunMultipart(this.getFormData(test)), retryCount, this.config.enableSoftAssert);
|
|
137
146
|
}
|
|
138
|
-
this.processTestRun(testRunResponse);
|
|
139
147
|
return new testRunResult_1.default(testRunResponse, this.config.apiUrl);
|
|
140
148
|
});
|
|
141
149
|
}
|
|
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
150
|
}
|
|
165
151
|
exports.VisualRegressionTracker = VisualRegressionTracker;
|