Squash of the patch of item 0x4ac69e554cfa29c1fb7819e9835c17153233e73e72ecb0b821628233c820eb3c, final in the elffuss ledger. Solver 0xdd8075ba73c2173b9f05957b5f1a7561600e5494; 2 approvals of round 0. T2T-Item: 0x4ac69e554cfa29c1fb7819e9835c17153233e73e72ecb0b821628233c820eb3c T2T-Issue: 0xb8d7c6d9815eb6af5efae391d136467cda8c028200c2b5ec5a36fa6620196c53 T2T-Event: 0x96cb4689693dca2b068c24579b325bee24f431c0e6c31a1d7f0b39f8810f534f
32 lines
1012 B
JavaScript
32 lines
1012 B
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
const mod = await import('../../../web/js/model-cache.js')
|
|
|
|
function setNavigator(value) {
|
|
Object.defineProperty(globalThis, 'navigator', { value, configurable: true, writable: true })
|
|
}
|
|
|
|
test('criterion 1', async () => {
|
|
const removed = []
|
|
const deletedCaches = []
|
|
const root = {
|
|
async removeEntry(name, opts) { removed.push([name, opts]) },
|
|
}
|
|
setNavigator({ storage: { getDirectory: async () => root } })
|
|
globalThis.caches = { delete: async (n) => { deletedCaches.push(n); return true } }
|
|
|
|
await mod.clearModelCache()
|
|
|
|
assert.ok(removed.some(([n]) => n === 'elffuss-models'))
|
|
assert.deepEqual(deletedCaches, ['elffuss-models-v1'])
|
|
})
|
|
|
|
test('criterion 2', async () => {
|
|
let calls = 0
|
|
setNavigator({ storage: { getDirectory: async () => { calls++; throw new Error('sin OPFS') } } })
|
|
globalThis.caches = { delete: async () => true }
|
|
|
|
await assert.doesNotReject(mod.clearModelCache())
|
|
assert.equal(calls, 1)
|
|
})
|