diff --git a/test/integration/accessibility_spec.mjs b/test/integration/accessibility_spec.mjs index 4dde9779b..9ed7eda50 100644 --- a/test/integration/accessibility_spec.mjs +++ b/test/integration/accessibility_spec.mjs @@ -13,7 +13,7 @@ * limitations under the License. */ -const { closePages, loadAndWait } = require("./test_utils.js"); +import { closePages, loadAndWait } from "./test_utils.mjs"; describe("accessibility", () => { describe("structure tree", () => { diff --git a/test/integration/annotation_spec.mjs b/test/integration/annotation_spec.mjs index 06e5562ce..7c35b1e6e 100644 --- a/test/integration/annotation_spec.mjs +++ b/test/integration/annotation_spec.mjs @@ -13,12 +13,12 @@ * limitations under the License. */ -const { +import { closePages, - getSelector, getQuerySelector, + getSelector, loadAndWait, -} = require("./test_utils.js"); +} from "./test_utils.mjs"; describe("Annotation highlight", () => { describe("annotation-highlight.pdf", () => { diff --git a/test/integration/copy_paste_spec.mjs b/test/integration/copy_paste_spec.mjs index 721cfe585..e8fc78347 100644 --- a/test/integration/copy_paste_spec.mjs +++ b/test/integration/copy_paste_spec.mjs @@ -13,13 +13,13 @@ * limitations under the License. */ -const { +import { closePages, loadAndWait, mockClipboard, waitForEvent, waitForTextLayer, -} = require("./test_utils.js"); +} from "./test_utils.mjs"; const selectAll = async page => { const promise = waitForEvent(page, "selectionchange"); diff --git a/test/integration/find_spec.mjs b/test/integration/find_spec.mjs index c5c0e29fb..c761094f0 100644 --- a/test/integration/find_spec.mjs +++ b/test/integration/find_spec.mjs @@ -13,7 +13,7 @@ * 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) { expect(a) diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index 7a2889b76..5d6da3fce 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -13,24 +13,23 @@ * limitations under the License. */ -const { +import { closePages, dragAndDropAnnotation, getEditors, getEditorSelector, - getSelectedEditors, getFirstSerialized, + getSelectedEditors, getSerialized, loadAndWait, scrollIntoView, waitForEvent, waitForSelectedEditor, - waitForUnselectedEditor, waitForSerialized, waitForStorageEntries, -} = require("./test_utils.js"); - -const PNG = require("pngjs").PNG; + waitForUnselectedEditor, +} from "./test_utils.mjs"; +import { PNG } from "pngjs"; const copyPaste = async page => { let promise = waitForEvent(page, "copy"); diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index 890a04f97..7ab235ea9 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -13,12 +13,12 @@ * limitations under the License. */ -const { +import { closePages, getSelectedEditors, loadAndWait, waitForStorageEntries, -} = require("./test_utils.js"); +} from "./test_utils.mjs"; const waitForPointerUp = page => page.evaluate( diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index 4117249ed..0a714f994 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -13,16 +13,16 @@ * limitations under the License. */ -const { +import { clearInput, closePages, - getSelector, - getQuerySelector, getComputedStyleSelector, - loadAndWait, getFirstSerialized, + getQuerySelector, + getSelector, + loadAndWait, scrollIntoView, -} = require("./test_utils.js"); +} from "./test_utils.mjs"; describe("Interaction", () => { async function actAndWaitForInput(page, selector, action, clear = true) { diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index e57677d3c..4d88abc93 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -13,7 +13,7 @@ * limitations under the License. */ -const { +import { closePages, getEditorDimensions, getEditorSelector, @@ -21,11 +21,14 @@ const { loadAndWait, serializeBitmapDimensions, waitForAnnotationEditorLayer, - waitForStorageEntries, waitForSelectedEditor, -} = require("./test_utils.js"); -const path = require("path"); -const fs = require("fs"); + waitForStorageEntries, +} from "./test_utils.mjs"; +import { fileURLToPath } from "url"; +import fs from "fs"; +import path from "path"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const selectAll = async page => { await page.keyboard.down("Control"); diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index bc79c60d0..b71e75049 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -13,8 +13,8 @@ * limitations under the License. */ -exports.loadAndWait = (filename, selector, zoom, pageSetup) => - Promise.all( +function loadAndWait(filename, selector, zoom, pageSetup) { + return Promise.all( global.integrationSessions.map(async session => { const page = await session.browser.newPage(); @@ -49,40 +49,42 @@ exports.loadAndWait = (filename, selector, zoom, pageSetup) => return [session.name, page]; }) ); +} -exports.closePages = pages => - Promise.all( +function closePages(pages) { + return Promise.all( pages.map(async ([_, page]) => { // Avoid to keep something from a previous test. await page.evaluate(() => window.localStorage.clear()); await page.close(); }) ); +} -exports.clearInput = async (page, selector) => { +async function clearInput(page, selector) { await page.click(selector); await page.keyboard.down("Control"); await page.keyboard.press("A"); await page.keyboard.up("Control"); await page.keyboard.press("Backspace"); await page.waitForTimeout(10); -}; +} function getSelector(id) { return `[data-element-id="${id}"]`; } -exports.getSelector = getSelector; function getQuerySelector(id) { return `document.querySelector('${getSelector(id)}')`; } -exports.getQuerySelector = getQuerySelector; function getComputedStyleSelector(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) { return page.evaluate(() => { @@ -95,7 +97,6 @@ function getSelectedEditors(page) { return results; }); } -exports.getSelectedEditors = getSelectedEditors; async function waitForEvent(page, eventName, timeout = 5000) { const hasTimedout = await Promise.race([ @@ -119,40 +120,35 @@ async function waitForEvent(page, eventName, timeout = 5000) { console.log(`waitForEvent: timeout waiting for ${eventName}`); } } -exports.waitForEvent = waitForEvent; -const waitForStorageEntries = async (page, nEntries) => { - await page.waitForFunction( +async function waitForStorageEntries(page, nEntries) { + return page.waitForFunction( n => window.PDFViewerApplication.pdfDocument.annotationStorage.size === n, {}, nEntries ); -}; -exports.waitForStorageEntries = waitForStorageEntries; +} -const waitForSerialized = async (page, nEntries) => { - await page.waitForFunction( +async function waitForSerialized(page, nEntries) { + return page.waitForFunction( n => (window.PDFViewerApplication.pdfDocument.annotationStorage.serializable .map?.size ?? 0) === n, {}, nEntries ); -}; -exports.waitForSerialized = waitForSerialized; +} -const waitForSelectedEditor = async (page, selector) => { - await page.waitForSelector(`${selector}.selectedEditor`); -}; -exports.waitForSelectedEditor = waitForSelectedEditor; +async function waitForSelectedEditor(page, selector) { + return page.waitForSelector(`${selector}.selectedEditor`); +} -const waitForUnselectedEditor = async (page, selector) => { - await page.waitForSelector(`${selector}:not(.selectedEditor)`); -}; -exports.waitForUnselectedEditor = waitForUnselectedEditor; +async function waitForUnselectedEditor(page, selector) { + return page.waitForSelector(`${selector}:not(.selectedEditor)`); +} -const mockClipboard = async pages => { - await Promise.all( +async function mockClipboard(pages) { + return Promise.all( pages.map(async ([_, page]) => { await page.evaluate(() => { let data = null; @@ -164,8 +160,7 @@ const mockClipboard = async pages => { }); }) ); -}; -exports.mockClipboard = mockClipboard; +} async function getSerialized(page, filter = undefined) { const values = await page.evaluate(() => { @@ -175,11 +170,10 @@ async function getSerialized(page, filter = undefined) { }); return filter ? values.map(filter) : values; } -exports.getSerialized = getSerialized; -const getFirstSerialized = async (page, filter = undefined) => - (await getSerialized(page, filter))[0]; -exports.getFirstSerialized = getFirstSerialized; +async function getFirstSerialized(page, filter = undefined) { + return (await getSerialized(page, filter))[0]; +} function getEditors(page, kind) { return page.evaluate(aKind => { @@ -191,7 +185,6 @@ function getEditors(page, kind) { return results; }, kind); } -exports.getEditors = getEditors; function getEditorDimensions(page, id) { return page.evaluate(n => { @@ -205,7 +198,6 @@ function getEditorDimensions(page, id) { }; }, id); } -exports.getEditorDimensions = getEditorDimensions; async function serializeBitmapDimensions(page) { await page.waitForFunction(() => { @@ -229,7 +221,6 @@ async function serializeBitmapDimensions(page) { : []; }); } -exports.serializeBitmapDimensions = serializeBitmapDimensions; async function dragAndDropAnnotation(page, startX, startY, tX, tY) { await page.mouse.move(startX, startY); @@ -239,7 +230,6 @@ async function dragAndDropAnnotation(page, startX, startY, tX, tY) { await page.mouse.up(); await page.waitForSelector("#viewer:not(.noUserSelect)"); } -exports.dragAndDropAnnotation = dragAndDropAnnotation; async function waitForAnnotationEditorLayer(page) { return page.evaluate(() => { @@ -251,7 +241,6 @@ async function waitForAnnotationEditorLayer(page) { }); }); } -exports.waitForAnnotationEditorLayer = waitForAnnotationEditorLayer; async function waitForTextLayer(page) { return page.evaluate(() => { @@ -260,7 +249,6 @@ async function waitForTextLayer(page) { }); }); } -exports.waitForTextLayer = waitForTextLayer; async function scrollIntoView(page, selector) { const promise = page.evaluate( @@ -296,4 +284,29 @@ async function scrollIntoView(page, 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, +};