summaryrefslogtreecommitdiffstats
path: root/test/websocket/ping-pong.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
commit0b6210cd37b68b94252cb798598b12974a20e1c1 (patch)
treee371686554a877842d95aa94f100bee552ff2a8e /test/websocket/ping-pong.js
parentInitial commit. (diff)
downloadnode-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz
node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/websocket/ping-pong.js')
-rw-r--r--test/websocket/ping-pong.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/websocket/ping-pong.js b/test/websocket/ping-pong.js
new file mode 100644
index 0000000..b7c4694
--- /dev/null
+++ b/test/websocket/ping-pong.js
@@ -0,0 +1,46 @@
+'use strict'
+
+const { test } = require('tap')
+const { WebSocketServer } = require('ws')
+const diagnosticsChannel = require('diagnostics_channel')
+const { WebSocket } = require('../..')
+
+test('Receives ping and parses body', (t) => {
+ t.plan(1)
+
+ const server = new WebSocketServer({ port: 0 })
+
+ server.on('connection', (ws) => {
+ ws.ping('Hello, world')
+ })
+
+ t.teardown(server.close.bind(server))
+
+ const ws = new WebSocket(`ws://localhost:${server.address().port}`)
+ ws.onerror = ws.onmessage = t.fail
+
+ diagnosticsChannel.channel('undici:websocket:ping').subscribe(({ payload }) => {
+ t.same(payload, Buffer.from('Hello, world'))
+ ws.close()
+ })
+})
+
+test('Receives pong and parses body', (t) => {
+ t.plan(1)
+
+ const server = new WebSocketServer({ port: 0 })
+
+ server.on('connection', (ws) => {
+ ws.pong('Pong')
+ })
+
+ t.teardown(server.close.bind(server))
+
+ const ws = new WebSocket(`ws://localhost:${server.address().port}`)
+ ws.onerror = ws.onmessage = t.fail
+
+ diagnosticsChannel.channel('undici:websocket:pong').subscribe(({ payload }) => {
+ t.same(payload, Buffer.from('Pong'))
+ ws.close()
+ })
+})