Skip to content

Commit e592476

Browse files
authored
Address CI Test Flakiness (hotwired#717)
* Frame Missing Tests: Wait for `turbo:render` One of the `turbo:frame-missing` event tests is flaky since the assertions execute without first waiting for a synchronizing event. This commit changes the test to wait until a `turbo:render` event is dispatched before making its assertions. * Scrolling Tests: Increase scrollY threshold Tests are often flaky when exercising scrolling. More often than not, Firefox scrolls to within _exactly_ 2 Y units. This commit changes the `isScrolledToSelector` boolean to treat a 2 unit difference as within the threshold. * Add test coverage for exports Introduce the `src/tests/unit/export_tests.ts` module to cover what's exported from the `src/index.ts` module, including both Turbo-prefixed classes and objects and functions accessible as the `Turbo.`-prefixed accessors.
1 parent c0b4209 commit e592476

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export {
1919
TurboBeforeRenderEvent,
2020
TurboBeforeVisitEvent,
2121
TurboClickEvent,
22+
TurboBeforeFrameRenderEvent,
2223
TurboFrameLoadEvent,
2324
TurboFrameRenderEvent,
2425
TurboLoadEvent,

src/tests/functional/frame_tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ test("test failing to follow a link to a page without a matching frame dispatche
140140
const { response } = await nextEventOnTarget(page, "missing", "turbo:frame-missing")
141141
await noNextEventNamed(page, "turbo:before-fetch-request")
142142
await noNextEventNamed(page, "turbo:load")
143+
await nextEventNamed(page, "turbo:render")
143144

144145
assert.ok(response, "dispatches turbo:frame-missing with event.detail.response")
145146
assert.equal(pathname(page.url()), "/missing.html", "navigates the page")

src/tests/helpers/page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function isScrolledToSelector(page: Page, selector: string): Promis
5959
const { y: pageY } = await scrollPosition(page)
6060
const { y: elementY } = boundingBox
6161
const offset = pageY - elementY
62-
return Math.abs(offset) < 2
62+
return Math.abs(offset) <= 2
6363
} else {
6464
return false
6565
}

src/tests/unit/export_tests.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { DOMTestCase } from "../helpers/dom_test_case"
2+
import * as Turbo from "../../index"
3+
4+
export {
5+
PageRenderer,
6+
PageSnapshot,
7+
FrameRenderer,
8+
FrameElement,
9+
StreamActions,
10+
StreamElement,
11+
StreamSourceElement,
12+
TurboBeforeCacheEvent,
13+
TurboBeforeFetchRequestEvent,
14+
TurboBeforeFetchResponseEvent,
15+
TurboBeforeFrameRenderEvent,
16+
TurboBeforeRenderEvent,
17+
TurboBeforeStreamRenderEvent,
18+
TurboBeforeVisitEvent,
19+
TurboClickEvent,
20+
TurboFetchRequestErrorEvent,
21+
TurboFrameLoadEvent,
22+
TurboFrameMissingEvent,
23+
TurboFrameRenderEvent,
24+
TurboLoadEvent,
25+
TurboRenderEvent,
26+
TurboStreamAction,
27+
TurboStreamActions,
28+
TurboSubmitEndEvent,
29+
TurboSubmitStartEvent,
30+
TurboVisitEvent,
31+
} from "../../index"
32+
33+
export class ExportTests extends DOMTestCase {
34+
async "test Turbo interface"() {
35+
this.assert.equal(typeof Turbo.start, "function")
36+
this.assert.equal(typeof Turbo.registerAdapter, "function")
37+
this.assert.equal(typeof Turbo.visit, "function")
38+
this.assert.equal(typeof Turbo.connectStreamSource, "function")
39+
this.assert.equal(typeof Turbo.disconnectStreamSource, "function")
40+
this.assert.equal(typeof Turbo.renderStreamMessage, "function")
41+
this.assert.equal(typeof Turbo.clearCache, "function")
42+
this.assert.equal(typeof Turbo.setProgressBarDelay, "function")
43+
this.assert.equal(typeof Turbo.setConfirmMethod, "function")
44+
this.assert.equal(typeof Turbo.setFormMode, "function")
45+
this.assert.equal(typeof Turbo.cache, "object")
46+
this.assert.equal(typeof Turbo.navigator, "object")
47+
this.assert.equal(typeof Turbo.session, "object")
48+
}
49+
}
50+
51+
ExportTests.registerSuite()

src/tests/unit/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from "./export_tests"
12
export * from "./deprecated_adapter_support_test"
23
export * from "./stream_element_tests"

0 commit comments

Comments
 (0)