Skip to content

Commit 8fdbd25

Browse files
committed
release v0.0.6
1 parent 73891cd commit 8fdbd25

17 files changed

+196
-135
lines changed

dist/index.d.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
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-
}
1+
export * from './visualRegressionTracker';
2+
export * from './types';

dist/index.js

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,7 @@
11
"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-
}
2+
function __export(m) {
3+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
604
}
61-
exports.VisualRegressionTracker = VisualRegressionTracker;
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
__export(require("./visualRegressionTracker"));
7+
__export(require("./types"));

dist/types/index.d.ts

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

dist/types/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
"use strict";
2+
function __export(m) {
3+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4+
}
25
Object.defineProperty(exports, "__esModule", { value: true });
6+
__export(require("./testRunStatus"));

dist/types/testRunResult.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { TestRunStatus } from "./";
12
export interface TestRunResult {
23
url: string;
3-
status: string;
4+
status: TestRunStatus;
45
pixelMisMatchCount: number;
56
diffPercent: number;
67
diffTollerancePercent: number;

dist/types/testRunStatus.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export declare enum TestRunStatus {
2+
new = "new",
3+
ok = "ok",
4+
unresolved = "unresolved"
5+
}

dist/types/testRunStatus.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var TestRunStatus;
4+
(function (TestRunStatus) {
5+
TestRunStatus["new"] = "new";
6+
TestRunStatus["ok"] = "ok";
7+
TestRunStatus["unresolved"] = "unresolved";
8+
})(TestRunStatus = exports.TestRunStatus || (exports.TestRunStatus = {}));

dist/visualRegressionTracker.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Config, TestRun } 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+
private submitTestResult;
10+
track(test: TestRun): Promise<void>;
11+
}

dist/visualRegressionTracker.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 types_1 = require("./types");
16+
const axios_1 = __importDefault(require("axios"));
17+
class VisualRegressionTracker {
18+
constructor(config) {
19+
this.config = config;
20+
this.axiosConfig = {
21+
headers: {
22+
apiKey: this.config.token,
23+
},
24+
};
25+
}
26+
startBuild(projectId, branchName) {
27+
return __awaiter(this, void 0, void 0, function* () {
28+
if (!this.buildId) {
29+
console.log("Starting new build");
30+
const data = { branchName, projectId };
31+
const build = yield axios_1.default
32+
.post(`${this.config.apiUrl}/builds`, data, this.axiosConfig)
33+
.then(function (response) {
34+
// handle success
35+
return response.data;
36+
})
37+
.catch(function (error) {
38+
// handle error
39+
return Promise.reject(error);
40+
});
41+
this.buildId = build.id;
42+
}
43+
});
44+
}
45+
submitTestResult(test) {
46+
return __awaiter(this, void 0, void 0, function* () {
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+
track(test) {
61+
return __awaiter(this, void 0, void 0, function* () {
62+
yield this.startBuild(this.config.projectId, this.config.branchName);
63+
const result = yield this.submitTestResult(test);
64+
if (result.status === types_1.TestRunStatus.new) {
65+
throw new Error(`No baseline: ${result.url}`);
66+
}
67+
if (result.status === types_1.TestRunStatus.unresolved) {
68+
throw new Error(`Difference found: ${result.url}`);
69+
}
70+
});
71+
}
72+
}
73+
exports.VisualRegressionTracker = VisualRegressionTracker;

examples/example.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { VisualRegressionTracker, Config } from "../";
1+
import { VisualRegressionTracker, Config } from "../lib";
22
import { readFileSync } from "fs";
33

44
describe("asd", () => {
55
const config: Config = {
66
apiUrl: "http://localhost:4200",
77
branchName: "develop",
8-
projectId: "a93c0341-cf31-48cf-a067-240e214ee39b",
9-
token: "3W7TJCZR2H4ADSM76Q1VYMBYVCA2",
8+
projectId: "76f0c443-9811-4f4f-b1c2-7c01c5775d9a",
9+
token: "F5Z2H0H2SNMXZVHX0EA4YQM1MGDD",
1010
};
1111
const vrt = new VisualRegressionTracker(config);
1212

1313
it("test 2", async () => {
14-
const testResult = await vrt.submitTestResult({
14+
const testResult = await vrt.track({
1515
name: "Example 2",
1616
// buildId: buildId,
1717
imageBase64: new Buffer(readFileSync("examples/1.png")).toString(
@@ -28,7 +28,7 @@ describe("asd", () => {
2828
});
2929

3030
it("test 1", async () => {
31-
const testResult = await vrt.submitTestResult({
31+
const testResult = await vrt.track({
3232
name: "Example 1",
3333
imageBase64: new Buffer(readFileSync("examples/1.png")).toString(
3434
"base64"
@@ -43,7 +43,7 @@ describe("asd", () => {
4343
});
4444

4545
it("test 1 chrome", async () => {
46-
const testResult = await vrt.submitTestResult({
46+
const testResult = await vrt.track({
4747
name: "Example 1",
4848
imageBase64: new Buffer(readFileSync("examples/1.png")).toString(
4949
"base64"

0 commit comments

Comments
 (0)