Fix linter warnings
This commit is contained in:
parent
5275c99976
commit
ead57baf6f
5 changed files with 51 additions and 26 deletions
|
|
@ -209,10 +209,16 @@ describe("awareness", () => {
|
|||
open(ws) {
|
||||
// Simulate sending awareness after join
|
||||
setTimeout(() => {
|
||||
ws.send(JSON.stringify({
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: "awareness",
|
||||
data: { clientId: 99, cursor: { line: 3, col: 7 }, name: "peer" }
|
||||
}));
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
ws1.send(
|
||||
JSON.stringify({
|
||||
type: "awareness",
|
||||
data: { clientId: 1, cursor: { line: 10, col: 5 } }
|
||||
}));
|
||||
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 });
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue