From 973b67f04759941bdbce962cd98abbc62ca84756 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 17 Nov 2024 21:05:37 +0100 Subject: [PATCH] Fix the "must check that an infinite loop is not triggered" integration test This integration test fails intermittently, locally at least in Chrome with Puppeteer 23.4.0+, with the following errors: ``` In chrome: Expected '123Hello' to equal 'Hello123'. In chrome: Expected '123Hello' to equal '123'. ``` This happens because the test before it left queued sandbox events behind. We don't close the document between tests, so those get run when we click the textbox in this test and that interferes with our selection/typing actions. This commit fixes the issue by flushing the queued sandbox events in the first test, which makes sure that state no longer leaks through to the next test and thus improves isolation. Morever, similar to commit 3adf8b6 we use safer assertions to avoid further intermittent failures, and we replace the `page.$eval` call with a simpler Home button push like we already do in e.g. the test helpers. This combined makes the code shorter and simpler. --- test/integration/scripting_spec.mjs | 30 +++++++++++++---------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index 7f74d5893c13f..1228e4ff13edf 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -1266,6 +1266,13 @@ describe("Interaction", () => { await page.waitForFunction( `${getQuerySelector("27R")}.value === "HEAO "` ); + + // The typing actions in the first textbox caused sandbox events to be + // queued. We don't close the document between tests, so we have to + // flush them here, by clicking the second textbox, so they don't leak + // through to the following test. + await page.click(getSelector("28R")); + await waitForSandboxTrip(page); }) ); }); @@ -1276,30 +1283,19 @@ describe("Interaction", () => { await waitForScripting(page); await page.click(getSelector("28R")); - await page.$eval(getSelector("28R"), el => - el.setSelectionRange(0, 0) - ); - + await page.keyboard.press("Home"); await page.type(getSelector("28R"), "Hello"); await page.waitForFunction( - `${getQuerySelector("28R")}.value !== "123"` + `${getQuerySelector("28R")}.value === "Hello123"` ); - let text = await page.$eval(getSelector("28R"), el => el.value); - expect(text).withContext(`In ${browserName}`).toEqual("Hello123"); - - // The action will trigger a calculateNow which itself - // will trigger a resetForm (inducing a calculateNow) and a - // calculateNow. + // The action triggers a `calculateNow` which in turn triggers a + // `resetForm (inducing a `calculateNow`) and a `calculateNow`. + // Without infinite loop prevention the field would be empty. await page.click("[data-annotation-id='31R']"); - await page.waitForFunction( - `${getQuerySelector("28R")}.value !== "Hello123"` + `${getQuerySelector("28R")}.value === "123"` ); - - // Without preventing against infinite loop the field is empty. - text = await page.$eval(getSelector("28R"), el => el.value); - expect(text).withContext(`In ${browserName}`).toEqual("123"); }) ); });