v1rtlV
Denoβ€’4y ago
v1rtl

Closing a websocket server in a unit test

Hello, I'm an author of rpc lib and I'm currently writing unit tests for it. I am facing a problem of closing a server. How should I do it without
deno
hanging forever?

my test case:
import { send, App } from './mod.ts'

Deno.test('send', async (t) => {
  await t.step('should send a message with websocket', async () => {
    const app = new App()
    await app.listen({ port: 8881, hostname: 'localhost' })

    const socket = new WebSocket('ws://localhost:8881')
    socket.onopen = () => {
      send(socket, { hello: 'world' })
      socket.close()
      app.close()
    }
  })
})


app.listen
here both starts the
Deno.listener
and
Deno.serveHttp
GitHub
πŸ“‘ JSONRPC server implementation for Deno. Contribute to deno-libs/rpc development by creating an account on GitHub.
GitHub - deno-libs/rpc: πŸ“‘ JSONRPC server implementation for Deno
Was this page helpful?