@rljson/server 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.architecture.md +1352 -0
- package/README.blog.md +9 -1
- package/README.contributors.md +47 -13
- package/README.md +78 -11
- package/README.public.md +600 -7
- package/README.trouble.md +50 -0
- package/dist/README.architecture.md +1352 -0
- package/dist/README.blog.md +9 -1
- package/dist/README.contributors.md +47 -13
- package/dist/README.md +78 -11
- package/dist/README.public.md +600 -7
- package/dist/README.trouble.md +50 -0
- package/dist/client.d.ts +75 -3
- package/dist/index.d.ts +6 -0
- package/dist/logger.d.ts +115 -0
- package/dist/server.d.ts +148 -7
- package/dist/server.js +858 -118
- package/dist/socket-bundle.d.ts +16 -0
- package/package.json +17 -17
package/README.trouble.md
CHANGED
|
@@ -11,6 +11,7 @@ found in the LICENSE file in the root of this package.
|
|
|
11
11
|
## Table of contents <!-- omit in toc -->
|
|
12
12
|
|
|
13
13
|
- [Vscode Windows: Debugging is not working](#vscode-windows-debugging-is-not-working)
|
|
14
|
+
- [Test Isolation: Socket.IO event listener accumulation](#test-isolation-socketio-event-listener-accumulation)
|
|
14
15
|
|
|
15
16
|
## Vscode Windows: Debugging is not working
|
|
16
17
|
|
|
@@ -21,3 +22,52 @@ in the VS Code Vitest extension (v1.14.4), which prevents test debugging from
|
|
|
21
22
|
working: <https://github.com/vitest-dev/vscode/issues/548> Please check from
|
|
22
23
|
time to time if the issue has been fixed and remove this note once it is
|
|
23
24
|
resolved.
|
|
25
|
+
|
|
26
|
+
## Test Isolation: Socket.IO event listener accumulation
|
|
27
|
+
|
|
28
|
+
Date: 2025-01-28
|
|
29
|
+
|
|
30
|
+
**Problem:**
|
|
31
|
+
|
|
32
|
+
When running multiple tests that use Socket.IO connections, tests pass individually but fail when run together. This is caused by event listeners from previous tests remaining active on persistent socket instances.
|
|
33
|
+
|
|
34
|
+
**Symptoms:**
|
|
35
|
+
|
|
36
|
+
- Individual tests pass: ✅
|
|
37
|
+
- All tests together fail: ❌
|
|
38
|
+
- Error messages like "received 0 instead of expected number of nodes"
|
|
39
|
+
- Unexpected behavior when sockets receive messages from previous tests
|
|
40
|
+
|
|
41
|
+
**Root Cause:**
|
|
42
|
+
|
|
43
|
+
Socket.IO sockets persist across tests in the `beforeAll` setup. When `SocketIoBridge` instances are created in `beforeEach`, old event listeners accumulate on the underlying sockets, causing interference between tests.
|
|
44
|
+
|
|
45
|
+
**Solution:**
|
|
46
|
+
|
|
47
|
+
Clear all event listeners in `beforeEach` before creating new bridges:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
beforeEach(async () => {
|
|
51
|
+
// Remove all event listeners from previous test to prevent interference
|
|
52
|
+
serverSockets.forEach((socket) => socket.removeAllListeners());
|
|
53
|
+
clientSockets.forEach((socket) => socket.removeAllListeners());
|
|
54
|
+
|
|
55
|
+
// Now proceed with test setup...
|
|
56
|
+
server = new Server(route, serverIo, serverBs);
|
|
57
|
+
await server.init();
|
|
58
|
+
// ... rest of setup
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Why This Works:**
|
|
63
|
+
|
|
64
|
+
- `removeAllListeners()` clears accumulated event handlers
|
|
65
|
+
- Each test starts with clean sockets
|
|
66
|
+
- No interference from previous test's `SocketIoBridge` instances
|
|
67
|
+
- Maintains socket connections established in `beforeAll`
|
|
68
|
+
|
|
69
|
+
**Alternative Approaches Considered:**
|
|
70
|
+
|
|
71
|
+
1. ❌ `tearDown()` in `afterEach`: Caused hook timeouts
|
|
72
|
+
2. ❌ Creating new socket connections per test: Too slow, defeats purpose of `beforeAll`
|
|
73
|
+
3. ✅ Clear listeners while reusing connections: Fast and reliable
|