Merge pull request #17112 from Snuffleupagus/integration-test-modules

Convert the `integration` test-files to JavaScript modules
This commit is contained in:
Jonas Jenwald 2023-10-13 18:53:52 +02:00 committed by GitHub
commit 96258449e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 91 additions and 76 deletions

View File

@ -24,14 +24,14 @@ async function runTests(results) {
random: false, random: false,
spec_dir: "integration", spec_dir: "integration",
spec_files: [ spec_files: [
"accessibility_spec.js", "accessibility_spec.mjs",
"annotation_spec.js", "annotation_spec.mjs",
"copy_paste_spec.js", "copy_paste_spec.mjs",
"find_spec.js", "find_spec.mjs",
"freetext_editor_spec.js", "freetext_editor_spec.mjs",
"ink_editor_spec.js", "ink_editor_spec.mjs",
"scripting_spec.js", "scripting_spec.mjs",
"stamp_editor_spec.js", "stamp_editor_spec.mjs",
], ],
}); });

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
const { closePages, loadAndWait } = require("./test_utils.js"); import { closePages, loadAndWait } from "./test_utils.mjs";
describe("accessibility", () => { describe("accessibility", () => {
describe("structure tree", () => { describe("structure tree", () => {

View File

@ -13,12 +13,12 @@
* limitations under the License. * limitations under the License.
*/ */
const { import {
closePages, closePages,
getSelector,
getQuerySelector, getQuerySelector,
getSelector,
loadAndWait, loadAndWait,
} = require("./test_utils.js"); } from "./test_utils.mjs";
describe("Annotation highlight", () => { describe("Annotation highlight", () => {
describe("annotation-highlight.pdf", () => { describe("annotation-highlight.pdf", () => {

View File

@ -13,13 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
const { import {
closePages, closePages,
loadAndWait, loadAndWait,
mockClipboard, mockClipboard,
waitForEvent, waitForEvent,
waitForTextLayer, waitForTextLayer,
} = require("./test_utils.js"); } from "./test_utils.mjs";
const selectAll = async page => { const selectAll = async page => {
const promise = waitForEvent(page, "selectionchange"); const promise = waitForEvent(page, "selectionchange");

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
const { closePages, loadAndWait } = require("./test_utils.js"); import { closePages, loadAndWait } from "./test_utils.mjs";
function fuzzyMatch(a, b, browserName, pixelFuzz = 3) { function fuzzyMatch(a, b, browserName, pixelFuzz = 3) {
expect(a) expect(a)

View File

@ -13,24 +13,23 @@
* limitations under the License. * limitations under the License.
*/ */
const { import {
closePages, closePages,
dragAndDropAnnotation, dragAndDropAnnotation,
getEditors, getEditors,
getEditorSelector, getEditorSelector,
getSelectedEditors,
getFirstSerialized, getFirstSerialized,
getSelectedEditors,
getSerialized, getSerialized,
loadAndWait, loadAndWait,
scrollIntoView, scrollIntoView,
waitForEvent, waitForEvent,
waitForSelectedEditor, waitForSelectedEditor,
waitForUnselectedEditor,
waitForSerialized, waitForSerialized,
waitForStorageEntries, waitForStorageEntries,
} = require("./test_utils.js"); waitForUnselectedEditor,
} from "./test_utils.mjs";
const PNG = require("pngjs").PNG; import { PNG } from "pngjs";
const copyPaste = async page => { const copyPaste = async page => {
let promise = waitForEvent(page, "copy"); let promise = waitForEvent(page, "copy");

View File

@ -13,12 +13,12 @@
* limitations under the License. * limitations under the License.
*/ */
const { import {
closePages, closePages,
getSelectedEditors, getSelectedEditors,
loadAndWait, loadAndWait,
waitForStorageEntries, waitForStorageEntries,
} = require("./test_utils.js"); } from "./test_utils.mjs";
const waitForPointerUp = page => const waitForPointerUp = page =>
page.evaluate( page.evaluate(

View File

@ -13,16 +13,16 @@
* limitations under the License. * limitations under the License.
*/ */
const { import {
clearInput, clearInput,
closePages, closePages,
getSelector,
getQuerySelector,
getComputedStyleSelector, getComputedStyleSelector,
loadAndWait,
getFirstSerialized, getFirstSerialized,
getQuerySelector,
getSelector,
loadAndWait,
scrollIntoView, scrollIntoView,
} = require("./test_utils.js"); } from "./test_utils.mjs";
describe("Interaction", () => { describe("Interaction", () => {
async function actAndWaitForInput(page, selector, action, clear = true) { async function actAndWaitForInput(page, selector, action, clear = true) {

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
const { import {
closePages, closePages,
getEditorDimensions, getEditorDimensions,
getEditorSelector, getEditorSelector,
@ -21,11 +21,14 @@ const {
loadAndWait, loadAndWait,
serializeBitmapDimensions, serializeBitmapDimensions,
waitForAnnotationEditorLayer, waitForAnnotationEditorLayer,
waitForStorageEntries,
waitForSelectedEditor, waitForSelectedEditor,
} = require("./test_utils.js"); waitForStorageEntries,
const path = require("path"); } from "./test_utils.mjs";
const fs = require("fs"); import { fileURLToPath } from "url";
import fs from "fs";
import path from "path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const selectAll = async page => { const selectAll = async page => {
await page.keyboard.down("Control"); await page.keyboard.down("Control");

View File

@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
exports.loadAndWait = (filename, selector, zoom, pageSetup) => function loadAndWait(filename, selector, zoom, pageSetup) {
Promise.all( return Promise.all(
global.integrationSessions.map(async session => { global.integrationSessions.map(async session => {
const page = await session.browser.newPage(); const page = await session.browser.newPage();
@ -49,40 +49,42 @@ exports.loadAndWait = (filename, selector, zoom, pageSetup) =>
return [session.name, page]; return [session.name, page];
}) })
); );
}
exports.closePages = pages => function closePages(pages) {
Promise.all( return Promise.all(
pages.map(async ([_, page]) => { pages.map(async ([_, page]) => {
// Avoid to keep something from a previous test. // Avoid to keep something from a previous test.
await page.evaluate(() => window.localStorage.clear()); await page.evaluate(() => window.localStorage.clear());
await page.close(); await page.close();
}) })
); );
}
exports.clearInput = async (page, selector) => { async function clearInput(page, selector) {
await page.click(selector); await page.click(selector);
await page.keyboard.down("Control"); await page.keyboard.down("Control");
await page.keyboard.press("A"); await page.keyboard.press("A");
await page.keyboard.up("Control"); await page.keyboard.up("Control");
await page.keyboard.press("Backspace"); await page.keyboard.press("Backspace");
await page.waitForTimeout(10); await page.waitForTimeout(10);
}; }
function getSelector(id) { function getSelector(id) {
return `[data-element-id="${id}"]`; return `[data-element-id="${id}"]`;
} }
exports.getSelector = getSelector;
function getQuerySelector(id) { function getQuerySelector(id) {
return `document.querySelector('${getSelector(id)}')`; return `document.querySelector('${getSelector(id)}')`;
} }
exports.getQuerySelector = getQuerySelector;
function getComputedStyleSelector(id) { function getComputedStyleSelector(id) {
return `getComputedStyle(${getQuerySelector(id)})`; return `getComputedStyle(${getQuerySelector(id)})`;
} }
exports.getComputedStyleSelector = getComputedStyleSelector;
exports.getEditorSelector = n => `#pdfjs_internal_editor_${n}`; function getEditorSelector(n) {
return `#pdfjs_internal_editor_${n}`;
}
function getSelectedEditors(page) { function getSelectedEditors(page) {
return page.evaluate(() => { return page.evaluate(() => {
@ -95,7 +97,6 @@ function getSelectedEditors(page) {
return results; return results;
}); });
} }
exports.getSelectedEditors = getSelectedEditors;
async function waitForEvent(page, eventName, timeout = 5000) { async function waitForEvent(page, eventName, timeout = 5000) {
const hasTimedout = await Promise.race([ const hasTimedout = await Promise.race([
@ -119,40 +120,35 @@ async function waitForEvent(page, eventName, timeout = 5000) {
console.log(`waitForEvent: timeout waiting for ${eventName}`); console.log(`waitForEvent: timeout waiting for ${eventName}`);
} }
} }
exports.waitForEvent = waitForEvent;
const waitForStorageEntries = async (page, nEntries) => { async function waitForStorageEntries(page, nEntries) {
await page.waitForFunction( return page.waitForFunction(
n => window.PDFViewerApplication.pdfDocument.annotationStorage.size === n, n => window.PDFViewerApplication.pdfDocument.annotationStorage.size === n,
{}, {},
nEntries nEntries
); );
}; }
exports.waitForStorageEntries = waitForStorageEntries;
const waitForSerialized = async (page, nEntries) => { async function waitForSerialized(page, nEntries) {
await page.waitForFunction( return page.waitForFunction(
n => n =>
(window.PDFViewerApplication.pdfDocument.annotationStorage.serializable (window.PDFViewerApplication.pdfDocument.annotationStorage.serializable
.map?.size ?? 0) === n, .map?.size ?? 0) === n,
{}, {},
nEntries nEntries
); );
}; }
exports.waitForSerialized = waitForSerialized;
const waitForSelectedEditor = async (page, selector) => { async function waitForSelectedEditor(page, selector) {
await page.waitForSelector(`${selector}.selectedEditor`); return page.waitForSelector(`${selector}.selectedEditor`);
}; }
exports.waitForSelectedEditor = waitForSelectedEditor;
const waitForUnselectedEditor = async (page, selector) => { async function waitForUnselectedEditor(page, selector) {
await page.waitForSelector(`${selector}:not(.selectedEditor)`); return page.waitForSelector(`${selector}:not(.selectedEditor)`);
}; }
exports.waitForUnselectedEditor = waitForUnselectedEditor;
const mockClipboard = async pages => { async function mockClipboard(pages) {
await Promise.all( return Promise.all(
pages.map(async ([_, page]) => { pages.map(async ([_, page]) => {
await page.evaluate(() => { await page.evaluate(() => {
let data = null; let data = null;
@ -164,8 +160,7 @@ const mockClipboard = async pages => {
}); });
}) })
); );
}; }
exports.mockClipboard = mockClipboard;
async function getSerialized(page, filter = undefined) { async function getSerialized(page, filter = undefined) {
const values = await page.evaluate(() => { const values = await page.evaluate(() => {
@ -175,11 +170,10 @@ async function getSerialized(page, filter = undefined) {
}); });
return filter ? values.map(filter) : values; return filter ? values.map(filter) : values;
} }
exports.getSerialized = getSerialized;
const getFirstSerialized = async (page, filter = undefined) => async function getFirstSerialized(page, filter = undefined) {
(await getSerialized(page, filter))[0]; return (await getSerialized(page, filter))[0];
exports.getFirstSerialized = getFirstSerialized; }
function getEditors(page, kind) { function getEditors(page, kind) {
return page.evaluate(aKind => { return page.evaluate(aKind => {
@ -191,7 +185,6 @@ function getEditors(page, kind) {
return results; return results;
}, kind); }, kind);
} }
exports.getEditors = getEditors;
function getEditorDimensions(page, id) { function getEditorDimensions(page, id) {
return page.evaluate(n => { return page.evaluate(n => {
@ -205,7 +198,6 @@ function getEditorDimensions(page, id) {
}; };
}, id); }, id);
} }
exports.getEditorDimensions = getEditorDimensions;
async function serializeBitmapDimensions(page) { async function serializeBitmapDimensions(page) {
await page.waitForFunction(() => { await page.waitForFunction(() => {
@ -229,7 +221,6 @@ async function serializeBitmapDimensions(page) {
: []; : [];
}); });
} }
exports.serializeBitmapDimensions = serializeBitmapDimensions;
async function dragAndDropAnnotation(page, startX, startY, tX, tY) { async function dragAndDropAnnotation(page, startX, startY, tX, tY) {
await page.mouse.move(startX, startY); await page.mouse.move(startX, startY);
@ -239,7 +230,6 @@ async function dragAndDropAnnotation(page, startX, startY, tX, tY) {
await page.mouse.up(); await page.mouse.up();
await page.waitForSelector("#viewer:not(.noUserSelect)"); await page.waitForSelector("#viewer:not(.noUserSelect)");
} }
exports.dragAndDropAnnotation = dragAndDropAnnotation;
async function waitForAnnotationEditorLayer(page) { async function waitForAnnotationEditorLayer(page) {
return page.evaluate(() => { return page.evaluate(() => {
@ -251,7 +241,6 @@ async function waitForAnnotationEditorLayer(page) {
}); });
}); });
} }
exports.waitForAnnotationEditorLayer = waitForAnnotationEditorLayer;
async function waitForTextLayer(page) { async function waitForTextLayer(page) {
return page.evaluate(() => { return page.evaluate(() => {
@ -260,7 +249,6 @@ async function waitForTextLayer(page) {
}); });
}); });
} }
exports.waitForTextLayer = waitForTextLayer;
async function scrollIntoView(page, selector) { async function scrollIntoView(page, selector) {
const promise = page.evaluate( const promise = page.evaluate(
@ -296,4 +284,29 @@ async function scrollIntoView(page, selector) {
selector selector
); );
} }
exports.scrollIntoView = scrollIntoView;
export {
clearInput,
closePages,
dragAndDropAnnotation,
getComputedStyleSelector,
getEditorDimensions,
getEditors,
getEditorSelector,
getFirstSerialized,
getQuerySelector,
getSelectedEditors,
getSelector,
getSerialized,
loadAndWait,
mockClipboard,
scrollIntoView,
serializeBitmapDimensions,
waitForAnnotationEditorLayer,
waitForEvent,
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTextLayer,
waitForUnselectedEditor,
};