Skip to content
File

Blob: worker/tests/runtime/harness.ts

typescript30 lines
1import { vi } from 'vitest';
2import { env, exports } from 'cloudflare:workers';
3import { evictDurableObject } from 'cloudflare:test';
4import { createRadioClient, createSfu } from '@tests/helpers/sfu-fixture.ts';
5import type { Responder } from '@tests/helpers/sfu-fixture.ts';
6 
7export {
8 device,
9 offer,
10 answer,
11 track,
12 nowPlaying,
13 startedSchema,
14} from '@tests/helpers/sfu-fixture.ts';
15export function createHarness(respond?: Responder) {
16 const sfu = createSfu(respond);
17 vi.stubGlobal('fetch', (input: RequestInfo | URL, init?: RequestInit) =>
18 sfu.fetch(new Request(input, init)),
19 );
20 const api = createRadioClient((request) => exports.default.fetch(request));
21 const room = env.ROBOTS.getByName(env.ROBOT_NAME);
22 return {
23 ...api,
24 calls: sfu.calls,
25 allocations: sfu.allocations,
26 room,
27 evict: () => evictDurableObject(room),
28 };
29}