deno.land / x / replicache@v10.0.0-beta.0 / replicache-collect-idb-databases.test.ts

replicache-collect-idb-databases.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {expect} from '@esm-bundle/chai';import {clock, initReplicacheTesting, replicacheForTesting} from './test-util';
initReplicacheTesting();
test('collect IDB databases', async () => { if (!indexedDB.databases) { // Firefox does not support indexedDB.databases return; }
const ONE_MINUTE = 1000 * 60 * 1; const FIVE_MINUTES = ONE_MINUTE * 5; const ONE_WEEK = ONE_MINUTE * 60 * 24 * 7; const ONE_MONTH = 1000 * 60 * 60 * 24 * 30;
const rep = await replicacheForTesting('collect-idb-databases-1'); await rep.close();
expect(await getDatabases()).to.deep.equal(['collect-idb-databases-1']);
await clock.tickAsync(ONE_MONTH);
const rep2 = await replicacheForTesting('collect-idb-databases-2'); await rep2.close();
expect(await getDatabases()).to.deep.equal([ 'collect-idb-databases-1', 'collect-idb-databases-2', ]);
await clock.tickAsync(ONE_WEEK);
// Open one more database and keep it open long enough to trigger the collection. const rep3 = await replicacheForTesting('collect-idb-databases-3'); await clock.tickAsync(FIVE_MINUTES); await rep3.close();
expect(await getDatabases()).to.deep.equal([ 'collect-idb-databases-2', 'collect-idb-databases-3', ]);
async function getDatabases() { function parseName(idbName: string | undefined): string | undefined { return idbName && /^rep:[^:]+:([^:]+):\d+$/.exec(idbName)?.[1]; }
return (await indexedDB.databases()) .map(({name}) => parseName(name)) .filter(name => name && name.startsWith('collect-idb-databases')) .sort(); }});
replicache

Version Info

Tagged at
2 years ago