Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ws.test.ts

40 lines1.5 KB

1import { assert, it } from "@effect/vitest";
2import * as Deferred from "effect/Deferred";
3import * as Duration from "effect/Duration";
4import * as Effect from "effect/Effect";
5import * as Fiber from "effect/Fiber";
6import * as TestClock from "effect/testing/TestClock";
7​
8import { hasCompatibleOrchestrationProtocol, resolveAvailableEditorsForConfig } from "./ws.ts";
9import { ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts";
10​
11it("accepts only the current orchestration protocol before websocket RPC setup", () => {
12 assert.isTrue(
13 hasCompatibleOrchestrationProtocol(
14 new URL(`https://host.test/ws?orchestrationProtocol=${ORCHESTRATION_PROTOCOL_VERSION}`),
15 ),
16 );
17 assert.isFalse(hasCompatibleOrchestrationProtocol(new URL("https://host.test/ws")));
18 assert.isFalse(
19 hasCompatibleOrchestrationProtocol(
20 new URL(`https://host.test/ws?orchestrationProtocol=${ORCHESTRATION_PROTOCOL_VERSION - 1}`),
21 ),
22 );
23});
24​
25it.effect("does not block server config when editor discovery never resolves", () =>
26 Effect.gen(function* () {
27 const discoveryInterrupted = yield* Deferred.make<void>();
28 const responseFiber = yield* resolveAvailableEditorsForConfig(
29 Effect.never.pipe(
30 Effect.onInterrupt(() => Deferred.succeed(discoveryInterrupted, undefined)),
31 ),
32 ).pipe(Effect.forkChild);
33​
34 yield* TestClock.adjust(Duration.seconds(5));
35​
36 const availableEditors = yield* Fiber.join(responseFiber);
37 yield* Deferred.await(discoveryInterrupted);
38 assert.deepEqual(availableEditors, []);
39 }),
40);