From 393e799e49032129b3e2a0217a6d9a14405bc4d6 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 18 May 2025 15:55:01 +0200 Subject: [PATCH] Fix missing `await` for asynchronous method calls in the integration tests The `Page.evaluate()` and `Mouse.click()` APIs in Puppeteer both return a promise; see https://pptr.dev/api/puppeteer.page.evaluate and https://pptr.dev/api/puppeteer.mouse.click, and should therefore be awaited before proceeding in tests to make sure that the test's behavior is deterministic and avoid intermittent failures. The following command was used to find potential places to fix: `grep -nEr "[^await|return] page\." test/integration/*` --- test/integration/freetext_editor_spec.mjs | 4 ++-- test/integration/highlight_editor_spec.mjs | 4 ++-- test/integration/ink_editor_spec.mjs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index bc5eb57c9..df0cf9a33 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -669,7 +669,7 @@ describe("FreeText Editor", () => { } ); - page.evaluate(() => { + await page.evaluate(() => { window.PDFViewerApplication.eventBus.dispatch( "switchannotationeditorparams", { @@ -1290,7 +1290,7 @@ describe("FreeText Editor", () => { ".selectedEditor .internal" ); - page.evaluate(() => { + await page.evaluate(() => { window.PDFViewerApplication.eventBus.dispatch( "switchannotationeditorparams", { diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index bf48b5a74..505e671f6 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -626,7 +626,7 @@ describe("Highlight Editor", () => { const { width: prevWidth } = await getRect(page, editorSelector); value = 24; - page.evaluate(val => { + await page.evaluate(val => { window.PDFViewerApplication.eventBus.dispatch( "switchannotationeditorparams", { @@ -763,7 +763,7 @@ describe("Highlight Editor", () => { const { width: prevWidth } = await getRect(page, editorSelector); - page.evaluate(val => { + await page.evaluate(val => { window.PDFViewerApplication.eventBus.dispatch( "switchannotationeditorparams", { diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index 5a1639208..148a5f5fe 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -302,7 +302,7 @@ describe("Ink Editor", () => { await page.mouse.up(); await awaitPromise(clickHandle); - page.mouse.click(rect.x - 10, rect.y + 10); + await page.mouse.click(rect.x - 10, rect.y + 10); await page.waitForSelector(`${getEditorSelector(0)}.disabled`); }) ); @@ -583,7 +583,7 @@ describe("Ink Editor", () => { } const red = "#ff0000"; - page.evaluate(value => { + await page.evaluate(value => { window.PDFViewerApplication.eventBus.dispatch( "switchannotationeditorparams", { @@ -763,7 +763,7 @@ describe("Ink Editor", () => { await selectEditor(page, pdfjsA); const red = "#ff0000"; - page.evaluate(value => { + await page.evaluate(value => { window.PDFViewerApplication.eventBus.dispatch( "switchannotationeditorparams", {