-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export StreamActions as property of window.Turbo #1073
Conversation
This was removed in #1049 but it's still used in the turbo-rails test suite. https://github.com/hotwired/turbo-rails/blob/c3ca7009c0759563ec65ecf1bc60a9af1ff33728/test/system/broadcasts_test.rb#L137
Thanks! I've upgraded to beta and can confirm that custom actions are not working. Turbo.StreamActions is undefined |
The exports should be equivalent between the reverted change and this one. I'm not sure why this is necessary. There's existing test coverage introduced prior to this change that guarantees Turbo.StreamActions is exported. I was unsure of whether or not the export test was sufficient, so I experimented with adding more specific coverage locally. The following tests passed when executed on diff --git a/src/tests/unit/export_tests.js b/src/tests/unit/export_tests.js
index 7b7ddf3..e3e06cc 100644
--- a/src/tests/unit/export_tests.js
+++ b/src/tests/unit/export_tests.js
@@ -3,7 +3,6 @@ import * as Turbo from "../../"
import { StreamActions } from "../../"
test("Turbo interface", () => {
- assert.equal(typeof Turbo.StreamActions, "object")
assert.equal(typeof Turbo.start, "function")
assert.equal(typeof Turbo.registerAdapter, "function")
assert.equal(typeof Turbo.visit, "function")
@@ -20,6 +19,28 @@ test("Turbo interface", () => {
assert.equal(typeof Turbo.session, "object")
})
+test("Turbo.StreamActions interface", () => {
+ assert.equal(Turbo.StreamActions, StreamActions)
+ assert.equal(typeof Turbo.StreamActions, "object")
+ assert.equal(typeof Turbo.StreamActions.after, "function")
+ assert.equal(typeof Turbo.StreamActions.append, "function")
+ assert.equal(typeof Turbo.StreamActions.before, "function")
+ assert.equal(typeof Turbo.StreamActions.prepend, "function")
+ assert.equal(typeof Turbo.StreamActions.remove, "function")
+ assert.equal(typeof Turbo.StreamActions.replace, "function")
+ assert.equal(typeof Turbo.StreamActions.update, "function")
+ assert.equal(typeof Turbo.StreamActions.refresh, "function")
+})
+
test("StreamActions interface", () => {
+ assert.equal(StreamActions, Turbo.StreamActions)
assert.equal(typeof StreamActions, "object")
+ assert.equal(typeof StreamActions.after, "function")
+ assert.equal(typeof StreamActions.append, "function")
+ assert.equal(typeof StreamActions.before, "function")
+ assert.equal(typeof StreamActions.prepend, "function")
+ assert.equal(typeof StreamActions.remove, "function")
+ assert.equal(typeof StreamActions.replace, "function")
+ assert.equal(typeof StreamActions.update, "function")
+ assert.equal(typeof StreamActions.refresh, "function")
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @afcapel
@seanpdoyle I think what is happening is that The unit tests pass because the asserting the exports from the module, not the global |
Follow-up to [hotwired#1049][] Follow-up to [hotwired#1073][] Related to [hotwired#1078][] Replace an internal `window.Turbo.session` access with an `import { session }` statement. Prior attempts at this change introduced circular dependencies. This attempt does not. Additionally, this change maintains the ability for consumers to access StreamActions through `window.Turbo.StreamActions`, while also enabling `import { StreamActions } from "@hotwired/turbo"` (or `from "@hotwired/turbo-rails"`). [hotwired#1049]: hotwired#1049 [hotwired#1073]: hotwired#1073 [hotwired#1078]: hotwired#1078
* Export StreamActions as property of window.Turbo This was removed in hotwired#1049 but it's still used in the turbo-rails test suite. https://github.com/hotwired/turbo-rails/blob/c3ca7009c0759563ec65ecf1bc60a9af1ff33728/test/system/broadcasts_test.rb#L137 * Remove circular dependency * Assert that Turbo interface is exposed via window global
Follow-up to [hotwired#1049][] Follow-up to [hotwired#1073][] Related to [hotwired#1078][] Replace an internal `window.Turbo.session` access with an `import { session }` statement. Prior attempts at this change introduced circular dependencies. This attempt does not. Additionally, this change maintains the ability for consumers to access StreamActions through `window.Turbo.StreamActions`, while also enabling `import { StreamActions } from "@hotwired/turbo"` (or `from "@hotwired/turbo-rails"`). [hotwired#1049]: hotwired#1049 [hotwired#1073]: hotwired#1073 [hotwired#1078]: hotwired#1078
This was removed in #1049 but it's still used in the turbo-rails test suite.
https://github.com/hotwired/turbo-rails/blob/c3ca7009c0759563ec65ecf1bc60a9af1ff33728/test/system/broadcasts_test.rb#L137
@seanpdoyle can you have a look, please?