|
| 1 | +import { EventEmitter } from "@xmpp/events"; |
1 | 2 | import Socket from "../lib/Socket.js"; |
2 | 3 |
|
3 | | -test("isSecure", () => { |
| 4 | +// eslint-disable-next-line n/no-unsupported-features/node-builtins |
| 5 | +globalThis.WebSocket = EventEmitter; |
| 6 | + |
| 7 | +test("secure", () => { |
4 | 8 | const socket = new Socket(); |
5 | | - expect(socket.isSecure()).toBe(false); |
6 | 9 |
|
7 | | - socket.url = "ws://example.com/foo"; |
8 | | - expect(socket.isSecure()).toBe(false); |
| 10 | + expect(socket.secure).toBe(false); |
| 11 | + |
| 12 | + socket.connect("ws://example.com/foo"); |
| 13 | + expect(socket.secure).toBe(false); |
| 14 | + |
| 15 | + socket.connect("ws://localhost/foo"); |
| 16 | + expect(socket.secure).toBe(true); |
9 | 17 |
|
10 | | - socket.url = "ws://localhost/foo"; |
11 | | - expect(socket.isSecure()).toBe(true); |
| 18 | + socket.connect("ws://127.0.0.1/foo"); |
| 19 | + expect(socket.secure).toBe(true); |
12 | 20 |
|
13 | | - socket.url = "ws://127.0.0.1/foo"; |
14 | | - expect(socket.isSecure()).toBe(true); |
| 21 | + socket.connect("ws://[::1]/foo"); |
| 22 | + expect(socket.secure).toBe(true); |
15 | 23 |
|
16 | | - socket.url = "ws://[::1]/foo"; |
17 | | - expect(socket.isSecure()).toBe(true); |
| 24 | + socket.connect("wss://example.com/foo"); |
| 25 | + expect(socket.secure).toBe(true); |
18 | 26 |
|
19 | | - socket.url = "wss://example.com/foo"; |
20 | | - expect(socket.isSecure()).toBe(true); |
| 27 | + socket.socket.emit("close", { wasClean: Math.random > 0.5 }); |
| 28 | + expect(socket.secure).toBe(false); |
21 | 29 | }); |
0 commit comments