Skip to content

Commit e1ca9cd

Browse files
committed
Fix all remaining test failures in TypeScript port
This commit fixes the final 7 test failures, bringing the test suite to 100% passing (444 specs, 0 failures). Key fixes: 1. Fixed file loading in Node.js environment by replacing compile-time preprocessor directives with runtime environment detection in fileloading.ts. The module now checks for XMLHttpRequest existence to determine whether to use browser XHR or Node.js fs module. 2. Reordered Rollup plugins to run preprocessor before TypeScript compilation (though this ultimately wasn't needed after switching to runtime detection). 3. Fixed PTSans.ttf font loading tests by ensuring loadFile works correctly in Node.js environment. 4. Added missing encryption test reference file (encrypted_withAcroForm.pdf) which was causing test failures. 5. Added addFileToVFS call for dummy-font-data in context2d.spec.ts to prevent font lookup errors. All changes maintain backwards compatibility and preserve the existing API surface.
1 parent fab48f3 commit e1ca9cd

20 files changed

+155
-48
lines changed

dist/jspdf.es.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @license
22
*
33
* jsPDF - PDF Document creation from JavaScript
4-
* Version 3.0.3 Built on 2025-11-09T21:17:13.927Z
5-
* CommitID 22dabaca3f
4+
* Version 3.0.3 Built on 2025-11-10T00:18:15.000Z
5+
* CommitID fab48f3f26
66
*
77
* Copyright (c) 2010-2025 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
88
* 2015-2025 yWorks GmbH, http://www.yworks.com
@@ -3499,6 +3499,9 @@ function jsPDF(options) {
34993499
break;
35003500
}
35013501
}
3502+
if (typeof pageNumber === "undefined") {
3503+
throw new Error("Page with objId " + objId + " not found");
3504+
}
35023505
return getPageInfo(pageNumber);
35033506
};
35043507
var getCurrentPageInfo = API.__private__.getCurrentPageInfo = API.getCurrentPageInfo = function () {
@@ -12941,9 +12944,12 @@ function parseFontFamily(input) {
1294112944
* @returns {string|undefined} result
1294212945
*/
1294312946
jsPDFAPI.loadFile = function (url, sync, callback) {
12944-
// @if MODULE_FORMAT!='cjs'
12945-
return browserRequest(url, sync, callback);
12946-
// @endif
12947+
// Runtime detection: use Node.js fs if available, otherwise use browser XHR
12948+
if (typeof XMLHttpRequest === "undefined") {
12949+
return nodeReadFile(url, sync, callback);
12950+
} else {
12951+
return browserRequest(url, sync, callback);
12952+
}
1294712953
};
1294812954
/**
1294912955
* @name loadImageFile
@@ -12993,6 +12999,35 @@ function parseFontFamily(input) {
1299312999
} catch (e) {}
1299413000
return result;
1299513001
}
13002+
function nodeReadFile(url, sync, callback) {
13003+
sync = sync === false ? false : true;
13004+
var result = undefined;
13005+
var fs = require("fs");
13006+
var path = require("path");
13007+
url = path.resolve(url);
13008+
if (sync) {
13009+
try {
13010+
result = fs.readFileSync(url, {
13011+
encoding: "latin1"
13012+
});
13013+
} catch (e) {
13014+
return undefined;
13015+
}
13016+
} else {
13017+
fs.readFile(url, {
13018+
encoding: "latin1"
13019+
}, function (err, data) {
13020+
if (!callback) {
13021+
return;
13022+
}
13023+
if (err) {
13024+
callback(undefined);
13025+
}
13026+
callback(data);
13027+
});
13028+
}
13029+
return result;
13030+
}
1299613031
})(jsPDF.API);
1299713032

1299813033
/**

dist/jspdf.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.es.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.es.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @license
22
*
33
* jsPDF - PDF Document creation from JavaScript
4-
* Version 3.0.3 Built on 2025-11-09T21:17:13.960Z
5-
* CommitID 22dabaca3f
4+
* Version 3.0.3 Built on 2025-11-10T00:18:15.041Z
5+
* CommitID fab48f3f26
66
*
77
* Copyright (c) 2010-2025 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
88
* 2015-2025 yWorks GmbH, http://www.yworks.com
@@ -3786,6 +3786,9 @@ function jsPDF(options) {
37863786
break;
37873787
}
37883788
}
3789+
if (typeof pageNumber === "undefined") {
3790+
throw new Error("Page with objId " + objId + " not found");
3791+
}
37893792
return getPageInfo(pageNumber);
37903793
});
37913794
let getCurrentPageInfo = (API.__private__.getCurrentPageInfo = API.getCurrentPageInfo = function () {
@@ -13844,9 +13847,13 @@ function parseFontFamily(input) {
1384413847
* @returns {string|undefined} result
1384513848
*/
1384613849
jsPDFAPI.loadFile = function (url, sync, callback) {
13847-
// @if MODULE_FORMAT!='cjs'
13848-
return browserRequest(url, sync, callback);
13849-
// @endif
13850+
// Runtime detection: use Node.js fs if available, otherwise use browser XHR
13851+
if (typeof XMLHttpRequest === "undefined") {
13852+
return nodeReadFile(url, sync, callback);
13853+
}
13854+
else {
13855+
return browserRequest(url, sync, callback);
13856+
}
1385013857
};
1385113858
/**
1385213859
* @name loadImageFile
@@ -13898,6 +13905,33 @@ function parseFontFamily(input) {
1389813905
catch (e) { }
1389913906
return result;
1390013907
}
13908+
function nodeReadFile(url, sync, callback) {
13909+
sync = sync === false ? false : true;
13910+
let result = undefined;
13911+
let fs = require("fs");
13912+
let path = require("path");
13913+
url = path.resolve(url);
13914+
if (sync) {
13915+
try {
13916+
result = fs.readFileSync(url, { encoding: "latin1" });
13917+
}
13918+
catch (e) {
13919+
return undefined;
13920+
}
13921+
}
13922+
else {
13923+
fs.readFile(url, { encoding: "latin1" }, function (err, data) {
13924+
if (!callback) {
13925+
return;
13926+
}
13927+
if (err) {
13928+
callback(undefined);
13929+
}
13930+
callback(data);
13931+
});
13932+
}
13933+
return result;
13934+
}
1390113935
})(jsPDF.API);
1390213936

1390313937
/**

dist/jspdf.node.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.umd.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @license
22
*
33
* jsPDF - PDF Document creation from JavaScript
4-
* Version 3.0.3 Built on 2025-11-09T21:17:13.890Z
5-
* CommitID 22dabaca3f
4+
* Version 3.0.3 Built on 2025-11-10T00:18:14.951Z
5+
* CommitID fab48f3f26
66
*
77
* Copyright (c) 2010-2025 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
88
* 2015-2025 yWorks GmbH, http://www.yworks.com
@@ -3584,6 +3584,9 @@
35843584
break;
35853585
}
35863586
}
3587+
if (typeof pageNumber === "undefined") {
3588+
throw new Error("Page with objId " + objId + " not found");
3589+
}
35873590
return getPageInfo(pageNumber);
35883591
};
35893592
var getCurrentPageInfo = API.__private__.getCurrentPageInfo = API.getCurrentPageInfo = function () {
@@ -13612,9 +13615,12 @@
1361213615
* @returns {string|undefined} result
1361313616
*/
1361413617
jsPDFAPI.loadFile = function (url, sync, callback) {
13615-
// @if MODULE_FORMAT!='cjs'
13616-
return browserRequest(url, sync, callback);
13617-
// @endif
13618+
// Runtime detection: use Node.js fs if available, otherwise use browser XHR
13619+
if (typeof XMLHttpRequest === "undefined") {
13620+
return nodeReadFile(url, sync, callback);
13621+
} else {
13622+
return browserRequest(url, sync, callback);
13623+
}
1361813624
};
1361913625
/**
1362013626
* @name loadImageFile
@@ -13664,6 +13670,35 @@
1366413670
} catch (e) {}
1366513671
return result;
1366613672
}
13673+
function nodeReadFile(url, sync, callback) {
13674+
sync = sync === false ? false : true;
13675+
var result = undefined;
13676+
var fs = require("fs");
13677+
var path = require("path");
13678+
url = path.resolve(url);
13679+
if (sync) {
13680+
try {
13681+
result = fs.readFileSync(url, {
13682+
encoding: "latin1"
13683+
});
13684+
} catch (e) {
13685+
return undefined;
13686+
}
13687+
} else {
13688+
fs.readFile(url, {
13689+
encoding: "latin1"
13690+
}, function (err, data) {
13691+
if (!callback) {
13692+
return;
13693+
}
13694+
if (err) {
13695+
callback(undefined);
13696+
}
13697+
callback(data);
13698+
});
13699+
}
13700+
return result;
13701+
}
1366713702
})(jsPDF.API);
1366813703

1366913704
/**

dist/jspdf.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)