Skip to content

Commit e7a489c

Browse files
committed
Use fallback for Cache API if not supported in CI
1 parent 2c4bc54 commit e7a489c

File tree

4 files changed

+66
-14
lines changed

4 files changed

+66
-14
lines changed

src/components/cylc/workspace/Lumino.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { watchWithControl } from '@/utils/reactivity'
4747
import { replacer, reviver } from '@/utils/json'
4848
import { useDefaultView } from '@/views/views'
4949
import { eventBus } from '@/services/eventBus'
50+
import { useWorkspaceLayoutsCache } from '@/composables/cacheStorage'
5051
5152
import '@lumino/default-theme/style'
5253
@@ -113,7 +114,7 @@ const resizeObserver = new ResizeObserver(() => {
113114
boxPanel.update()
114115
})
115116
116-
const layoutsCache = window.caches.open('workspace-layouts')
117+
const layoutsCache = useWorkspaceLayoutsCache()
117118
const layoutWatcher = watchWithControl(views, saveLayout, { deep: true })
118119
119120
onMounted(async () => {

src/composables/cacheStorage.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
/** @type {Map<string,Response>} */
19+
const fallbackStore = new Map()
20+
21+
/**
22+
* Returns a Cache object for storing workspace layouts.
23+
*
24+
* This uses CacheStorage if available, otherwise falls back to a non-persistent store.
25+
*
26+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage
27+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Cache
28+
*/
29+
export function useWorkspaceLayoutsCache () {
30+
return window.caches?.open('workspace-layouts') ?? Promise.resolve({
31+
// Fallback for environments without Cache API support (e.g. Cypress Firefox on GH Actions).
32+
// Does not persist across page reloads, but oh well.
33+
async match (key) {
34+
console.error('Cache API not available; falling back to non-persistent store for workspace layouts.')
35+
return fallbackStore.get(key)?.clone()
36+
},
37+
async put (key, value) {
38+
fallbackStore.delete(key)
39+
fallbackStore.set(key, value)
40+
},
41+
async delete (key) {
42+
fallbackStore.delete(key)
43+
},
44+
async keys () {
45+
return Array.from(fallbackStore.keys())
46+
},
47+
})
48+
}

tests/e2e/specs/workspace.cy.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ describe('Workspace view and component/widget', () => {
107107
})
108108

109109
it('Saves and restores layout when navigating', () => {
110-
cy.clearLayoutsCache(false)
111110
// We will drag tab to the right to split into 2 panes
112111
const dragOptions = { clientX: 950, clientY: 330, force: true }
113112

@@ -169,9 +168,15 @@ describe('Workspace view and component/widget', () => {
169168
cy.visit('/#/workspace/one')
170169
expectRememberedLayout()
171170

172-
// Refresh
173-
cy.reload()
174-
expectRememberedLayout()
171+
cy.window().then((win) => {
172+
if (win.caches) {
173+
// Test page refresh
174+
cy.reload()
175+
expectRememberedLayout()
176+
} else {
177+
cy.log('Cache API not supported; skipping page refresh test.')
178+
}
179+
})
175180
})
176181

177182
it('Resets layout', () => {

tests/e2e/support/commands.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@
4141
// -- This is will overwrite an existing command --
4242
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
4343

44-
Cypress.Commands.add('clearLayoutsCache', (value = true) => {
45-
// Clear any stored workspace layouts (or not)
46-
Cypress.env('clearLayoutsCache', value)
47-
})
48-
49-
Cypress.on('window:before:load', async (win) => {
50-
if (Cypress.env('clearLayoutsCache')) {
51-
await win.caches.delete('workspace-layouts')
52-
}
44+
Cypress.Commands.add('clearLayoutsCache', () => {
45+
// Clear any stored workspace layouts
46+
cy.window().then((win) => new Cypress.Promise(
47+
(resolve) => {
48+
win.caches?.delete('workspace-layouts')?.then(resolve) ?? resolve()
49+
}
50+
))
5351
})

0 commit comments

Comments
 (0)