File
Blob: worker/tests/runtime/harness.ts
| 1 | import { vi } from 'vitest'; |
| 2 | import { env, exports } from 'cloudflare:workers'; |
| 3 | import { evictDurableObject } from 'cloudflare:test'; |
| 4 | import { createRadioClient, createSfu } from '@tests/helpers/sfu-fixture.ts'; |
| 5 | import type { Responder } from '@tests/helpers/sfu-fixture.ts'; |
| 6 | |
| 7 | export { |
| 8 | device, |
| 9 | offer, |
| 10 | answer, |
| 11 | track, |
| 12 | nowPlaying, |
| 13 | startedSchema, |
| 14 | } from '@tests/helpers/sfu-fixture.ts'; |
| 15 | export 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 | } |