UNPKG

lsp-ws-connection

Version:
66 lines 2.64 kB
import * as sinon from 'sinon'; // There is a library that can be used to mock WebSockets, but the API surface tested here is small // enough that it is not necessary to use the library. This mock is a simple EventEmitter var MockConnection = /** @class */ (function () { function MockConnection() { var _this = this; this.listeners = {}; /** * Sends a synthetic event to the client code, for example to imitate a server response */ this.dispatchEvent = function (event) { var listeners = _this.listeners[event.type]; if (!listeners) { return false; } listeners.forEach(function (listener) { return listener.call(null, event.data); }); return true; }; this.sendInitialize = sinon.stub(); this.sendChange = sinon.stub(); this.sendOpen = sinon.stub(); this.getHoverTooltip = sinon.stub(); this.getCompletion = sinon.stub(); this.getDetailedCompletion = sinon.stub(); this.getSignatureHelp = sinon.stub(); this.getDocumentHighlights = sinon.stub(); this.getDefinition = sinon.stub(); this.getTypeDefinition = sinon.stub(); this.getImplementation = sinon.stub(); this.getReferences = sinon.stub(); this.getDocumentUri = sinon.stub(); this.isDefinitionSupported = sinon.stub(); this.isTypeDefinitionSupported = sinon.stub(); this.isImplementationSupported = sinon.stub(); this.isReferencesSupported = sinon.stub(); this.close = sinon.stub(); this.completionCharacters = ['.', ',']; this.signatureCharacters = ['(']; } MockConnection.prototype.on = function (type, listener) { var listeners = this.listeners[type]; if (!listeners) { this.listeners[type] = []; } this.listeners[type].push(listener); }; MockConnection.prototype.off = function (type, listener) { var listeners = this.listeners[type]; if (!listeners) { return; } var index = listeners.findIndex(function (l) { return l === listener; }); if (index > -1) { this.listeners[type].splice(index); } }; MockConnection.prototype.getLanguageCompletionCharacters = function () { return this.completionCharacters; }; MockConnection.prototype.getLanguageSignatureCharacters = function () { return this.signatureCharacters; }; return MockConnection; }()); export { MockConnection }; //# sourceMappingURL=mock-connection.js.map