Files
socket.io/test/engine.io-client.js
Damien Arrachequesne 27de300de4 chore: migrate to rollup
This change allows us to:

- reduce the size of the bundle
- provide an ESM bundle (for usage in <script type="module">)

BREAKING CHANGE: due to how default export works with ES modules, we
have removed the default export of the library, which means the
following code:

```js
require("engine.io-client")(...);
```

will not work anymore. The named export must be used instead:

```js
const { Socket } = require("engine.io-client);
// or import { Socket } from "engine.io-client";

const socket = new Socket(...);
```

Note: the UMD build still exposes a function though:

```html
<script src="/path/to/engine.io.js"></script>
<script>
  const socket = eio(...);
</script>
```

Note: webpack is still used with zuul because of the custom builder
(zuul-builder-webpack)
2021-10-08 11:46:11 +02:00

97 lines
2.9 KiB
JavaScript

const expect = require("expect.js");
const { Socket, protocol } = require("..");
const expectedPort =
typeof location !== "undefined" && "https:" === location.protocol
? "443"
: "80";
describe("engine.io-client", () => {
let open;
before(() => {
open = Socket.prototype.open;
// override Socket#open to not connect
Socket.prototype.open = () => {};
});
after(() => {
Socket.prototype.open = open;
});
it("should expose protocol number", () => {
expect(protocol).to.be.a("number");
});
it("should properly parse http uri without port", () => {
const client = new Socket("http://localhost");
expect(client.port).to.be("80");
});
it("should properly parse https uri without port", () => {
const client = new Socket("https://localhost");
expect(client.hostname).to.be("localhost");
expect(client.port).to.be("443");
});
it("should properly parse wss uri without port", () => {
const client = new Socket("wss://localhost");
expect(client.hostname).to.be("localhost");
expect(client.port).to.be("443");
});
it("should properly parse wss uri with port", () => {
const client = new Socket("wss://localhost:2020");
expect(client.hostname).to.be("localhost");
expect(client.port).to.be("2020");
});
it("should properly parse a host without port", () => {
const client = new Socket({ host: "localhost" });
expect(client.hostname).to.be("localhost");
expect(client.port).to.be(expectedPort);
});
it("should properly parse a host with port", () => {
const client = new Socket({ 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", () => {
const client = new Socket("http://[::1]");
expect(client.hostname).to.be("::1");
expect(client.port).to.be("80");
});
it("should properly parse an IPv6 uri with port", () => {
const client = new Socket("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)", () => {
const client = new Socket({ 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)", () => {
const client = new Socket({ 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", () => {
const client = new Socket({ 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", () => {
const client = new Socket({ host: "::1" });
expect(client.hostname).to.be("::1");
expect(client.port).to.be(expectedPort);
});
});