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.
65 lines (64 loc) • 3.16 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getImage = void 0;
const path = require("path");
const utils_1 = require("../../utils");
const config_1 = require("../config");
const fetch_suite_config_1 = require("./fetch-suite-config");
const getImage = (fileInfo) => __awaiter(void 0, void 0, void 0, function* () {
const { filePath, cleanName, suiteImagesDir, type, suiteSlug, fileName } = fileInfo;
const { createdAt, modifiedAt } = (0, utils_1.getFileInfo)(filePath);
const siblingPaths = [];
const baselinePath = path.join(suiteImagesDir, cleanName + '.base.png');
const receivedPath = path.join(suiteImagesDir, '__received_output__', cleanName + '-received.png');
const diffPath = path.join(suiteImagesDir, '__diff_output__', cleanName + '.diff.png');
if ((0, utils_1.pathExists)(baselinePath)) {
siblingPaths.push({
type: 'baseline',
previewUrl: `/suite/${suiteSlug}/images/baseline/${cleanName}.base.png`
});
}
if ((0, utils_1.pathExists)(diffPath)) {
siblingPaths.push({
type: 'diff',
previewUrl: `/suite/${suiteSlug}/images/diff/${cleanName}.diff.png`
});
}
if ((0, utils_1.pathExists)(receivedPath)) {
siblingPaths.push({
type: 'received',
previewUrl: `/suite/${suiteSlug}/images/received/${cleanName}-received.png`
});
}
const suiteConfig = yield (0, fetch_suite_config_1.fetchSuiteConfig)(suiteSlug);
const endpoint = suiteConfig === null || suiteConfig === void 0 ? void 0 : suiteConfig.endpoints.find((endpoint) => {
return endpoint.title === cleanName.slice(0, cleanName.indexOf(' @'));
});
const fullUrl = ((suiteConfig === null || suiteConfig === void 0 ? void 0 : suiteConfig.baseUrl) || '') + ((endpoint === null || endpoint === void 0 ? void 0 : endpoint.path) || '');
const image = {
suiteName: suiteSlug,
name: cleanName,
fileName: fileName,
createdAt,
modifiedAt,
type,
sizeString: (0, utils_1.getHumanReadableFileSize)(filePath),
fileUrl: `http://localhost:${config_1.serverPort}/images/${suiteSlug}/${type}/${fileName}`,
path: filePath,
siblingPaths,
endpoint,
baseUrl: suiteConfig === null || suiteConfig === void 0 ? void 0 : suiteConfig.baseUrl,
fullUrl,
};
return image;
});
exports.getImage = getImage;