pdf-visual-diff
Version:
Visual Regression Testing for PDFs in JavaScript
39 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const assert = 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