From c6ec8d385b4d3d3bcae3611e313823c3be284b93 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Wed, 28 Aug 2024 15:31:38 -0400 Subject: [PATCH 1/2] Delegate `Turbo.session` properties to `Turbo.config` Follow-up to comment on [238ec2688b2f4907e05ad1eaeb011e93bae75995][] [hotwired/turbo#1216][] unintentionally removed support for the `Turbo.session.drive` boolean property and the `Turbo.session.formMode` string property. This commit re-introduces that support by delegating reads and writes to those properties to their corresponding `Turbo.config` versions. [hotwired/turbo#1216]: https://github.com/hotwired/turbo/pull/1216 [238ec2688b2f4907e05ad1eaeb011e93bae75995]: https://github.com/hotwired/turbo/commit/238ec2688b2f4907e05ad1eaeb011e93bae75995#commitcomment-145954235 --- src/core/session.js | 16 ++++++++++++++++ src/tests/fixtures/drive_disabled.html | 2 +- src/tests/unit/export_tests.js | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/core/session.js b/src/core/session.js index 181b6b2a2..e7e57a90f 100644 --- a/src/core/session.js +++ b/src/core/session.js @@ -144,6 +144,22 @@ export class Session { return config.drive.progressBarDelay } + set drive(value) { + config.drive.enabled = value + } + + get drive() { + return config.drive.enabled + } + + set formMode(value) { + config.forms.mode = value + } + + get formMode() { + return config.forms.mode + } + get location() { return this.history.location } diff --git a/src/tests/fixtures/drive_disabled.html b/src/tests/fixtures/drive_disabled.html index da787f0bb..477ca3c65 100644 --- a/src/tests/fixtures/drive_disabled.html +++ b/src/tests/fixtures/drive_disabled.html @@ -15,7 +15,7 @@ }) diff --git a/src/tests/unit/export_tests.js b/src/tests/unit/export_tests.js index d255a3fc0..485963043 100644 --- a/src/tests/unit/export_tests.js +++ b/src/tests/unit/export_tests.js @@ -19,9 +19,28 @@ test("Turbo interface", () => { assert.equal(typeof Turbo.cache.clear, "function") assert.equal(typeof Turbo.navigator, "object") assert.equal(typeof Turbo.session, "object") + assert.equal(typeof Turbo.session.drive, "boolean") + assert.equal(typeof Turbo.session.formMode, "string") assert.equal(typeof Turbo.fetch, "function") }) +test("Session interface", () => { + const { session, config } = Turbo + + assert.equal(true, session.drive) + assert.equal(true, config.drive.enabled) + assert.equal("on", session.formMode) + assert.equal("on", config.forms.mode) + + session.drive = false + session.formMode = "off" + + assert.equal(false, session.drive) + assert.equal(false, config.drive.enabled) + assert.equal("off", session.formMode) + assert.equal("off", config.forms.mode) +}) + test("StreamActions interface", () => { assert.equal(typeof StreamActions, "object") }) From 391452f650629445e58c3946bfd60bbef7cb5f6c Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Wed, 28 Aug 2024 15:56:18 -0400 Subject: [PATCH 2/2] Resolve timing-based CI failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Browser tests periodically fail due to a timing issue: ``` 1) [firefox] › functional/frame_tests.js:190:5 › failing to follow a link to a page without a matching frame shows an error and throws an exception AssertionError: expected 'Missing frame Missing page Unvisitabl…' to match /Content missing/ 196 | await page.click("#missing-page-link") 197 | > 198 | assert.match(await page.innerText("#missing"), /Content missing/) | ^ 199 | 200 | assert.exists(error) 201 | assert.include(error.message, `The response (404) did not contain the expected `) ``` This commit replaces the `assert`-based assertion with an `expect`-based Playwright assertion that will utilize retries and timing synchronization. [CI failure]: https://github.com/hotwired/turbo/actions/runs/10603228414/job/29387060926?pr=1306#step:11:18 --- src/tests/functional/frame_tests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/functional/frame_tests.js b/src/tests/functional/frame_tests.js index 3b0770c39..30381a52c 100644 --- a/src/tests/functional/frame_tests.js +++ b/src/tests/functional/frame_tests.js @@ -163,7 +163,7 @@ test("successfully following a link to a page without a matching frame shows an await page.click("#missing-frame-link") - assert.match(await page.innerText("#missing"), /Content missing/) + await expect(page.locator("#missing")).toHaveText("Content missing") assert.exists(error) assert.include(error.message, `The response (200) did not contain the expected `) @@ -195,7 +195,7 @@ test("failing to follow a link to a page without a matching frame shows an error await page.click("#missing-page-link") - assert.match(await page.innerText("#missing"), /Content missing/) + await expect(page.locator("#missing")).toHaveText("Content missing") assert.exists(error) assert.include(error.message, `The response (404) did not contain the expected `)