@atproto/ws-client 0.1.1 → 0.1.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atproto/ws-client
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#5117](https://github.com/bluesky-social/atproto/pull/5117) [`8a4c88b`](https://github.com/bluesky-social/atproto/commit/8a4c88b0f63fb2d82b1391d64c54e0c760fac48b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Make tests less flaky in CI
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/ws-client",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "description": "Websocket client library",
6
6
  "keywords": [
@@ -23,6 +23,7 @@
23
23
  "devDependencies": {
24
24
  "@types/ws": "^8.5.4",
25
25
  "get-port": "^6.1.2",
26
+ "http-terminator": "^3.2.0",
26
27
  "jest": "^30.0.0"
27
28
  },
28
29
  "type": "module",
@@ -1,4 +1,8 @@
1
- import getPort from 'get-port'
1
+ import { once } from 'node:events'
2
+ import { createServer } from 'node:http'
3
+ import { AddressInfo } from 'node:net'
4
+ // eslint-disable-next-line import/default
5
+ import httpTerminator from 'http-terminator'
2
6
  import { WebSocketServer } from 'ws'
3
7
  import { wait } from '@atproto/common'
4
8
  import { CloseCode, WebSocketKeepAlive } from '../src/index.js'
@@ -7,11 +11,17 @@ describe('WebSocketKeepAlive', () => {
7
11
  it('uses a heartbeat to reconnect if a connection is dropped', async () => {
8
12
  // we run a server that, on first connection, pauses for longer than the heartbeat interval (doesn't return "pong"s)
9
13
  // on second connection, it sends a message and then closes
10
- const port = await getPort()
11
- const server = new WebSocketServer({ port })
14
+
15
+ const server = createServer()
16
+
17
+ // make sure to always close the server (even in case of test failure)
18
+ const { terminate } = httpTerminator.createHttpTerminator({ server })
19
+ await using _ = { [Symbol.asyncDispose]: async () => terminate() }
20
+
21
+ const wsServer = new WebSocketServer({ server })
12
22
  let firstConnection = true
13
23
  let firstWasClosed = false
14
- server.on('connection', async (socket) => {
24
+ wsServer.on('connection', async (socket) => {
15
25
  if (firstConnection === true) {
16
26
  firstConnection = false
17
27
  socket.pause()
@@ -32,6 +42,9 @@ describe('WebSocketKeepAlive', () => {
32
42
  }
33
43
  })
34
44
 
45
+ await once(server.listen(0), 'listening')
46
+ const port = (server.address() as AddressInfo).port
47
+
35
48
  const wsKeepAlive = new WebSocketKeepAlive({
36
49
  getUrl: async () => `ws://localhost:${port}`,
37
50
  heartbeatIntervalMs: 500,
@@ -45,6 +58,5 @@ describe('WebSocketKeepAlive', () => {
45
58
  expect(messages).toHaveLength(1)
46
59
  expect(Buffer.from(messages[0]).toString()).toBe('test message')
47
60
  expect(firstWasClosed).toBe(true)
48
- server.close()
49
61
  })
50
62
  })