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 () => {
|
it('CloseEvent should be executed without crash', async () => {
|
||||||
|
const testCode = 3001
|
||||||
|
const testReason = 'Test!'
|
||||||
app.get(
|
app.get(
|
||||||
'/',
|
'/',
|
||||||
upgradeWebSocket(() => ({
|
upgradeWebSocket(() => ({
|
||||||
onClose() {
|
onClose(event) {
|
||||||
// doing some stuff here
|
expect(event.code).toBe(testCode)
|
||||||
|
expect(event.reason).toBe(testReason)
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
|
|
||||||
const ws = new WebSocket('ws://localhost:3030/')
|
const ws = new WebSocket('ws://localhost:3030/')
|
||||||
await new Promise<void>((resolve) => ws.on('open', resolve))
|
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 () => {
|
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', () => {
|
ws.on('close', (code, reason) => {
|
||||||
events.onClose?.(new CloseEvent('close'), ctx)
|
events.onClose?.(new CloseEvent('close', { code, reason: reason.toString() }), ctx)
|
||||||
})
|
})
|
||||||
ws.on('error', (error) => {
|
ws.on('error', (error) => {
|
||||||
events.onError?.(
|
events.onError?.(
|
||||||
|
|
Loading…
Reference in New Issue