Diffinery

homeflare/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

diffinery/apps/diffinery/test/unit/stubs/cloudflare-sockets.ts
13 lines · 536 BRaw History
1/** Stand-in for the Workers runtime's `cloudflare:sockets` module: a unit test sets what connect() returns with setConnect. */
2type Connect = (address: { hostname: string; port: number } | string, options?: { secureTransport?: string; allowHalfOpen: boolean }) => Socket;
3
4let fake: Connect | null = null;
5
6export function setConnect(fn: Connect | null): void {
7 fake = fn;
8}
9
10export const connect: Connect = (address, options) => {
11 if (!fake) throw new Error("this test set no fake connect()");
12 return fake(address, options);
13};