Merge pull request #16658 from Snuffleupagus/test-more-APIs

Add unit-tests to check that more PDF.js APIs expose the expected functionality
This commit is contained in:
Jonas Jenwald 2023-07-08 08:16:57 +02:00 committed by GitHub
commit 5696c3aa3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 84 additions and 5 deletions

View File

@ -1559,7 +1559,7 @@ function buildLib(defines, dir) {
[
"src/{core,display,shared}/**/*.js",
"!src/shared/{cffStandardStrings,fonts_utils}.js",
"src/{pdf,pdf.worker}.js",
"src/{pdf,pdf.image_decoders,pdf.worker}.js",
],
{ base: "src/" }
),

View File

@ -18,10 +18,12 @@ import { Jbig2Image } from "./core/jbig2.js";
import { JpegImage } from "./core/jpg.js";
import { JpxImage } from "./core/jpx.js";
// eslint-disable-next-line no-unused-vars
const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION");
// eslint-disable-next-line no-unused-vars
const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD");
/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
export {
getVerbosityLevel,

View File

@ -32,6 +32,8 @@
"network_utils_spec.js",
"node_stream_spec.js",
"parser_spec.js",
"pdf.image_decoders_spec.js",
"pdf.worker_spec.js",
"pdf_find_controller_spec.js",
"pdf_find_utils_spec.js",
"pdf_history_spec.js",

View File

@ -74,6 +74,8 @@ async function initializePDFJS(callback) {
"pdfjs-test/unit/network_spec.js",
"pdfjs-test/unit/network_utils_spec.js",
"pdfjs-test/unit/parser_spec.js",
"pdfjs-test/unit/pdf.image_decoders_spec.js",
"pdfjs-test/unit/pdf.worker_spec.js",
"pdfjs-test/unit/pdf_find_controller_spec.js",
"pdfjs-test/unit/pdf_find_utils_spec.js",
"pdfjs-test/unit/pdf_history_spec.js",

View File

@ -0,0 +1,40 @@
/* Copyright 2023 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getVerbosityLevel, setVerbosityLevel } from "../../src/shared/util.js";
import { Jbig2Image } from "../../src/core/jbig2.js";
import { JpegImage } from "../../src/core/jpg.js";
import { JpxImage } from "../../src/core/jpx.js";
describe("pdfimage_api", function () {
it("checks that the *official* PDF.js-image decoders API exposes the expected functionality", async function () {
// eslint-disable-next-line no-unsanitized/method
const pdfimageAPI = await import(
typeof PDFJSDev !== "undefined" && PDFJSDev.test("LIB")
? "../../pdf.image_decoders.js"
: "../../src/pdf.image_decoders.js"
);
// The imported Object contains an (automatically) inserted Symbol,
// hence we copy the data to allow using a simple comparison below.
expect({ ...pdfimageAPI }).toEqual({
getVerbosityLevel,
Jbig2Image,
JpegImage,
JpxImage,
setVerbosityLevel,
});
});
});

View File

@ -0,0 +1,33 @@
/* Copyright 2023 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { WorkerMessageHandler } from "../../src/core/worker.js";
describe("pdfworker_api", function () {
it("checks that the *official* PDF.js-worker API exposes the expected functionality", async function () {
// eslint-disable-next-line no-unsanitized/method
const pdfworkerAPI = await import(
typeof PDFJSDev !== "undefined" && PDFJSDev.test("LIB")
? "../../pdf.worker.js"
: "../../src/pdf.worker.js"
);
// The imported Object contains an (automatically) inserted Symbol,
// hence we copy the data to allow using a simple comparison below.
expect({ ...pdfworkerAPI }).toEqual({
WorkerMessageHandler,
});
});
});