Commit b084d0a4 authored by Solly Ross's avatar Solly Ross

Actually throw errors in tests

parent f00193e0
...@@ -167,7 +167,7 @@ var RFB; ...@@ -167,7 +167,7 @@ var RFB;
try { try {
this._display = new Display({target: this._target}); this._display = new Display({target: this._target});
} catch (exc) { } catch (exc) {
Util.Error("Display exception: " + exc); Util.Error("Display exception:", exc);
throw exc; throw exc;
} }
......
...@@ -217,7 +217,7 @@ Util.init_logging = function (level) { ...@@ -217,7 +217,7 @@ Util.init_logging = function (level) {
case 'warn': case 'warn':
Util.Warn = function (msg) { console.warn(msg); }; Util.Warn = function (msg) { console.warn(msg); };
case 'error': case 'error':
Util.Error = function (msg) { console.error(msg); }; Util.Error = function (msg, err) { console.error(msg, err); };
case 'none': case 'none':
break; break;
default: default:
......
...@@ -375,31 +375,8 @@ function Websock() { ...@@ -375,31 +375,8 @@ function Websock() {
Util.Debug("Ignoring empty message"); Util.Debug("Ignoring empty message");
} }
} catch (exc) { } catch (exc) {
var exception_str = ""; Util.Error("recv_message, caught exception:", exc);
if (exc.name) { this._eventHandlers.error(exc)
exception_str += "\n name: " + exc.name + "\n";
exception_str += " message: " + exc.message + "\n";
}
if (typeof exc.description !== 'undefined') {
exception_str += " description: " + exc.description + "\n";
}
if (typeof exc.stack !== 'undefined') {
exception_str += exc.stack;
}
if (exception_str.length > 0) {
Util.Error("recv_message, caught exception: " + exception_str);
} else {
Util.Error("recv_message, caught exception: " + exc);
}
if (typeof exc.name !== 'undefined') {
this._eventHandlers.error(exc.name + ": " + exc.message);
} else {
this._eventHandlers.error(exc);
}
} }
} }
}; };
......
...@@ -32,6 +32,12 @@ describe('Remote Frame Buffer Protocol Client', function() { ...@@ -32,6 +32,12 @@ describe('Remote Frame Buffer Protocol Client', function() {
this._rQ = rQ; this._rQ = rQ;
}; };
// Actually throw errors
if (Util.__Error === undefined) { Util.__Error = Util.Error; }
Util.Error = function (msg, err) {
if (err) { throw err; }
Util.__Error(msg, err);
};
}); });
after(function () { after(function () {
......
...@@ -7,6 +7,19 @@ var expect = chai.expect; ...@@ -7,6 +7,19 @@ var expect = chai.expect;
describe('Websock', function() { describe('Websock', function() {
"use strict"; "use strict";
function throwUtilError() {
if (Util.__Error === undefined) { Util.__Error = Util.Error; }
Util.Error = function (msg, err) {
if (err) { throw err; }
Util.__Error(msg, err);
};
}
before(function () {
// Actually throw errors
throwUtilError();
});
describe('Queue methods', function () { describe('Queue methods', function () {
var sock; var sock;
var RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); var RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
...@@ -405,12 +418,14 @@ describe('Websock', function() { ...@@ -405,12 +418,14 @@ describe('Websock', function() {
}); });
it('should call the error event handler on an exception', function () { it('should call the error event handler on an exception', function () {
Util.Error = Util.__Error;
sock._eventHandlers.error = sinon.spy(); sock._eventHandlers.error = sinon.spy();
sock._eventHandlers.message = sinon.stub().throws(); sock._eventHandlers.message = sinon.stub().throws();
var msg = { data: new Uint8Array([1, 2, 3]).buffer }; var msg = { data: new Uint8Array([1, 2, 3]).buffer };
sock._mode = 'binary'; sock._mode = 'binary';
sock._recv_message(msg); sock._recv_message(msg);
expect(sock._eventHandlers.error).to.have.been.calledOnce; expect(sock._eventHandlers.error).to.have.been.calledOnce;
throwUtilError();
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment