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) {
|
open(ws) {
|
||||||
// Simulate sending awareness after join
|
// Simulate sending awareness after join
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ws.send(JSON.stringify({
|
ws.send(
|
||||||
type: "awareness",
|
JSON.stringify({
|
||||||
data: { clientId: 99, cursor: { line: 3, col: 7 }, name: "peer" }
|
type: "awareness",
|
||||||
}));
|
data: {
|
||||||
|
clientId: 99,
|
||||||
|
cursor: { line: 3, col: 7 },
|
||||||
|
name: "peer",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
}, 100);
|
}, 100);
|
||||||
},
|
},
|
||||||
message() {},
|
message() {},
|
||||||
|
|
@ -240,14 +246,18 @@ describe("awareness", () => {
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
await new Promise(r => setTimeout(r, 50));
|
await new Promise((r) => setTimeout(r, 50));
|
||||||
bridge.stdin.write(JSON.stringify({ type: "connect", room: "test" }) + "\n");
|
bridge.stdin.write(
|
||||||
await new Promise(r => setTimeout(r, 200));
|
`${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)
|
.filter(Boolean)
|
||||||
.map(l => JSON.parse(l))
|
.map((l) => JSON.parse(l))
|
||||||
.find(m => m.type === "cursor");
|
.find((m) => m.type === "cursor");
|
||||||
|
|
||||||
expect(awarenessMsg).toBeDefined();
|
expect(awarenessMsg).toBeDefined();
|
||||||
expect(awarenessMsg.data.line).toBe(3);
|
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";
|
import type { Server } from "bun";
|
||||||
|
|
||||||
describe("awareness routing", () => {
|
describe("awareness routing", () => {
|
||||||
|
|
@ -23,8 +23,12 @@ describe("awareness routing", () => {
|
||||||
const received: unknown[] = [];
|
const received: unknown[] = [];
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
new Promise(r => ws1.onopen = r),
|
new Promise((r) => {
|
||||||
new Promise(r => ws2.onopen = r),
|
ws1.onopen = r;
|
||||||
|
}),
|
||||||
|
new Promise((r) => {
|
||||||
|
ws2.onopen = r;
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ws2.onmessage = (e) => {
|
ws2.onmessage = (e) => {
|
||||||
|
|
@ -38,14 +42,16 @@ describe("awareness routing", () => {
|
||||||
await Bun.sleep(50);
|
await Bun.sleep(50);
|
||||||
|
|
||||||
// ws1 sends awareness
|
// ws1 sends awareness
|
||||||
ws1.send(JSON.stringify({
|
ws1.send(
|
||||||
type: "awareness",
|
JSON.stringify({
|
||||||
data: { clientId: 1, cursor: { line: 10, col: 5 } }
|
type: "awareness",
|
||||||
}));
|
data: { clientId: 1, cursor: { line: 10, col: 5 } },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
await Bun.sleep(50);
|
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).toBeDefined();
|
||||||
expect(awareness.data.cursor).toEqual({ line: 10, col: 5 });
|
expect(awareness.data.cursor).toEqual({ line: 10, col: 5 });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,12 @@ export type ClientMessage =
|
||||||
export type AwarenessState = {
|
export type AwarenessState = {
|
||||||
clientId: number;
|
clientId: number;
|
||||||
cursor?: { line: number; col: 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;
|
name?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import * as Y from "yjs";
|
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", () => {
|
describe("Session", () => {
|
||||||
test("creates yjs doc on init", () => {
|
test("creates yjs doc on init", () => {
|
||||||
|
|
@ -64,8 +64,12 @@ describe("awareness", () => {
|
||||||
const sent1: unknown[] = [];
|
const sent1: unknown[] = [];
|
||||||
const sent2: unknown[] = [];
|
const sent2: unknown[] = [];
|
||||||
|
|
||||||
const client1 = { ws: { send: (m: string) => sent1.push(JSON.parse(m)) } } as Client;
|
const client1 = {
|
||||||
const client2 = { ws: { send: (m: string) => sent2.push(JSON.parse(m)) } } as Client;
|
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(client1);
|
||||||
session.join(client2);
|
session.join(client2);
|
||||||
|
|
@ -74,9 +78,9 @@ describe("awareness", () => {
|
||||||
session.broadcastAwareness(client1, awareness);
|
session.broadcastAwareness(client1, awareness);
|
||||||
|
|
||||||
// client1 should NOT receive their own 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
|
// client2 should receive it
|
||||||
expect(sent2.filter(m => m.type === "awareness")).toHaveLength(1);
|
expect(sent2.filter((m) => m.type === "awareness")).toHaveLength(1);
|
||||||
expect(sent2.find(m => m.type === "awareness")?.data).toEqual(awareness);
|
expect(sent2.find((m) => m.type === "awareness")?.data).toEqual(awareness);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import type { ServerWebSocket } from "bun";
|
import type { ServerWebSocket } from "bun";
|
||||||
import * as Y from "yjs";
|
import * as Y from "yjs";
|
||||||
import { encode, type AwarenessState } from "./protocol";
|
import { type AwarenessState, encode } from "./protocol";
|
||||||
|
|
||||||
export interface WsData {
|
export interface WsData {
|
||||||
room: string | null;
|
room: string | null;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue