From 091ef2e240c35afab1b1010a6676ddae7801740b Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 12 Jun 2021 23:01:48 +0900 Subject: [PATCH] fix connection close logic --- package.json | 2 +- src/streaming.ts | 3 +-- test/streaming.ts | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index af429d3aca..fc285c7e4d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "npm run tsc", "tsc": "tsc", "tsd": "tsd", - "jest": "jest", + "jest": "jest --detectOpenHandles", "test": "npm run jest && npm run tsd" }, "repository": { diff --git a/src/streaming.ts b/src/streaming.ts index 7a809f19af..cc1b9a887b 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -255,8 +255,7 @@ export default class Stream extends EventEmitter { */ @autobind public close() { - this.stream.removeEventListener('open', this.onOpen); - this.stream.removeEventListener('message', this.onMessage); + this.stream.close(); } } diff --git a/test/streaming.ts b/test/streaming.ts index afd0852ff8..7de85ce775 100644 --- a/test/streaming.ts +++ b/test/streaming.ts @@ -32,12 +32,14 @@ describe('Streaming', () => { id: 'foo' }); + stream.close(); server.close(); }); + /* TODO test('useChannel with parameters', async () => { - // TODO }); + */ test('Connection#dispose', async () => { const server = new WS('wss://misskey.test/streaming'); @@ -68,6 +70,7 @@ describe('Streaming', () => { expect(mainChannelReceived.length).toEqual(0); + stream.close(); server.close(); });