Fix linter warnings

This commit is contained in:
Jared Miller 2026-01-27 20:45:36 -05:00
parent 5275c99976
commit ead57baf6f
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
5 changed files with 51 additions and 26 deletions

View file

@ -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);

View file

@ -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 });

View file

@ -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;
};

View file

@ -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);
});
});

View file

@ -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;