UNPKG

@visual-regression-tracker/agent-codeceptjs

Version:

Custom helper to integrate CondeceptJS with Visual Regression Tracker

76 lines (75 loc) 3.04 kB
"use strict"; /* global codecept_helper */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; const Helper = codecept_helper; const fs_1 = require("fs"); const path_1 = require("path"); const sdk_js_1 = require("@visual-regression-tracker/sdk-js"); var DRIVERS; (function (DRIVERS) { DRIVERS["Playwright"] = "Playwright"; DRIVERS["Puppeteer"] = "Puppeteer"; DRIVERS["WebDriver"] = "WebDriver"; DRIVERS["Appium"] = "Appium"; DRIVERS["WebDriverIO"] = "WebDriverIO"; DRIVERS["TestCafe"] = "TestCafe"; })(DRIVERS || (DRIVERS = {})); class VisualRegressionTrackerHelper extends Helper { constructor(config) { super(); this.vrt = new sdk_js_1.VisualRegressionTracker(config); } vrtStart() { return __awaiter(this, void 0, void 0, function* () { return this.vrt.start(); }); } vrtStop() { return __awaiter(this, void 0, void 0, function* () { return this.vrt.stop(); }); } /** * @param name {String} name of the page you want to track * @param options {TrackOptions} options */ vrtTrack(name, options) { return __awaiter(this, void 0, void 0, function* () { const helper = this._getHelper(); const filepath = path_1.join(__dirname, `${name}-${Date.now()}.png`); const image = yield helper.saveScreenshot(filepath, options === null || options === void 0 ? void 0 : options.fullScreen); fs_1.unlinkSync(filepath); return this.vrt.track(Object.assign({ name, imageBase64: image.toString("base64") }, options)); }); } _getHelper() { if (this.helpers[DRIVERS.Puppeteer]) { return this.helpers[DRIVERS.Puppeteer]; } if (this.helpers[DRIVERS.WebDriver]) { return this.helpers[DRIVERS.WebDriver]; } if (this.helpers[DRIVERS.Appium]) { return this.helpers[DRIVERS.Appium]; } if (this.helpers[DRIVERS.WebDriverIO]) { return this.helpers[DRIVERS.WebDriverIO]; } if (this.helpers[DRIVERS.TestCafe]) { return this.helpers[DRIVERS.TestCafe]; } if (this.helpers[DRIVERS.Playwright]) { return this.helpers[DRIVERS.Playwright]; } throw new Error("Not supported driver"); } } module.exports = VisualRegressionTrackerHelper;