Skip to content

Commit 1666fb1

Browse files
committed
test(rpc): address review feedback on ws regression test
- Drop unnecessary `as any` casts on `definitions` — the local map type is structurally compatible with the transport's expected shape. - Allocate the port via `get-port-please` instead of hardcoding `3334`, matching the pattern in `adapters/__tests__/dev.test.ts` and avoiding flakes when the port is already in use.
1 parent 517f6b2 commit 1666fb1

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

packages/devframe/src/rpc/transports/ws.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getPort } from 'get-port-please'
12
import { describe, expect, it, vi } from 'vitest'
23
import { WebSocket } from 'ws'
34
import { createRpcClient } from '../client'
@@ -57,8 +58,8 @@ describe('devtools rpc', () => {
5758
// WS serializer with DF0020 because the error envelope was strict-JSON-encoded
5859
// alongside the result path.
5960
it('returns a rejection (not a serialization crash) when a jsonSerializable RPC throws', async () => {
60-
const PORT = 3334
6161
const HOST = '127.0.0.1'
62+
const PORT = await getPort({ port: 3334, host: HOST })
6263
const WS_URL = `ws://${HOST}:${PORT}`
6364

6465
const serverFunctions = {
@@ -72,11 +73,11 @@ describe('devtools rpc', () => {
7273
])
7374

7475
const server = createRpcServer<Record<string, never>, typeof serverFunctions>(serverFunctions)
75-
const { wss } = attachWsRpcTransport(server, { port: PORT, host: HOST, definitions: definitions as any })
76+
const { wss } = attachWsRpcTransport(server, { port: PORT, host: HOST, definitions })
7677

7778
try {
7879
const client = createRpcClient<typeof serverFunctions, Record<string, never>>({}, {
79-
channel: createWsRpcChannel({ url: WS_URL, definitions: definitions as any }),
80+
channel: createWsRpcChannel({ url: WS_URL, definitions }),
8081
})
8182

8283
await expect(client.$call('explode')).rejects.toThrow(/boom/)

0 commit comments

Comments
 (0)