diff --git a/adapters/vim/bridge.test.ts b/adapters/vim/bridge.test.ts index b921de9..bf1956b 100644 --- a/adapters/vim/bridge.test.ts +++ b/adapters/vim/bridge.test.ts @@ -209,10 +209,16 @@ describe("awareness", () => { open(ws) { // Simulate sending awareness after join setTimeout(() => { - ws.send(JSON.stringify({ - type: "awareness", - data: { clientId: 99, cursor: { line: 3, col: 7 }, name: "peer" } - })); + ws.send( + JSON.stringify({ + type: "awareness", + data: { + clientId: 99, + cursor: { line: 3, col: 7 }, + name: "peer", + }, + }), + ); }, 100); }, message() {}, @@ -240,14 +246,18 @@ describe("awareness", () => { } })(); - await new Promise(r => setTimeout(r, 50)); - bridge.stdin.write(JSON.stringify({ type: "connect", room: "test" }) + "\n"); - await new Promise(r => setTimeout(r, 200)); + await new Promise((r) => setTimeout(r, 50)); + bridge.stdin.write( + `${JSON.stringify({ type: "connect", room: "test" })}\n`, + ); + await new Promise((r) => setTimeout(r, 200)); - const awarenessMsg = output.join("").split("\n") + const awarenessMsg = output + .join("") + .split("\n") .filter(Boolean) - .map(l => JSON.parse(l)) - .find(m => m.type === "cursor"); + .map((l) => JSON.parse(l)) + .find((m) => m.type === "cursor"); expect(awarenessMsg).toBeDefined(); expect(awarenessMsg.data.line).toBe(3); diff --git a/src/awareness.test.ts b/src/awareness.test.ts index fdc3850..1e3615c 100644 --- a/src/awareness.test.ts +++ b/src/awareness.test.ts @@ -1,4 +1,4 @@ -import { describe, test, expect, beforeAll, afterAll } from "bun:test"; +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import type { Server } from "bun"; describe("awareness routing", () => { @@ -23,8 +23,12 @@ describe("awareness routing", () => { const received: unknown[] = []; await Promise.all([ - new Promise(r => ws1.onopen = r), - new Promise(r => ws2.onopen = r), + new Promise((r) => { + ws1.onopen = r; + }), + new Promise((r) => { + ws2.onopen = r; + }), ]); ws2.onmessage = (e) => { @@ -38,14 +42,16 @@ describe("awareness routing", () => { await Bun.sleep(50); // ws1 sends awareness - ws1.send(JSON.stringify({ - type: "awareness", - data: { clientId: 1, cursor: { line: 10, col: 5 } } - })); + ws1.send( + JSON.stringify({ + type: "awareness", + data: { clientId: 1, cursor: { line: 10, col: 5 } }, + }), + ); await Bun.sleep(50); - const awareness = received.find(m => m.type === "awareness"); + const awareness = received.find((m) => m.type === "awareness"); expect(awareness).toBeDefined(); expect(awareness.data.cursor).toEqual({ line: 10, col: 5 }); diff --git a/src/protocol.ts b/src/protocol.ts index 5516a27..8ce100f 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -9,7 +9,12 @@ export type ClientMessage = export type AwarenessState = { clientId: number; cursor?: { line: number; col: number }; - selection?: { startLine: number; startCol: number; endLine: number; endCol: number }; + selection?: { + startLine: number; + startCol: number; + endLine: number; + endCol: number; + }; name?: string; }; diff --git a/src/session.test.ts b/src/session.test.ts index 26703e1..f55e148 100644 --- a/src/session.test.ts +++ b/src/session.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; import * as Y from "yjs"; -import { getOrCreateSession, Session, type Client, type WsData } from "./session"; +import { type Client, type WsData, getOrCreateSession, Session } from "./session"; describe("Session", () => { test("creates yjs doc on init", () => { @@ -64,8 +64,12 @@ describe("awareness", () => { const sent1: unknown[] = []; const sent2: unknown[] = []; - const client1 = { ws: { send: (m: string) => sent1.push(JSON.parse(m)) } } as Client; - const client2 = { ws: { send: (m: string) => sent2.push(JSON.parse(m)) } } as Client; + const client1 = { + ws: { send: (m: string) => sent1.push(JSON.parse(m)) }, + } as Client; + const client2 = { + ws: { send: (m: string) => sent2.push(JSON.parse(m)) }, + } as Client; session.join(client1); session.join(client2); @@ -74,9 +78,9 @@ describe("awareness", () => { session.broadcastAwareness(client1, awareness); // client1 should NOT receive their own awareness - expect(sent1.filter(m => m.type === "awareness")).toHaveLength(0); + expect(sent1.filter((m) => m.type === "awareness")).toHaveLength(0); // client2 should receive it - expect(sent2.filter(m => m.type === "awareness")).toHaveLength(1); - expect(sent2.find(m => m.type === "awareness")?.data).toEqual(awareness); + expect(sent2.filter((m) => m.type === "awareness")).toHaveLength(1); + expect(sent2.find((m) => m.type === "awareness")?.data).toEqual(awareness); }); }); diff --git a/src/session.ts b/src/session.ts index b4a6ba2..088fbe7 100644 --- a/src/session.ts +++ b/src/session.ts @@ -1,6 +1,6 @@ import type { ServerWebSocket } from "bun"; import * as Y from "yjs"; -import { encode, type AwarenessState } from "./protocol"; +import { type AwarenessState, encode } from "./protocol"; export interface WsData { room: string | null;