diff --git a/lib/web/websocket/websocket.js b/lib/web/websocket/websocket.js index 7e465f56e99..6263443dde7 100644 --- a/lib/web/websocket/websocket.js +++ b/lib/web/websocket/websocket.js @@ -537,6 +537,14 @@ class WebSocket extends EventTarget { message: reason }) } + + if (!this.#parser && !this.#handler.receivedClose) { + fireEvent('close', this, (type, init) => new CloseEvent(type, init), { + wasClean: false, + code: 1006, + reason + }) + } } #onMessage (type, data) { diff --git a/test/websocket/issue-3546.js b/test/websocket/issue-3546.js index 5d328902538..59a7bd0f093 100644 --- a/test/websocket/issue-3546.js +++ b/test/websocket/issue-3546.js @@ -5,7 +5,7 @@ const { WebSocket } = require('../..') const { tspl } = require('@matteo.collina/tspl') test('first error than close event is fired on failed connection', async (t) => { - const { completed, strictEqual } = tspl(t, { plan: 2 }) + const { completed, strictEqual } = tspl(t, { plan: 4 }) const ws = new WebSocket('ws://localhost:1') let orderOfEvents = 0