parent
abb260632f
commit
237bff1b82
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@hono/node-ws': patch
|
||||
---
|
||||
|
||||
Fix missing code and reason on `CloseEvent`
|
|
@ -170,18 +170,21 @@ describe('WebSocket helper', () => {
|
|||
})
|
||||
|
||||
it('CloseEvent should be executed without crash', async () => {
|
||||
const testCode = 3001
|
||||
const testReason = 'Test!'
|
||||
app.get(
|
||||
'/',
|
||||
upgradeWebSocket(() => ({
|
||||
onClose() {
|
||||
// doing some stuff here
|
||||
onClose(event) {
|
||||
expect(event.code).toBe(testCode)
|
||||
expect(event.reason).toBe(testReason)
|
||||
},
|
||||
}))
|
||||
)
|
||||
|
||||
const ws = new WebSocket('ws://localhost:3030/')
|
||||
await new Promise<void>((resolve) => ws.on('open', resolve))
|
||||
ws.close()
|
||||
ws.close(testCode, testReason)
|
||||
})
|
||||
|
||||
it('Should be able to send and receive binary content with good length', async () => {
|
||||
|
|
|
@ -126,8 +126,8 @@ export const createNodeWebSocket = (init: NodeWebSocketInit): NodeWebSocket => {
|
|||
)
|
||||
}
|
||||
})
|
||||
ws.on('close', () => {
|
||||
events.onClose?.(new CloseEvent('close'), ctx)
|
||||
ws.on('close', (code, reason) => {
|
||||
events.onClose?.(new CloseEvent('close', { code, reason: reason.toString() }), ctx)
|
||||
})
|
||||
ws.on('error', (error) => {
|
||||
events.onError?.(
|
||||
|
|
Loading…
Reference in New Issue