Commit 9127cff
fix(nostr): improve NostrSyncService test reliability
Fix test reliability issues in nostr-sync.test.js related to WebSocket
mock behavior and connection state handling.
## nostr-sync.js
- Fix _verifyEventSignature to return explicit boolean (!!)
- Prevents truthy object/string values being interpreted as valid
## nostr-sync.test.js
### WebSocket Mock Improvements
- Create fresh wsInstance per WebSocket call (not shared mock)
- Properly wire addEventListener to set handlers (onopen, onclose, etc.)
- Each test gets isolated WebSocket state
### Test Fixes
- Wait for async connection establishment before assertions
- Use service.nostrKeypair.publicKeyHex instead of undefined mockNostrKeypair
- Create fresh WebSocket mock with proper readyState for publish tests
- Enable debug mode before testing log assertions
- Relax log assertion to expect.anything() for subscription ID
### Connection Error Test Fix
- Restructure failing WebSocket mock to use addEventListener pattern
- Trigger error handler via setTimeout to simulate async behavior
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent fbec137 commit 9127cff
2 files changed
Lines changed: 44 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
620 | | - | |
| 620 | + | |
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
57 | 68 | | |
58 | 69 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
62 | 73 | | |
63 | 74 | | |
64 | | - | |
| 75 | + | |
| 76 | + | |
65 | 77 | | |
66 | 78 | | |
67 | 79 | | |
| |||
216 | 228 | | |
217 | 229 | | |
218 | 230 | | |
219 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
220 | 236 | | |
221 | 237 | | |
222 | 238 | | |
| |||
227 | 243 | | |
228 | 244 | | |
229 | 245 | | |
230 | | - | |
| 246 | + | |
231 | 247 | | |
232 | 248 | | |
233 | 249 | | |
| |||
262 | 278 | | |
263 | 279 | | |
264 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
265 | 284 | | |
266 | 285 | | |
267 | 286 | | |
268 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
269 | 292 | | |
270 | 293 | | |
271 | 294 | | |
| |||
326 | 349 | | |
327 | 350 | | |
328 | 351 | | |
| 352 | + | |
| 353 | + | |
329 | 354 | | |
330 | 355 | | |
331 | 356 | | |
332 | 357 | | |
333 | 358 | | |
334 | 359 | | |
335 | 360 | | |
336 | | - | |
| 361 | + | |
337 | 362 | | |
338 | 363 | | |
339 | 364 | | |
| |||
348 | 373 | | |
349 | 374 | | |
350 | 375 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
357 | 386 | | |
358 | 387 | | |
359 | 388 | | |
| |||
0 commit comments