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
import {expect} from '@esm-bundle/chai';import {sleep} from '../sleep';import {closeAllReps, dbsToDrop, deleteAllDatabases} from '../test-util';
teardown(async () => { await closeAllReps(); await deleteAllDatabases();});
// This started failing on github only with https://github.com/rocicorp/replicache/pull/479.// It works fine locally. Error message is:// src/worker.test.ts://// ❌ worker test (failed on Chromium)// Error: Timed out// at src/worker.test.ts:42:42// at async o.<anonymous> (src/worker.test.ts:17:17)//// Example failure: https://github.com/rocicorp/replicache/runs/3519251318test.skip('worker test', async () => { const url = new URL('./worker-test.ts', import.meta.url); const w = new Worker(url, {type: 'module'}); const name = 'worker-test'; dbsToDrop.add(name);
const data = await send(w, {name}); expect(data).to.be.undefined;});
async function send(w: Worker, data: {name: string}): Promise<unknown> { const p = new Promise((resolve, reject) => { w.onmessage = e => resolve(e.data); w.onerror = reject; w.onmessageerror = reject; }); w.postMessage(data); return withTimeout(p);}
async function withTimeout<T>(p: Promise<T>): Promise<T> { return Promise.race([ p, sleep(3000).then(() => Promise.reject(new Error('Timed out'))), ]);}
replicache

Version Info

Tagged at
2 years ago