Skip to content

Commit 73891cd

Browse files
committed
published
1 parent 49624b9 commit 73891cd

21 files changed

+145
-18
lines changed

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
examples
2+
.vscode
3+
4+
jest.config.js
5+
tsconfig.json
6+
lib

dist/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Config, TestRun, TestRunResult } from "./types";
2+
import { AxiosRequestConfig } from "axios";
3+
export declare class VisualRegressionTracker {
4+
config: Config;
5+
buildId: string | undefined;
6+
axiosConfig: AxiosRequestConfig;
7+
constructor(config: Config);
8+
private startBuild;
9+
submitTestResult(test: TestRun): Promise<TestRunResult>;
10+
}

dist/index.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
var __importDefault = (this && this.__importDefault) || function (mod) {
12+
return (mod && mod.__esModule) ? mod : { "default": mod };
13+
};
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
const axios_1 = __importDefault(require("axios"));
16+
class VisualRegressionTracker {
17+
constructor(config) {
18+
this.config = config;
19+
this.axiosConfig = {
20+
headers: {
21+
apiKey: this.config.token,
22+
},
23+
};
24+
}
25+
startBuild(projectId, branchName) {
26+
return __awaiter(this, void 0, void 0, function* () {
27+
if (!this.buildId) {
28+
console.log("Starting new build");
29+
const data = { branchName, projectId };
30+
const build = yield axios_1.default
31+
.post(`${this.config.apiUrl}/builds`, data, this.axiosConfig)
32+
.then(function (response) {
33+
// handle success
34+
return response.data;
35+
})
36+
.catch(function (error) {
37+
// handle error
38+
return Promise.reject(error);
39+
});
40+
this.buildId = build.id;
41+
}
42+
});
43+
}
44+
submitTestResult(test) {
45+
return __awaiter(this, void 0, void 0, function* () {
46+
yield this.startBuild(this.config.projectId, this.config.branchName);
47+
const data = Object.assign({ buildId: this.buildId, projectId: this.config.projectId }, test);
48+
return axios_1.default
49+
.post(`${this.config.apiUrl}/test`, data, this.axiosConfig)
50+
.then(function (response) {
51+
// handle success
52+
return response.data;
53+
})
54+
.catch(function (error) {
55+
// handle error
56+
return Promise.reject(error);
57+
});
58+
});
59+
}
60+
}
61+
exports.VisualRegressionTracker = VisualRegressionTracker;

dist/types/build.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Build {
2+
id: string;
3+
}

dist/types/build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

dist/types/config.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface Config {
2+
apiUrl: string;
3+
branchName: string;
4+
projectId: string;
5+
token: string;
6+
}

dist/types/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

dist/types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './build';
2+
export * from './config';
3+
export * from './testRun';
4+
export * from './testRunResult';

dist/types/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

dist/types/testRun.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface TestRun {
2+
name: string;
3+
imageBase64: string;
4+
os?: string;
5+
browser?: string;
6+
viewport?: string;
7+
device?: string;
8+
diffTollerancePercent?: number;
9+
}

0 commit comments

Comments
 (0)