UNPKG

visreg-test

Version:

A visual regression testing solution that offers an easy setup with simple yet powerful customisation options, wrapped up in a convenient CLI runner to make assessing and accepting/rejecting diffs a breeze.

61 lines (60 loc) 3.13 kB
"use strict"; 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()); }); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runVisreg = void 0; const config_1 = require("./server/config"); const runVisreg = (props) => __awaiter(void 0, void 0, void 0, function* () { if (process.env.SEND_SUITE_CONF) { sendSuiteConf(props); } else { const { runTest } = yield Promise.resolve().then(() => require('./cypress/e2e/visual-regression-tests.cy.js')); runTest(props); } }); exports.runVisreg = runVisreg; const sendSuiteConf = (props) => { const api = `http://localhost:${config_1.serverPort}/api`; const stringifiedConfig = stringifyConfig(props); fetch(api + '/suite/deliver-suite-config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ testConfig: stringifiedConfig }), }) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.text(); }) .catch(error => { console.error('There was an error with the fetch operation:', error); }); }; const stringifyConfig = (props) => { const stringifiedEndpoints = props.endpoints.map(endpoint => { const { onBeforeVisit, onVisit, onAfterVisit } = endpoint, rest = __rest(endpoint, ["onBeforeVisit", "onVisit", "onAfterVisit"]); return Object.assign(Object.assign(Object.assign(Object.assign({}, rest), onBeforeVisit ? { onBeforeVisit: onBeforeVisit.toString() } : {}), onVisit ? { onVisit: onVisit.toString() } : {}), onAfterVisit ? { onAfterVisit: onAfterVisit.toString() } : {}); }); const stringifiedConfig = Object.assign(Object.assign(Object.assign(Object.assign({}, props), props.formatUrl ? { formatUrl: props.formatUrl.toString() } : {}), props.onVisit ? { onVisit: props.onVisit.toString() } : {}), { endpoints: stringifiedEndpoints }); return stringifiedConfig; };