Open History to see the last commit
1import * as Cause from "effect/Cause";
2import { AsyncResult, AtomRegistry } from "effect/reactivity";
3import { describe, expect, it, vi } from "vite-plus/test";
4
5import { connectionAtomRuntime } from "./runtime";
6
7function visit(path: string): Disposable {
8 const previous = `${window.location.pathname}${window.location.search}`;
9 window.history.replaceState(window.history.state, "", path);
10 return {
11 [Symbol.dispose]: () => window.history.replaceState(window.history.state, "", previous),
12 };
13}
14
15describe("connectionAtomRuntime", () => {
16 it("connects to no environment on the guest page", async () => {
17 using _page = visit("/guest?share=share-1");
18 using socket = vi.spyOn(window, "WebSocket");
19 const registry = AtomRegistry.make();
20 using _mounted = { [Symbol.dispose]: registry.mount(connectionAtomRuntime) };
21 await vi.waitFor(() => {
22 const result = registry.get(connectionAtomRuntime);
23 expect(AsyncResult.isFailure(result) && String(Cause.squash(result.cause))).toContain(
24 "The guest page has no environment connection.",
25 );
26 });
27 expect(socket).not.toHaveBeenCalled();
28 });
29});