Skip to content

Commit

Permalink
set websocket readyState on fail (#3507)
Browse files Browse the repository at this point in the history
Fixes #3506

set websocket readyState on fail

Fixes #3506
  • Loading branch information
KhafraDev authored Aug 25, 2024
1 parent 9d57401 commit e96178f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ class WebSocket extends EventTarget {
this.#handler.socket.destroy()
}

this.#handler.readyState = states.CLOSED

if (reason) {
// TODO: process.nextTick
fireEvent('error', this, (type, init) => new ErrorEvent(type, init), {
Expand Down
18 changes: 18 additions & 0 deletions test/websocket/issue-3506.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const { test } = require('node:test')
const { WebSocket } = require('../..')
const { tspl } = require('@matteo.collina/tspl')

test('readyState is set on fail', async (t) => {
const { deepStrictEqual, completed } = tspl(t, { plan: 1 })
const ws = new WebSocket('ws://localhost:1')

t.after(() => ws.close())

ws.addEventListener('error', () => {
deepStrictEqual(ws.readyState, WebSocket.CLOSED)
})

await completed
})

0 comments on commit e96178f

Please sign in to comment.