Skip to content

Commit

Permalink
expose WebSocket related events in node bundle (#3167)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Apr 26, 2024
1 parent d3de002 commit 77a7947
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion index-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ module.exports.Headers = require('./lib/web/fetch/headers').Headers
module.exports.Response = require('./lib/web/fetch/response').Response
module.exports.Request = require('./lib/web/fetch/request').Request

const { CloseEvent, ErrorEvent, MessageEvent } = require('./lib/web/websocket/events')
module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
module.exports.MessageEvent = require('./lib/web/websocket/events').MessageEvent
module.exports.CloseEvent = CloseEvent
module.exports.ErrorEvent = ErrorEvent
module.exports.MessageEvent = MessageEvent

module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource

Expand Down
8 changes: 7 additions & 1 deletion test/fetch/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { test } = require('node:test')
const assert = require('node:assert')

const { Response, Request, FormData, Headers } = require('../../undici-fetch')
const { Response, Request, FormData, Headers, MessageEvent, CloseEvent, ErrorEvent } = require('../../undici-fetch')

test('bundle sets constructor.name and .name properly', () => {
assert.strictEqual(new Response().constructor.name, 'Response')
Expand Down Expand Up @@ -31,3 +31,9 @@ test('regression test for https://github.com/nodejs/node/issues/50263', () => {

assert.strictEqual(request1.headers.get('test'), 'abc')
})

test('WebSocket related events are exported', (t) => {
assert.deepStrictEqual(typeof CloseEvent, 'function')
assert.deepStrictEqual(typeof MessageEvent, 'function')
assert.deepStrictEqual(typeof ErrorEvent, 'function')
})

0 comments on commit 77a7947

Please sign in to comment.