Skip to content

Commit

Permalink
Resolve flaky navigation tests
Browse files Browse the repository at this point in the history
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 <button data-turbo-action="replace">Same-origin form[method="post"] button[data-turbo…</button>
    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
```
  • Loading branch information
seanpdoyle committed Aug 1, 2022
1 parent f64957b commit 3da4ab2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/tests/functional/navigation_tests.ts
Expand Up @@ -11,6 +11,7 @@ import {
nextEventNamed,
noNextEventNamed,
pathname,
readEventLogs,
search,
selectorHasFocus,
visitAction,
Expand All @@ -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 }) => {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
})
Expand Down

0 comments on commit 3da4ab2

Please sign in to comment.