Merge pull request #19358 from Snuffleupagus/Node-enable-web_pdfjsLib

Enable the "checks that the viewer re-exports the expected API functionality" unit-test in Node.js
This commit is contained in:
Tim van der Meij 2025-01-26 16:45:51 +01:00 committed by GitHub
commit 09a0a0f06f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 21 deletions

View File

@ -1952,20 +1952,25 @@ function createBaseline(done) {
gulp.task( gulp.task(
"unittestcli", "unittestcli",
gulp.series(setTestEnv, "lib-legacy", function runUnitTestCli(done) { gulp.series(
const options = [ setTestEnv,
"node_modules/jasmine/bin/jasmine", "generic-legacy",
"JASMINE_CONFIG_PATH=test/unit/clitests.json", "lib-legacy",
]; function runUnitTestCli(done) {
const jasmineProcess = startNode(options, { stdio: "inherit" }); const options = [
jasmineProcess.on("close", function (code) { "node_modules/jasmine/bin/jasmine",
if (code !== 0) { "JASMINE_CONFIG_PATH=test/unit/clitests.json",
done(new Error("Unit tests failed.")); ];
return; const jasmineProcess = startNode(options, { stdio: "inherit" });
} jasmineProcess.on("close", function (code) {
done(); if (code !== 0) {
}); done(new Error("Unit tests failed."));
}) return;
}
done();
});
}
)
); );
gulp.task("lint", function (done) { gulp.task("lint", function (done) {

View File

@ -22,7 +22,6 @@ import {
FeatureTest, FeatureTest,
ImageKind, ImageKind,
InvalidPDFException, InvalidPDFException,
isNodeJS,
normalizeUnicode, normalizeUnicode,
OPS, OPS,
PasswordResponses, PasswordResponses,
@ -129,13 +128,20 @@ describe("pdfjs_api", function () {
describe("web_pdfjsLib", function () { describe("web_pdfjsLib", function () {
it("checks that the viewer re-exports the expected API functionality", async function () { it("checks that the viewer re-exports the expected API functionality", async function () {
if (isNodeJS) { // Load the API globally, as the viewer does.
pending("loadScript is not supported in Node.js."); // eslint-disable-next-line no-unsanitized/method
} await import(
const apiPath = "../../build/generic/build/pdf.mjs"; typeof PDFJSDev !== "undefined" && PDFJSDev.test("LIB")
await import(apiPath); ? "../../../generic-legacy/build/pdf.mjs"
: "../../build/generic/build/pdf.mjs"
);
const webPdfjsLib = await import("../../web/pdfjs.js"); // eslint-disable-next-line no-unsanitized/method
const webPdfjsLib = await import(
typeof PDFJSDev !== "undefined" && PDFJSDev.test("LIB")
? "../../../../web/pdfjs.js"
: "../../web/pdfjs.js"
);
expect(Object.keys(webPdfjsLib).sort()).toEqual( expect(Object.keys(webPdfjsLib).sort()).toEqual(
Object.keys(expectedAPI).sort() Object.keys(expectedAPI).sort()