deno.land / x / replicache@v10.0.0-beta.0 / worker-tests / worker-test.ts

worker-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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// This test file is loaded by worker.test.ts
import {ReplicacheTest} from '../test-util';import type {ReadTransaction, WriteTransaction} from '../transactions';import {asyncIterableToArray} from '../async-iterable-to-array';import {expect} from '@esm-bundle/chai';import type {JSONValue} from '../json';import {closeAllReps, reps} from '../test-util';import {TEST_LICENSE_KEY} from '@rocicorp/licensing/src/client';
onmessage = async (e: MessageEvent) => { const {name} = e.data; try { await testGetHasScanOnEmptyDB(name); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore TypeScripts type defs are incorrect. postMessage(undefined); await closeAllReps(); } catch (ex) { await closeAllReps(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore TypeScripts type defs are incorrect. postMessage(ex); }};
async function testGetHasScanOnEmptyDB(name: string) { const rep = new ReplicacheTest({ pushDelay: 60_000, // Large to prevent interferin;, name, licenseKey: TEST_LICENSE_KEY, mutators: { testMut: async ( tx: WriteTransaction, args: {key: string; value: JSONValue}, ) => { const {key, value} = args; await tx.put(key, value); expect(await tx.has(key)).to.equal(true); const v = await tx.get(key); expect(v).to.deep.equal(value);
expect(await tx.del(key)).to.equal(true); expect(await tx.has(key)).to.be.false; }, }, }); reps.add(rep);
const {testMut} = rep.mutate;
for (const [key, value] of Object.entries({ a: true, b: false, c: null, d: 'string', e: 12, f: {}, g: [], h: {h1: true}, i: [0, 1], })) { await testMut({key, value: value as JSONValue}); }
async function t(tx: ReadTransaction) { expect(await tx.get('key')).to.equal(undefined); expect(await tx.has('key')).to.be.false;
const scanItems = await asyncIterableToArray(tx.scan()); expect(scanItems).to.have.length(0); }
await rep.query(t);}
replicache

Version Info

Tagged at
2 years ago