UNPKG

playwright-cucumber-ts-steps

Version:

A collection of reusable Playwright step definitions for Cucumber in TypeScript, designed to streamline end-to-end testing across web, API, and mobile applications.

21 lines (20 loc) 1.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.compareSnapshots = compareSnapshots; const fs_1 = __importDefault(require("fs")); const pixelmatch_1 = __importDefault(require("pixelmatch")); const pngjs_1 = require("pngjs"); function compareSnapshots({ actualPath, baselinePath, diffPath, threshold = 0.1, }) { const actual = pngjs_1.PNG.sync.read(fs_1.default.readFileSync(actualPath)); const baseline = pngjs_1.PNG.sync.read(fs_1.default.readFileSync(baselinePath)); if (actual.width !== baseline.width || actual.height !== baseline.height) { throw new Error("Snapshot size mismatch"); } const diff = new pngjs_1.PNG({ width: actual.width, height: actual.height }); const numDiffPixels = (0, pixelmatch_1.default)(actual.data, baseline.data, diff.data, actual.width, actual.height, { threshold }); fs_1.default.writeFileSync(diffPath, pngjs_1.PNG.sync.write(diff)); return numDiffPixels; }