|
| 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; |
0 commit comments