Skip to content

Commit 973b67f

Browse files
committed
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.
1 parent 3219d49 commit 973b67f

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

test/integration/scripting_spec.mjs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,13 @@ describe("Interaction", () => {
12661266
await page.waitForFunction(
12671267
`${getQuerySelector("27R")}.value === "HEAO "`
12681268
);
1269+
1270+
// The typing actions in the first textbox caused sandbox events to be
1271+
// queued. We don't close the document between tests, so we have to
1272+
// flush them here, by clicking the second textbox, so they don't leak
1273+
// through to the following test.
1274+
await page.click(getSelector("28R"));
1275+
await waitForSandboxTrip(page);
12691276
})
12701277
);
12711278
});
@@ -1276,30 +1283,19 @@ describe("Interaction", () => {
12761283
await waitForScripting(page);
12771284

12781285
await page.click(getSelector("28R"));
1279-
await page.$eval(getSelector("28R"), el =>
1280-
el.setSelectionRange(0, 0)
1281-
);
1282-
1286+
await page.keyboard.press("Home");
12831287
await page.type(getSelector("28R"), "Hello");
12841288
await page.waitForFunction(
1285-
`${getQuerySelector("28R")}.value !== "123"`
1289+
`${getQuerySelector("28R")}.value === "Hello123"`
12861290
);
12871291

1288-
let text = await page.$eval(getSelector("28R"), el => el.value);
1289-
expect(text).withContext(`In ${browserName}`).toEqual("Hello123");
1290-
1291-
// The action will trigger a calculateNow which itself
1292-
// will trigger a resetForm (inducing a calculateNow) and a
1293-
// calculateNow.
1292+
// The action triggers a `calculateNow` which in turn triggers a
1293+
// `resetForm (inducing a `calculateNow`) and a `calculateNow`.
1294+
// Without infinite loop prevention the field would be empty.
12941295
await page.click("[data-annotation-id='31R']");
1295-
12961296
await page.waitForFunction(
1297-
`${getQuerySelector("28R")}.value !== "Hello123"`
1297+
`${getQuerySelector("28R")}.value === "123"`
12981298
);
1299-
1300-
// Without preventing against infinite loop the field is empty.
1301-
text = await page.$eval(getSelector("28R"), el => el.value);
1302-
expect(text).withContext(`In ${browserName}`).toEqual("123");
13031299
})
13041300
);
13051301
});

0 commit comments

Comments
 (0)