pdf-visual-diff
Version:
Visual Regression Testing for PDFs in JavaScript
72 lines • 3.76 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const assert = __importStar(require("node:assert/strict"));
const compare_images_1 = require("./compare-images");
const path_1 = require("path");
const fs_1 = require("fs");
const jimp_1 = require("jimp");
(0, node_test_1.describe)('mkDiffPath()', () => {
(0, node_test_1.it)('should mk path with extension', () => assert.strictEqual((0, compare_images_1.mkDiffPath)('some-path.ext'), 'some-path.diff.ext'));
(0, node_test_1.it)('should mk path with extension when starts with .', () => assert.strictEqual((0, compare_images_1.mkDiffPath)('./some-path.ext'), './some-path.diff.ext'));
(0, node_test_1.it)('should handle empty', () => assert.strictEqual((0, compare_images_1.mkDiffPath)(''), '.diff'));
(0, node_test_1.it)('should mk path without extension', () => assert.strictEqual((0, compare_images_1.mkDiffPath)('some-path'), 'some-path.diff'));
});
const expectedImageName = 'sample-image-expected.png';
const sampleImage = 'sample-image.png';
const sampleImage2 = 'sample-image-2.png';
const testDataDir = (0, path_1.join)(__dirname, './test-data');
const expectedImagePath = (0, path_1.join)(testDataDir, expectedImageName);
const imagePath = (0, path_1.join)(testDataDir, sampleImage);
const image2Path = (0, path_1.join)(testDataDir, sampleImage2);
(0, node_test_1.describe)('compareImages()', () => {
(0, node_test_1.it)('should succeed comparing', () => jimp_1.Jimp.read(imagePath)
.then((x) => x)
.then((img) => (0, compare_images_1.compareImages)(expectedImagePath, [img]))
.then((x) => {
assert.strictEqual(x.equal, true);
assert.strictEqual((0, fs_1.existsSync)((0, compare_images_1.mkDiffPath)(imagePath)), false, 'should not generate diff output');
}));
(0, node_test_1.it)('should fail comparing and output diff', () => jimp_1.Jimp.read(image2Path)
.then((x) => x)
.then((img) => (0, compare_images_1.compareImages)(expectedImagePath, [img]))
.then((x) => {
assert.strictEqual(x.equal, false);
assert.ok(x.diffs && x.diffs[0] && 'diff' in x.diffs[0], "Expected 'diffs[0].diff' to exist");
assert.ok(x.diffs && x.diffs[0] && 'page' in x.diffs[0], "Expected 'diffs[0].page' to exist");
}));
});
//# sourceMappingURL=compare-images.test.js.map