UNPKG

pdf-visual-diff

Version:

Visual Regression Testing for PDFs in JavaScript

57 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const node_test_1 = require("node:test"); const assert = require("node:assert/strict"); const path_1 = require("path"); const pdf2png_1 = require("./pdf2png"); const compare_images_1 = require("../compare-images"); const types_1 = require("../types"); const testDataDir = (0, path_1.join)(__dirname, '../test-data'); const pdfs = (0, path_1.join)(testDataDir, 'pdfs'); const singlePage = (0, path_1.join)(pdfs, 'single-page.pdf'); const twoPage = (0, path_1.join)(pdfs, 'two-page.pdf'); const cmaps = (0, path_1.join)(pdfs, 'cmaps.pdf'); const expectedDir = (0, path_1.join)(testDataDir, 'pdf2png-expected'); (0, node_test_1.describe)('pdf2png()', () => { (0, node_test_1.it)('two-page.pdf png per page with scaling', () => { const expectedImage1Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_scaled_1.png'); const expectedImage2Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_scaled_2.png'); return (0, pdf2png_1.pdf2png)(twoPage, { dpi: types_1.Dpi.High }) .then((imgs) => { return Promise.all([ (0, compare_images_1.compareImages)(expectedImage1Path, [imgs[0]]), (0, compare_images_1.compareImages)(expectedImage2Path, [imgs[1]]), ]); }) .then((results) => { results.forEach((x) => assert.strictEqual(x.equal, true)); }); }); (0, node_test_1.it)('two-page.pdf png per page and without scaling', () => { const expectedImage1Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_1.png'); const expectedImage2Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_2.png'); return (0, pdf2png_1.pdf2png)(twoPage, { dpi: types_1.Dpi.Low }) .then((imgs) => { return Promise.all([ (0, compare_images_1.compareImages)(expectedImage1Path, [imgs[0]]), (0, compare_images_1.compareImages)(expectedImage2Path, [imgs[1]]), ]); }) .then((results) => { results.forEach((x) => assert.strictEqual(x.equal, true)); }); }); (0, node_test_1.it)('should scale using custom DPI', () => { const expectedImagePath = (0, path_1.join)(expectedDir, 'should_scale_using_custom_DPI.png'); return (0, pdf2png_1.pdf2png)(singlePage, { dpi: 200 }) .then((imgs) => (0, compare_images_1.compareImages)(expectedImagePath, imgs)) .then((result) => assert.strictEqual(result.equal, true)); }); (0, node_test_1.it)('pdf that requires cmaps', () => { const expectedImagePath = (0, path_1.join)(expectedDir, 'cmaps.png'); return (0, pdf2png_1.pdf2png)(cmaps) .then((imgs) => (0, compare_images_1.compareImages)(expectedImagePath, imgs)) .then((result) => assert.strictEqual(result.equal, true)); }); }); //# sourceMappingURL=pdf2png.test.js.map