mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
97 lines
2.9 KiB
JavaScript
97 lines
2.9 KiB
JavaScript
const expect = require("expect.js");
|
|
const eio = require("../");
|
|
|
|
const expectedPort =
|
|
typeof location !== "undefined" && "https:" === location.protocol
|
|
? "443"
|
|
: "80";
|
|
|
|
describe("engine.io-client", function() {
|
|
let open;
|
|
|
|
before(function() {
|
|
open = eio.Socket.prototype.open;
|
|
// override Socket#open to not connect
|
|
eio.Socket.prototype.open = function() {};
|
|
});
|
|
|
|
after(function() {
|
|
eio.Socket.prototype.open = open;
|
|
});
|
|
|
|
it("should expose protocol number", function() {
|
|
expect(eio.protocol).to.be.a("number");
|
|
});
|
|
|
|
it("should properly parse http uri without port", function() {
|
|
const client = eio("http://localhost");
|
|
expect(client.port).to.be("80");
|
|
});
|
|
|
|
it("should properly parse https uri without port", function() {
|
|
const client = eio("https://localhost");
|
|
expect(client.hostname).to.be("localhost");
|
|
expect(client.port).to.be("443");
|
|
});
|
|
|
|
it("should properly parse wss uri without port", function() {
|
|
const client = eio("wss://localhost");
|
|
expect(client.hostname).to.be("localhost");
|
|
expect(client.port).to.be("443");
|
|
});
|
|
|
|
it("should properly parse wss uri with port", function() {
|
|
const client = eio("wss://localhost:2020");
|
|
expect(client.hostname).to.be("localhost");
|
|
expect(client.port).to.be("2020");
|
|
});
|
|
|
|
it("should properly parse a host without port", function() {
|
|
const client = eio({ host: "localhost" });
|
|
expect(client.hostname).to.be("localhost");
|
|
expect(client.port).to.be(expectedPort);
|
|
});
|
|
|
|
it("should properly parse a host with port", function() {
|
|
const client = eio({ host: "localhost", port: "8080" });
|
|
expect(client.hostname).to.be("localhost");
|
|
expect(client.port).to.be("8080");
|
|
});
|
|
|
|
it("should properly parse an IPv6 uri without port", function() {
|
|
const client = eio("http://[::1]");
|
|
expect(client.hostname).to.be("::1");
|
|
expect(client.port).to.be("80");
|
|
});
|
|
|
|
it("should properly parse an IPv6 uri with port", function() {
|
|
const client = eio("http://[::1]:8080");
|
|
expect(client.hostname).to.be("::1");
|
|
expect(client.port).to.be("8080");
|
|
});
|
|
|
|
it("should properly parse an IPv6 host without port (1/2)", function() {
|
|
const client = eio({ host: "[::1]" });
|
|
expect(client.hostname).to.be("::1");
|
|
expect(client.port).to.be(expectedPort);
|
|
});
|
|
|
|
it("should properly parse an IPv6 host without port (2/2)", function() {
|
|
const client = eio({ secure: true, host: "[::1]" });
|
|
expect(client.hostname).to.be("::1");
|
|
expect(client.port).to.be("443");
|
|
});
|
|
|
|
it("should properly parse an IPv6 host with port", function() {
|
|
const client = eio({ host: "[::1]", port: "8080" });
|
|
expect(client.hostname).to.be("::1");
|
|
expect(client.port).to.be("8080");
|
|
});
|
|
|
|
it("should properly parse an IPv6 host without brace", function() {
|
|
const client = eio({ host: "::1" });
|
|
expect(client.hostname).to.be("::1");
|
|
expect(client.port).to.be(expectedPort);
|
|
});
|
|
});
|