Merge branch 'fix/node-ws-crashes' of github.com:nakasyou/hono-middleware into fix/node-ws-crashes
commit
8c77d5f9aa
|
@ -1,5 +1,11 @@
|
||||||
# @hono/node-ws
|
# @hono/node-ws
|
||||||
|
|
||||||
|
## 1.1.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1138](https://github.com/honojs/middleware/pull/1138) [`237bff1b82f2c0adfcd015dc97538b36cfb5d418`](https://github.com/honojs/middleware/commit/237bff1b82f2c0adfcd015dc97538b36cfb5d418) Thanks [@leia-uwu](https://github.com/leia-uwu)! - Fix missing code and reason on `CloseEvent`
|
||||||
|
|
||||||
## 1.1.1
|
## 1.1.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@hono/node-ws",
|
"name": "@hono/node-ws",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"description": "WebSocket helper for Node.js",
|
"description": "WebSocket helper for Node.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|
|
@ -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 () => {
|
||||||
|
|
|
@ -146,9 +146,9 @@ export const createNodeWebSocket = (init: NodeWebSocketInit): NodeWebSocket => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
ws.on('close', () => {
|
ws.on('close', (code, reason) => {
|
||||||
try {
|
try {
|
||||||
events?.onClose?.(new CloseEvent('close'), ctx)
|
events?.onClose?.(new CloseEvent('close', { code, reason: reason.toString() }), ctx)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
;(options?.onError ?? console.error)(e)
|
;(options?.onError ?? console.error)(e)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue