Skip to content

Commit 7cbc00b

Browse files
committed
Adjusting the readableObjectMode test for earlier versions of Node
1 parent 84f7875 commit 7cbc00b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/base.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const http = require('http')
4+
const util = require('util')
45
const split = require('split2')
56
const test = require('tap').test
67
const Fastify = require('fastify')
@@ -317,11 +318,16 @@ test('Should be able to pass custom connectionOptions to createWebSocketStream',
317318
fastify.register(fastifyWebsocket, { connectionOptions })
318319

319320
fastify.get('/', { websocket: true }, (connection, request) => {
320-
t.equal(connection.readableObjectMode, true)
321+
// readableObjectMode was added in Node v12.3.0 so for earlier versions
322+
// we check the encapsulated readable state directly
323+
const mode = (typeof connection.readableObjectMode === 'undefined')
324+
? connection._readableState.objectMode
325+
: connection.readableObjectMode
326+
t.equal(mode, true)
321327
connection.socket.binaryType = 'arraybuffer'
322328

323329
connection.once('data', (chunk) => {
324-
const message = new TextDecoder().decode(chunk)
330+
const message = new util.TextDecoder().decode(chunk)
325331
t.equal(message, 'Hello')
326332
})
327333
t.teardown(() => connection.destroy())

0 commit comments

Comments
 (0)