Skip to content

Commit 137c51f

Browse files
committed
test: fix test issues
1 parent b311e88 commit 137c51f

File tree

2 files changed

+18
-40
lines changed

2 files changed

+18
-40
lines changed

packages/loro-websocket/tests/e2e.test.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,18 @@ Object.defineProperty(globalThis, "WebSocket", {
2929
describe("E2E: Client-Server Sync", () => {
3030
let server: SimpleServer;
3131
let port: number;
32-
let skip = false;
3332

3433
beforeAll(async () => {
35-
try {
36-
port = await getPort();
37-
server = new SimpleServer({ port });
38-
await server.start();
39-
} catch (e) {
40-
skip = true;
41-
console.warn("Skipping e2e tests: cannot bind port", e);
42-
}
34+
port = await getPort();
35+
server = new SimpleServer({ port });
36+
await server.start();
4337
});
4438

4539
afterAll(async () => {
46-
if (!skip && server) {
47-
await server.stop();
48-
}
40+
await server.stop();
4941
}, 15000);
5042

5143
it("should sync two clients through server", async () => {
52-
if (skip) return;
53-
// Create two clients
54-
if (skip) return;
5544
const client1 = new LoroWebsocketClient({ url: `ws://localhost:${port}` });
5645
const client2 = new LoroWebsocketClient({ url: `ws://localhost:${port}` });
5746

@@ -208,7 +197,6 @@ describe("E2E: Client-Server Sync", () => {
208197
}, 10000);
209198

210199
it("should resolve ping() with pong", async () => {
211-
if (skip) return;
212200
const client = new LoroWebsocketClient({ url: `ws://localhost:${port}` });
213201
await client.waitConnected();
214202

@@ -217,7 +205,6 @@ describe("E2E: Client-Server Sync", () => {
217205
}, 10000);
218206

219207
it("emits correct status transitions across reconnects and manual close/connect", async () => {
220-
if (skip) return;
221208
const client = new LoroWebsocketClient({ url: `ws://localhost:${port}` });
222209

223210
const seen: string[] = [];
@@ -443,9 +430,9 @@ describe("E2E: Client-Server Sync", () => {
443430
await waitUntil(
444431
() =>
445432
statuses1.filter(s => s === ClientStatus.Connected).length >
446-
initialConnected1 &&
433+
initialConnected1 &&
447434
statuses2.filter(s => s === ClientStatus.Connected).length >
448-
initialConnected2,
435+
initialConnected2,
449436
5000,
450437
25
451438
);
@@ -658,7 +645,7 @@ describe("E2E: Client-Server Sync", () => {
658645
setTimeout(() => {
659646
try {
660647
ws.close(1008, "policy");
661-
} catch {}
648+
} catch { }
662649
}, 30);
663650
}
664651
});
@@ -993,7 +980,7 @@ describe("E2E: RoomError rejoin policy", () => {
993980
const adaptor = new LoroAdaptor();
994981
await client.join({ roomId: "room-rejoin", crdtAdaptor: adaptor });
995982

996-
await waitUntil(() => joinCount >= 2, 5000, 20).catch(() => {});
983+
await waitUntil(() => joinCount >= 2, 5000, 20).catch(() => { });
997984
// Ensure no extra rejoins
998985
await new Promise(r => setTimeout(r, 200));
999986
expect(joinCount).toBe(2);

packages/loro-websocket/tests/permission.test.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,24 @@ Object.defineProperty(globalThis, "WebSocket", {
1717
describe("Permission Enforcement", () => {
1818
let server: SimpleServer;
1919
let port: number;
20-
let skip = false;
2120

2221
beforeAll(async () => {
23-
try {
24-
port = await getPort();
25-
server = new SimpleServer({
26-
port,
27-
authenticate: async (_roomId, _crdtType, auth) => {
28-
const authStr = new TextDecoder().decode(auth);
29-
return authStr === "readonly" ? "read" : "write";
30-
},
31-
});
32-
await server.start();
33-
} catch (e) {
34-
skip = true;
35-
console.warn("Skipping permission tests: cannot bind port", e);
36-
}
22+
port = await getPort();
23+
server = new SimpleServer({
24+
port,
25+
authenticate: async (_roomId, _crdtType, auth) => {
26+
const authStr = new TextDecoder().decode(auth);
27+
return authStr === "readonly" ? "read" : "write";
28+
},
29+
});
30+
await server.start();
3731
});
3832

3933
afterAll(async () => {
40-
if (!skip && server) {
41-
await server.stop();
42-
}
34+
await server.stop();
4335
}, 10000);
4436

4537
it("should allow read-only client to receive updates but not send them", async () => {
46-
if (skip) return;
4738
// Create two clients: one with write permission, one with read permission
4839
const writeClient = new LoroWebsocketClient({
4940
url: `ws://localhost:${port}`,

0 commit comments

Comments
 (0)