From 138b9c4d09b777319154e2f29d03f325764a4185 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Sun, 8 Oct 2023 16:24:26 -0400 Subject: [PATCH] Add test coverage for `StreamActions` export According to the [official documentation][], applications that need to extend `StreamActions` should be importing it directly from the module instead of accessing it through `window.Turbo.StreamActions`. This commit adds test coverage to exercise the corresponding `import`. It also re-arranges the `export` to explicitly occur in the `@hotwired/turbo` module itself, instead of being transitively exported as part of the `@hotwired/turbo/core` module. [official documentation]: https://turbo.hotwired.dev/handbook/streams#custom-actions --- src/core/index.js | 4 +++- src/index.js | 1 + src/tests/unit/export_tests.js | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/index.js b/src/core/index.js index 440d67302..2a3dd8fe5 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,11 +1,13 @@ import { Session } from "./session" +import { Cache } from "./cache" import { PageRenderer } from "./drive/page_renderer" import { PageSnapshot } from "./drive/page_snapshot" import { FrameRenderer } from "./frames/frame_renderer" import { FormSubmission } from "./drive/form_submission" const session = new Session() -const { cache, navigator } = session +const cache = new Cache(session) +const { navigator } = session export { navigator, session, cache, PageRenderer, PageSnapshot, FrameRenderer } export { StreamActions } from "./streams/stream_actions" diff --git a/src/index.js b/src/index.js index 07e3e097d..6045469d1 100644 --- a/src/index.js +++ b/src/index.js @@ -10,3 +10,4 @@ Turbo.start() export * from "./core" export * from "./elements" export * from "./http" +export { StreamActions } from "./core/streams/stream_actions" diff --git a/src/tests/unit/export_tests.js b/src/tests/unit/export_tests.js index be46c8160..2ae44f88f 100644 --- a/src/tests/unit/export_tests.js +++ b/src/tests/unit/export_tests.js @@ -1,5 +1,6 @@ import { assert } from "@open-wc/testing" -import * as Turbo from "../../index" +import * as Turbo from "../../" +import { StreamActions } from "../../" test("test Turbo interface", () => { assert.equal(typeof Turbo.start, "function") @@ -16,3 +17,7 @@ test("test Turbo interface", () => { assert.equal(typeof Turbo.navigator, "object") assert.equal(typeof Turbo.session, "object") }) + +test("test StreamActions interface", () => { + assert.equal(typeof StreamActions, "object") +})