pdf-visual-compare 0.0.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/compare.pdf.d.ts +1 -1
- package/out/compare.pdf.js +26 -18
- package/out/compare.pdf.js.map +1 -1
- package/out/index.js +5 -1
- package/out/index.js.map +1 -1
- package/out/types/compare.options.d.ts +3 -2
- package/out/types/excluded.page.area.d.ts +1 -1
- package/package.json +14 -14
package/out/compare.pdf.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ComparePdfOptions } from './types';
|
|
2
|
-
export default function comparePdf(
|
|
2
|
+
export default function comparePdf(actualPdfFilePathOrBuffer: string | ArrayBufferLike, expectedPdfFilePathOrBuffer: string | ArrayBufferLike, opts?: ComparePdfOptions): Promise<boolean>;
|
package/out/compare.pdf.js
CHANGED
|
@@ -7,35 +7,43 @@ const fs_1 = require("fs");
|
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const pdf_to_png_converter_1 = require("pdf-to-png-converter");
|
|
9
9
|
const png_visual_compare_1 = __importDefault(require("png-visual-compare"));
|
|
10
|
-
async function comparePdf(
|
|
11
|
-
|
|
12
|
-
if (!(0, fs_1.existsSync)(actualPdfFilePathResolved)) {
|
|
10
|
+
async function comparePdf(actualPdfFilePathOrBuffer, expectedPdfFilePathOrBuffer, opts) {
|
|
11
|
+
if (!Buffer.isBuffer(actualPdfFilePathOrBuffer) && !(0, fs_1.existsSync)(actualPdfFilePathOrBuffer)) {
|
|
13
12
|
throw Error('Actual PDF file not found.');
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
if (!(0, fs_1.existsSync)(expectedPdfFilePathResolved)) {
|
|
14
|
+
if (!Buffer.isBuffer(expectedPdfFilePathOrBuffer) && !(0, fs_1.existsSync)(expectedPdfFilePathOrBuffer)) {
|
|
17
15
|
throw Error('Expected PDF file not found.');
|
|
18
16
|
}
|
|
19
|
-
const pdfToPngConvertOpts = opts?.pdfToPngConvertOptions ?? {
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const pdfToPngConvertOpts = opts?.pdfToPngConvertOptions ?? {
|
|
18
|
+
viewportScale: 2.0,
|
|
19
|
+
outputFileMask: 'comparePdf',
|
|
20
|
+
};
|
|
21
|
+
const diffsOutputFolder = opts?.diffsOutputFolder
|
|
22
|
+
? opts.diffsOutputFolder
|
|
23
|
+
: (0, path_1.resolve)(`./comparePdfOutput`);
|
|
24
|
+
const compareThreshold = opts?.compareThreshold
|
|
25
|
+
? opts?.compareThreshold
|
|
26
|
+
: 0;
|
|
27
|
+
const excludedAreas = opts?.excludedAreas
|
|
28
|
+
? opts.excludedAreas
|
|
29
|
+
: [];
|
|
30
|
+
if (compareThreshold < 0) {
|
|
31
|
+
throw Error('Compare Threshold cannot be less than 0.');
|
|
32
|
+
}
|
|
22
33
|
const [actualPdfPngPages, expectedPdfPngPages] = await Promise.all([
|
|
23
|
-
(0, pdf_to_png_converter_1.pdfToPng)(
|
|
24
|
-
(0, pdf_to_png_converter_1.pdfToPng)(
|
|
34
|
+
(0, pdf_to_png_converter_1.pdfToPng)(actualPdfFilePathOrBuffer, pdfToPngConvertOpts),
|
|
35
|
+
(0, pdf_to_png_converter_1.pdfToPng)(expectedPdfFilePathOrBuffer, pdfToPngConvertOpts),
|
|
25
36
|
]);
|
|
26
37
|
if (actualPdfPngPages.length !== expectedPdfPngPages.length) {
|
|
27
38
|
return false;
|
|
28
39
|
}
|
|
29
40
|
let overallCompareResult = true;
|
|
30
|
-
const diffsOutputFolder = opts?.diffsOutputFolder ?? (0, path_1.resolve)(`./test-results/comparePdf/${(0, path_1.parse)(actualPdfFilePathResolved).base}_vs_${(0, path_1.parse)(expectedPdfFilePath).base}`);
|
|
31
41
|
actualPdfPngPages.forEach((actualPdfPngPage, index) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const compareResult = (0, png_visual_compare_1.default)(actualPdfPngPage.content, expectedPdfPngPages.find((expectedPdfPngPage) => expectedPdfPngPage.name === actualPdfPngPage.name).content, comparePngOpts);
|
|
38
|
-
if (compareResult > 0) {
|
|
42
|
+
const comparePngOpts = { ...opts?.pdfToPngConvertOptions, ...excludedAreas[index] };
|
|
43
|
+
comparePngOpts.diffFilePath = (0, path_1.resolve)(diffsOutputFolder, `diff_${actualPdfPngPage.name}`);
|
|
44
|
+
const expectedPdfPngPage = expectedPdfPngPages.find((expectedPdfPngPage) => expectedPdfPngPage.name === actualPdfPngPage.name);
|
|
45
|
+
const compareResult = (0, png_visual_compare_1.default)(actualPdfPngPage.content, expectedPdfPngPage.content, comparePngOpts);
|
|
46
|
+
if (compareResult > compareThreshold) {
|
|
39
47
|
overallCompareResult = false;
|
|
40
48
|
}
|
|
41
49
|
});
|
package/out/compare.pdf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.pdf.js","sourceRoot":"","sources":["../src/compare.pdf.ts"],"names":[],"mappings":";;;;;AAAA,2BAAgC;AAChC,+
|
|
1
|
+
{"version":3,"file":"compare.pdf.js","sourceRoot":"","sources":["../src/compare.pdf.ts"],"names":[],"mappings":";;;;;AAAA,2BAAgC;AAChC,+BAA+B;AAC/B,+DAA+D;AAC/D,4EAAmE;AAGpD,KAAK,UAAU,UAAU,CACtC,yBAAmD,EACnD,2BAAqD,EACrD,IAAwB;IAExB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAA,eAAU,EAAC,yBAAmC,CAAC,EAAE;QACnG,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAC;KAC3C;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAA,eAAU,EAAC,2BAAqC,CAAC,EAAE;QACvG,MAAM,KAAK,CAAC,8BAA8B,CAAC,CAAC;KAC7C;IAED,MAAM,mBAAmB,GAAoB,IAAI,EAAE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,EAAE,CAAC,kBAAkB,CAAC,IAAI,KAAK,gBAAgB,CAAC,IAAI,CACzD,CAAC;QACnB,MAAM,aAAa,GAAW,IAAA,4BAAU,EAAC,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAE/G,IAAI,aAAa,GAAG,gBAAgB,EAAE;YACpC,oBAAoB,GAAG,KAAK,CAAC;SAC9B;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAvDD,6BAuDC"}
|
package/out/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,gEAAuC;AACvC,kBAAe,qBAAU,CAAC;AAC1B,0CAAwB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExcludedPageArea, PdfToPngOptions } from '.';
|
|
2
2
|
export declare type ComparePdfOptions = {
|
|
3
3
|
diffsOutputFolder?: string;
|
|
4
4
|
pdfToPngConvertOptions?: PdfToPngOptions;
|
|
5
|
-
excludedAreas
|
|
5
|
+
excludedAreas?: ExcludedPageArea[];
|
|
6
|
+
compareThreshold?: number;
|
|
6
7
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-visual-compare",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Visual regression testing library for PDFs in Js/Ts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Visual regression testing library for PDFs in Js/Ts without binary and OS dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pdf",
|
|
7
7
|
"pdf regression",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"clean": "rimraf ./out ./coverage ./test-results",
|
|
29
29
|
"docker:build": "docker build --compress -t test-pdf-visual-compare .",
|
|
30
30
|
"predocker:run": "npm run clean",
|
|
31
|
-
"docker:run": "docker run --rm -it -v
|
|
31
|
+
"docker:run": "docker run --rm -it -v ./test-results:/usr/pkg/test-results test-pdf-visual-compare",
|
|
32
32
|
"docker:test": "jest",
|
|
33
33
|
"license-checker": "npx license-checker --production --onlyAllow 'MIT; MIT OR X11; BSD; ISC; Apache-2.0; Unlicense'",
|
|
34
34
|
"lint": "eslint .",
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"tsc": "tsc --pretty"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"pdf-to-png-converter": "0.
|
|
43
|
-
"png-visual-compare": "0.4.
|
|
42
|
+
"pdf-to-png-converter": "1.0.0",
|
|
43
|
+
"png-visual-compare": "0.4.12"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/jest": "27.
|
|
47
|
-
"@types/node": "17.0.
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
49
|
-
"@typescript-eslint/parser": "5.
|
|
50
|
-
"eslint": "8.
|
|
51
|
-
"jest": "
|
|
52
|
-
"ts-jest": "
|
|
53
|
-
"ts-node": "10.
|
|
54
|
-
"typescript": "4.
|
|
46
|
+
"@types/jest": "27.5.0",
|
|
47
|
+
"@types/node": "17.0.31",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "5.22.0",
|
|
49
|
+
"@typescript-eslint/parser": "5.22.0",
|
|
50
|
+
"eslint": "8.15.0",
|
|
51
|
+
"jest": "28.1.0",
|
|
52
|
+
"ts-jest": "28.0.1",
|
|
53
|
+
"ts-node": "10.7.0",
|
|
54
|
+
"typescript": "4.6.4"
|
|
55
55
|
}
|
|
56
56
|
}
|