forked from websockets/ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket.integration.js
55 lines (43 loc) · 1.14 KB
/
websocket.integration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const assert = require('assert');
const WebSocket = require('..');
describe('WebSocket', () => {
it('communicates successfully with echo service (ws)', (done) => {
const ws = new WebSocket('ws:https://websocket-echo.com/', {
protocolVersion: 13
});
let dataReceived = false;
ws.on('open', () => {
ws.send('hello');
});
ws.on('close', () => {
assert.ok(dataReceived);
done();
});
ws.on('message', (message, isBinary) => {
dataReceived = true;
assert.ok(!isBinary);
assert.strictEqual(message.toString(), 'hello');
ws.close();
});
});
it('communicates successfully with echo service (wss)', (done) => {
const ws = new WebSocket('wss:https://websocket-echo.com/', {
protocolVersion: 13
});
let dataReceived = false;
ws.on('open', () => {
ws.send('hello');
});
ws.on('close', () => {
assert.ok(dataReceived);
done();
});
ws.on('message', (message, isBinary) => {
dataReceived = true;
assert.ok(!isBinary);
assert.strictEqual(message.toString(), 'hello');
ws.close();
});
});
});