forked from hotwired/turbo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functional Tests: Replace
chai
with Playwright Assertions
Utilize Playwright's built-in [assertions][] so that functional test assertions are consistent. The `chai`-based assertions provide similar coverage, but not much is gained for the suite by having two competing styles of assertion. The majority of this diff replaces `assert.equal` with `expect(...).toEqual()`. In some cases, text comparison is replaced with Playwright's [toHaveText][], since that assertion bakes in synchronization and waiting support, and has the ability to compare contents in a way that ignores spacing differences. There are other patterns throughout the test suite that could be improved by adhering more closely to Playwright idioms, but that would can be saved for another time. Related --- A reduction in functional test suite execution time was an unexpected benefit. Since the suite relies less on manual timing interventions like `nextBody` and `nextBeat`, it relies more on Playwright's built-in synchronization and timing mechanisms. ```sh yarn test:browser --project=chrome # ... 352 passed (38s) ✨ Done in 38.17s. ``` ```sh yarn test:browser --project=chrome # ... 349 passed (25s) ✨ Done in 24.89s. ``` [assertions]: https://playwright.dev/docs/test-assertions [toHaveText]: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-text
- Loading branch information
1 parent
cc263b4
commit 5e71a69
Showing
24 changed files
with
1,056 additions
and
1,357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,33 @@ | ||
import { test } from "@playwright/test" | ||
import { assert } from "chai" | ||
import { hasSelector, nextBody } from "../helpers/page" | ||
import { expect, test } from "@playwright/test" | ||
import { nextEventNamed } from "../helpers/page" | ||
|
||
test("removes temporary elements", async ({ page }) => { | ||
await page.goto("/src/tests/fixtures/cache_observer.html") | ||
|
||
assert.equal(await page.textContent("#temporary"), "data-turbo-temporary") | ||
await expect(page.locator("#temporary")).toHaveText("data-turbo-temporary") | ||
|
||
await page.click("#link") | ||
await nextBody(page) | ||
await nextEventNamed(page, "turbo:load") | ||
await page.goBack() | ||
await nextBody(page) | ||
|
||
assert.notOk(await hasSelector(page, "#temporary")) | ||
await expect(page.locator("#temporary")).not.toBeVisible() | ||
}) | ||
|
||
test("removes temporary elements with deprecated turbo-cache=false selector", async ({ page }) => { | ||
await page.goto("/src/tests/fixtures/cache_observer.html") | ||
|
||
assert.equal(await page.textContent("#temporary-with-deprecated-selector"), "data-turbo-cache=false") | ||
await expect(page.locator("#temporary-with-deprecated-selector")).toHaveText("data-turbo-cache=false") | ||
|
||
await page.click("#link") | ||
await nextBody(page) | ||
await nextEventNamed(page, "turbo:load") | ||
await page.goBack() | ||
await nextBody(page) | ||
|
||
assert.notOk(await hasSelector(page, "#temporary-with-deprecated-selector")) | ||
await expect(page.locator("#temporary-with-deprecated-selector")).not.toBeVisible() | ||
}) | ||
|
||
test("following a redirect renders [data-turbo-temporary] elements before the cache removes", async ({ page }) => { | ||
await page.goto("/src/tests/fixtures/navigation.html") | ||
await page.click("#redirect-to-cache-observer") | ||
await nextBody(page) | ||
|
||
assert.equal(await page.textContent("#temporary"), "data-turbo-temporary") | ||
await expect(page.locator("#temporary")).toHaveText("data-turbo-temporary") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.