-// requires local modules: websock, util
-// requires test modules: fake.websocket, assertions
-/* jshint expr: true */
-var assert = chai.assert;
var expect = chai.expect;
+import Websock from '../core/websock.js';
+import FakeWebSocket from './fake.websocket.js';
+
+import sinon from '../vendor/sinon.js';
+
describe('Websock', function() {
"use strict";
var sock;
beforeEach(function () {
- sock = new Websock();
- WebSocket = sinon.spy();
- WebSocket.OPEN = old_WS.OPEN;
- WebSocket.CONNECTING = old_WS.CONNECTING;
- WebSocket.CLOSING = old_WS.CLOSING;
- WebSocket.CLOSED = old_WS.CLOSED;
-
- WebSocket.prototype.binaryType = 'arraybuffer';
+ sock = new Websock();
+ // eslint-disable-next-line no-global-assign
+ WebSocket = sinon.spy();
+ WebSocket.OPEN = old_WS.OPEN;
+ WebSocket.CONNECTING = old_WS.CONNECTING;
+ WebSocket.CLOSING = old_WS.CLOSING;
+ WebSocket.CLOSED = old_WS.CLOSED;
+
+ WebSocket.prototype.binaryType = 'arraybuffer';
});
describe('opening', function () {
expect(WebSocket).to.have.been.calledWith('ws://localhost:8675', 'binary');
});
- it('should fail if we specify a protocol besides binary', function () {
- expect(function () { sock.open('ws:///', 'base64'); }).to.throw(Error);
- });
-
// it('should initialize the event handlers')?
});
expect(sock._recv_message).to.have.been.calledOnce;
});
- it('should fail if a protocol besides binary is requested', function () {
- sock._websocket.protocol = 'base64';
- expect(sock._websocket.onopen).to.throw(Error);
- });
-
- it('should assume binary if no protocol was available on opening', function () {
- sock._websocket.protocol = null;
- sock._websocket.onopen();
- expect(sock._mode).to.equal('binary');
- });
-
it('should call the open event handler on opening', function () {
sock._websocket.onopen();
expect(sock._eventHandlers.open).to.have.been.calledOnce;
});
after(function () {
+ // eslint-disable-next-line no-global-assign
WebSocket = old_WS;
});
});
expect(sock.get_rQi()).to.equal(0);
expect(sock._rQ.length).to.equal(240); // keep the invariant that rQbufferSize / 8 >= rQlen
});
-
- it('should call the error event handler on an exception', function () {
- sock._eventHandlers.error = sinon.spy();
- sock._eventHandlers.message = sinon.stub().throws();
- var msg = { data: new Uint8Array([1, 2, 3]).buffer };
- sock._mode = 'binary';
- sock._recv_message(msg);
- expect(sock._eventHandlers.error).to.have.been.calledOnce;
- });
});
describe('Data encoding', function () {