Skip to content

Commit 24fe10e

Browse files
authored
update jspdf to 4, cypress to 15 and use alternative image comparison for e2e (#175)
1 parent ba1326c commit 24fe10e

File tree

4 files changed

+3495
-2808
lines changed

4 files changed

+3495
-2808
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ umd
1010
cypress/downloads
1111
cypress/baseline/diff
1212
cypress/baseline/png
13+
cypress/baseline/__snapshots__
1314
cypress/screenshots
1415
coverage/
1516
.playwright/

cypress.config.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
import path from "path";
22
import { defineConfig } from "cypress";
3-
import ComparePdf, { ComparePdfConfig } from "compare-pdf";
3+
import { comparePdfToSnapshot } from "pdf-visual-diff";
44

5-
const comparePDFConfig: ComparePdfConfig = {
6-
paths: {
7-
actualPdfRootFolder: path.join(process.cwd(), "cypress", "downloads"),
8-
baselinePdfRootFolder: path.join(process.cwd(), "cypress", "baseline"),
9-
actualPngRootFolder: path.join(
10-
process.cwd(),
11-
"cypress",
12-
"downloads",
13-
"png"
14-
),
15-
baselinePngRootFolder: path.join(
16-
process.cwd(),
17-
"cypress",
18-
"baseline",
19-
"png"
20-
),
21-
diffPngRootFolder: path.join(process.cwd(), "cypress", "baseline", "diff"),
22-
},
23-
settings: {
24-
imageEngine: "native",
25-
density: 150,
26-
quality: 80,
27-
tolerance: 0,
28-
threshold: 0.1,
29-
cleanPngPaths: false,
30-
matchPageCount: true,
31-
disableFontFace: true,
32-
verbosity: 0,
33-
},
34-
};
5+
interface ComparisonResult {
6+
status: "passed" | "failed";
7+
message?: string;
8+
}
359

3610
export default defineConfig({
3711
e2e: {
3812
setupNodeEvents(on) {
3913
on("task", {
40-
async compareFile(filename: string) {
41-
const comparisonResults = await new ComparePdf(comparePDFConfig)
42-
.actualPdfFile(filename)
43-
.baselinePdfFile(filename)
44-
.compare();
45-
return comparisonResults;
14+
async compareFile(filename: string): Promise<ComparisonResult> {
15+
const actualPath = path.join(process.cwd(), "cypress", "downloads", filename);
16+
const snapshotDir = path.join(process.cwd(), "cypress", "baseline");
17+
18+
try {
19+
// comparePdfToSnapshot returns true if PDFs match, false if they don't
20+
const matches = await comparePdfToSnapshot(
21+
actualPath,
22+
snapshotDir,
23+
filename,
24+
{
25+
tolerance: 0.1,
26+
pdf2PngOptions: {
27+
dpi: 150,
28+
},
29+
}
30+
);
31+
32+
if (matches) {
33+
return { status: "passed" };
34+
} else {
35+
return {
36+
status: "failed",
37+
message: `PDF comparison failed: ${filename} does not match baseline`,
38+
};
39+
}
40+
} catch (error) {
41+
return {
42+
status: "failed",
43+
message: `PDF comparison error: ${error instanceof Error ? error.message : String(error)}`,
44+
};
45+
}
4646
},
4747
});
4848
},

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"clean": "rimraf dist",
2727
"docs": "typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts src/types.ts src/constants.ts",
2828
"test": "npm run lint && vitest run",
29+
"test:e2e": "cypress run",
30+
"test:e2e:open": "cypress open",
2931
"lint": "eslint . && prettier -c .",
3032
"release": "release-it",
3133
"prerelease": "npm run clean && npm run build",
@@ -40,11 +42,11 @@
4042
"@typescript-eslint/parser": "^5.59.0",
4143
"@vitejs/plugin-react": "^4.3.4",
4244
"canvas": "^3.1.0",
43-
"compare-pdf": "^1.1.8",
44-
"cypress": "^13.1.0",
45+
"cypress": "^15.8.1",
4546
"eslint": "^8.39.0",
4647
"eslint-plugin-react": "^7.32.2",
4748
"jsdom": "^26.0.0",
49+
"pdf-visual-diff": "^0.15.2",
4850
"prettier": "^2.8.4",
4951
"process": "^0.11.10",
5052
"react": "^16.8",
@@ -65,7 +67,7 @@
6567
},
6668
"dependencies": {
6769
"html2canvas": "^1.4.1",
68-
"jspdf": "^3.0.4"
70+
"jspdf": "^4.0.0"
6971
},
7072
"publishConfig": {
7173
"registry": "https://registry.npmjs.org/"

0 commit comments

Comments
 (0)