]> git.proxmox.com Git - mirror_novnc.git/blobdiff - tests/test.websock.js
Add eslint and fix reported issues
[mirror_novnc.git] / tests / test.websock.js
index 953a526882d58a7d240e6fd1e9b9a4b3f6ca7a52..1e978ec23ebdc1eac3a3f6060e32b71b11c3b42d 100644 (file)
@@ -1,9 +1,10 @@
-// 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";
 
@@ -170,9 +171,9 @@ describe('Websock', function() {
                 };
             });
 
-            it('should actually send on the websocket if the websocket does not have too much buffered', function () {
-                sock.maxBufferedAmount = 10;
+            it('should actually send on the websocket', function () {
                 sock._websocket.bufferedAmount = 8;
+                sock._websocket.readyState = WebSocket.OPEN
                 sock._sQ = new Uint8Array([1, 2, 3]);
                 sock._sQlen = 3;
                 var encoded = sock._encode_message();
@@ -182,30 +183,14 @@ describe('Websock', function() {
                 expect(sock._websocket.send).to.have.been.calledWith(encoded);
             });
 
-            it('should return true if the websocket did not have too much buffered', function () {
-                sock.maxBufferedAmount = 10;
-                sock._websocket.bufferedAmount = 8;
-
-                expect(sock.flush()).to.be.true;
-            });
-
             it('should not call send if we do not have anything queued up', function () {
                 sock._sQlen = 0;
-                sock.maxBufferedAmount = 10;
                 sock._websocket.bufferedAmount = 8;
 
                 sock.flush();
 
                 expect(sock._websocket.send).not.to.have.been.called;
             });
-
-            it('should not send and return false if the websocket has too much buffered', function () {
-                sock.maxBufferedAmount = 10;
-                sock._websocket.bufferedAmount = 12;
-
-                expect(sock.flush()).to.be.false;
-                expect(sock._websocket.send).to.not.have.been.called;
-            });
         });
 
         describe('send', function () {
@@ -245,14 +230,15 @@ describe('Websock', function() {
 
         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 () {
@@ -265,10 +251,6 @@ describe('Websock', 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')?
         });
 
@@ -328,17 +310,6 @@ describe('Websock', function() {
                 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;
@@ -356,6 +327,7 @@ describe('Websock', function() {
         });
 
         after(function () {
+            // eslint-disable-next-line no-global-assign
             WebSocket = old_WS;
         });
     });
@@ -417,15 +389,6 @@ describe('Websock', function() {
             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 () {