From 3da4ab2641b2563c8b3886ec112f16c982ac0a1c Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Mon, 1 Aug 2022 13:06:57 -0400 Subject: [PATCH] Resolve flaky navigation tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch the tests from a time-based waiting mechanism (1200 milliseconds) to an event-based waiting mechanism (waiting for `turbo:load`). ``` 2) [firefox] › navigation_tests.ts:341:1 › test double-clicking on a link ======================== AssertionError: expected '/src/tests/fixtures/navigation.html' to equal '/__turbo/delayed_response' 344 | 345 | await nextBody(page, 1200) > 346 | assert.equal(pathname(page.url()), "/__turbo/delayed_response") | ^ 347 | assert.equal(await visitAction(page), "advance") 348 | }) 349 | at /home/runner/work/turbo/turbo/src/tests/functional/navigation_tests.ts:346:10 1) [firefox] › navigation_tests.ts:131:1 › test following a same-origin POST form button[data-turbo-action=replace] page.click: Target closed =========================== logs =========================== waiting for selector "#same-origin-replace-form-submitter-post button" selector resolved to visible attempting click action waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed ============================================================ 130 | 131 | test("test following a same-origin POST form button[data-turbo-action=replace]", async ({ page }) => { > 132 | page.click("#same-origin-replace-form-submitter-post button") | ^ 133 | await nextBody(page) 134 | 135 | assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html") at /home/runner/work/turbo/turbo/src/tests/functional/navigation_tests.ts:132:8 ``` --- src/tests/functional/navigation_tests.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tests/functional/navigation_tests.ts b/src/tests/functional/navigation_tests.ts index afaf54221..2fe01af22 100644 --- a/src/tests/functional/navigation_tests.ts +++ b/src/tests/functional/navigation_tests.ts @@ -11,6 +11,7 @@ import { nextEventNamed, noNextEventNamed, pathname, + readEventLogs, search, selectorHasFocus, visitAction, @@ -21,6 +22,7 @@ import { test.beforeEach(async ({ page }) => { await page.goto("/src/tests/fixtures/navigation.html") + await readEventLogs(page) }) test("test navigating renders a progress bar", async ({ page }) => { @@ -129,8 +131,8 @@ test("test following a same-origin POST form[data-turbo-action=replace]", async }) test("test following a same-origin POST form button[data-turbo-action=replace]", async ({ page }) => { - page.click("#same-origin-replace-form-submitter-post button") - await nextBody(page) + await page.click("#same-origin-replace-form-submitter-post button") + await nextEventNamed(page, "turbo:load") assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html") assert.equal(await visitAction(page), "replace") @@ -339,10 +341,11 @@ test("test correct referrer header", async ({ page }) => { }) test("test double-clicking on a link", async ({ page }) => { - page.click("#delayed-link") - page.click("#delayed-link") + await page.click("#delayed-link", { clickCount: 2 }) + + await nextEventNamed(page, "turbo:load") + await nextEventNamed(page, "turbo:load") - await nextBody(page, 1200) assert.equal(pathname(page.url()), "/__turbo/delayed_response") assert.equal(await visitAction(page), "advance") })