From bf816ccc7e703abea747956c7599bbba3b4a308f Mon Sep 17 00:00:00 2001 From: jorisjaja Date: Mon, 25 Jun 2018 14:37:16 +0200 Subject: [PATCH 1/5] Added isOpen function for the listener --- src/infrastructure/Listener.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index bd5a242032..37bda049db 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -157,6 +157,17 @@ export class Listener { }); } + /** + * returns a boolean that repressents the open state + * @returns a boolean + */ + public isOpen(): boolean { + if(this.webSocket){ + return this.webSocket.readyState === WebSocket.OPEN; + } + return false; + } + /** * Close web socket connection. * @returns void From 99a0346e959fa332c4f61998132ea5265647479b Mon Sep 17 00:00:00 2001 From: jorisjaja Date: Mon, 25 Jun 2018 15:38:41 +0200 Subject: [PATCH 2/5] Added test for isOpen function --- test/infrastructure/Listener.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/infrastructure/Listener.spec.ts b/test/infrastructure/Listener.spec.ts index 87af430852..37653618b4 100644 --- a/test/infrastructure/Listener.spec.ts +++ b/test/infrastructure/Listener.spec.ts @@ -23,4 +23,12 @@ describe('Listener', () => { expect('ws://localhost:3000/ws').to.be.equal(listener.url); listener.close(); }); + + describe('isOpen', () => { + it('should return false when listener is created and not opened', () => { + const listener = new Listener('ws://localhost:3000'); + expect(listener.isOpen()).to.be.false; + listener.close(); + }); + }); }); From 42b70b3d8e0bd99c6ae57bd4645193596958b42f Mon Sep 17 00:00:00 2001 From: jorisjaja Date: Wed, 12 Sep 2018 09:42:36 +0200 Subject: [PATCH 3/5] FIX handle error in Listener --- src/infrastructure/Listener.ts | 1 + test/infrastructure/Listener.spec.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index fb128214d2..6ac36cfd7b 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -107,6 +107,7 @@ export class Listener { this.webSocket.onerror = (err) => { console.log('WebSocket Error '); console.log(err); + reject(err); }; this.webSocket.onmessage = (msg) => { const message = JSON.parse(msg.data as string); diff --git a/test/infrastructure/Listener.spec.ts b/test/infrastructure/Listener.spec.ts index 37653618b4..e8ebf1449b 100644 --- a/test/infrastructure/Listener.spec.ts +++ b/test/infrastructure/Listener.spec.ts @@ -31,4 +31,18 @@ describe('Listener', () => { listener.close(); }); }); + + describe('onerror', () => { + it('should reject because of wrong server url', async () => { + const listener = new Listener('https://notcorrecturl:0000'); + await listener.open() + .then((result) => { + throw new Error('This should not be called when expecting error'); + }) + .catch((error) => { + expect(error.toString()).to.be.equal("Error: getaddrinfo ENOTFOUND notcorrecturl notcorrecturl:0000"); + }) + }); + }); + }); From 3ba154f2fb8953fd291f81dea92bf21444b86e78 Mon Sep 17 00:00:00 2001 From: jorisjaja Date: Wed, 12 Sep 2018 10:15:20 +0200 Subject: [PATCH 4/5] Revert "FIX handle error in Listener" This reverts commit 42b70b3d8e0bd99c6ae57bd4645193596958b42f. --- src/infrastructure/Listener.ts | 1 - test/infrastructure/Listener.spec.ts | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index 6ac36cfd7b..fb128214d2 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -107,7 +107,6 @@ export class Listener { this.webSocket.onerror = (err) => { console.log('WebSocket Error '); console.log(err); - reject(err); }; this.webSocket.onmessage = (msg) => { const message = JSON.parse(msg.data as string); diff --git a/test/infrastructure/Listener.spec.ts b/test/infrastructure/Listener.spec.ts index e8ebf1449b..37653618b4 100644 --- a/test/infrastructure/Listener.spec.ts +++ b/test/infrastructure/Listener.spec.ts @@ -31,18 +31,4 @@ describe('Listener', () => { listener.close(); }); }); - - describe('onerror', () => { - it('should reject because of wrong server url', async () => { - const listener = new Listener('https://notcorrecturl:0000'); - await listener.open() - .then((result) => { - throw new Error('This should not be called when expecting error'); - }) - .catch((error) => { - expect(error.toString()).to.be.equal("Error: getaddrinfo ENOTFOUND notcorrecturl notcorrecturl:0000"); - }) - }); - }); - }); From 03612c0f9980a8728df1010eebf7dbe4da754106 Mon Sep 17 00:00:00 2001 From: jorisjaja Date: Wed, 12 Sep 2018 12:11:09 +0200 Subject: [PATCH 5/5] Fix handle error listener --- src/infrastructure/Listener.ts | 1 + test/infrastructure/Listener.spec.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index fb128214d2..6ac36cfd7b 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -107,6 +107,7 @@ export class Listener { this.webSocket.onerror = (err) => { console.log('WebSocket Error '); console.log(err); + reject(err); }; this.webSocket.onmessage = (msg) => { const message = JSON.parse(msg.data as string); diff --git a/test/infrastructure/Listener.spec.ts b/test/infrastructure/Listener.spec.ts index 37653618b4..b94c72afd7 100644 --- a/test/infrastructure/Listener.spec.ts +++ b/test/infrastructure/Listener.spec.ts @@ -31,4 +31,17 @@ describe('Listener', () => { listener.close(); }); }); + + describe('onerror', () => { + it('should reject because of wrong server url', async () => { + const listener = new Listener('https://notcorrecturl:0000'); + await listener.open() + .then((result) => { + throw new Error('This should not be called when expecting error'); + }) + .catch((error) => { + expect(error.toString()).to.be.equal("Error: getaddrinfo ENOTFOUND notcorrecturl notcorrecturl:0000"); + }) + }); + }); });