Skip to content

Commit

Permalink
Fix lint violations
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Jun 19, 2022
1 parent 88bf29a commit c0b6bb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/core/drive/preloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface PreloaderDelegate {

export class Preloader {
readonly delegate: PreloaderDelegate
readonly selector: string = 'a[data-turbo-preload]'
readonly selector: string = "a[data-turbo-preload]"

constructor(delegate: PreloaderDelegate) {
this.delegate = delegate
Expand All @@ -19,10 +19,10 @@ export class Preloader {
}

start() {
if (document.readyState === 'loading') {
return document.addEventListener('DOMContentLoaded', () => {
if (document.readyState === "loading") {
return document.addEventListener("DOMContentLoaded", () => {
this.preloadOnLoadLinksForView(document.body)
});
})
} else {
this.preloadOnLoadLinksForView(document.body)
}
Expand All @@ -42,12 +42,12 @@ export class Preloader {
}

try {
const response = await fetch(location.toString(), { headers: { 'VND.PREFETCH': 'true', 'Accept': 'text/html' } })
const response = await fetch(location.toString(), { headers: { "VND.PREFETCH": "true", Accept: "text/html" } })
const responseText = await response.text()
const snapshot = PageSnapshot.fromHTMLString(responseText)

this.snapshotCache.put(location, snapshot)
} catch(_) {
} catch (_) {
// If we cannot preload that is ok!
}
}
Expand Down
38 changes: 22 additions & 16 deletions src/tests/functional/preloader_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export class PreloaderTests extends TurboDriveTestCase {
await this.goToLocation("/src/tests/fixtures/preloading.html")
await this.nextBeat

this.assert.ok(await this.remote.execute(() => {
const preloadedUrl = "http://localhost:9000/src/tests/fixtures/preloaded.html"
const cache = window.Turbo.session.preloader.snapshotCache.snapshots

return preloadedUrl in cache
}))
this.assert.ok(
await this.remote.execute(() => {
const preloadedUrl = "http://localhost:9000/src/tests/fixtures/preloaded.html"
const cache = window.Turbo.session.preloader.snapshotCache.snapshots

return preloadedUrl in cache
})
)
}

async "test preloads snapshot on page visit"() {
Expand All @@ -23,12 +25,14 @@ export class PreloaderTests extends TurboDriveTestCase {
await this.waitUntilSelector("#preload_anchor")
await this.nextBeat

this.assert.ok(await this.remote.execute(() => {
const preloadedUrl = "http://localhost:9000/src/tests/fixtures/preloaded.html"
const cache = window.Turbo.session.preloader.snapshotCache.snapshots
this.assert.ok(
await this.remote.execute(() => {
const preloadedUrl = "http://localhost:9000/src/tests/fixtures/preloaded.html"
const cache = window.Turbo.session.preloader.snapshotCache.snapshots

return preloadedUrl in cache
}))
return preloadedUrl in cache
})
)
}

async "test navigates to preloaded snapshot from frame"() {
Expand All @@ -37,12 +41,14 @@ export class PreloaderTests extends TurboDriveTestCase {
await this.waitUntilSelector("#frame_preload_anchor")
await this.nextBeat

this.assert.ok(await this.remote.execute(() => {
const preloadedUrl = "http://localhost:9000/src/tests/fixtures/preloaded.html"
const cache = window.Turbo.session.preloader.snapshotCache.snapshots
this.assert.ok(
await this.remote.execute(() => {
const preloadedUrl = "http://localhost:9000/src/tests/fixtures/preloaded.html"
const cache = window.Turbo.session.preloader.snapshotCache.snapshots

return preloadedUrl in cache
}))
return preloadedUrl in cache
})
)
}
}

Expand Down

0 comments on commit c0b6bb6

Please sign in to comment.