diff --git a/test/inverse/ws.private.test.ts b/test/inverse/ws.private.test.ts index 23c703d..83b01c3 100644 --- a/test/inverse/ws.private.test.ts +++ b/test/inverse/ws.private.test.ts @@ -68,12 +68,10 @@ describe('Private Inverse Perps Websocket Client', () => { it('should open a ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - expect(wsOpenPromise).resolves.toMatchObject({ + expect(await wsOpenPromise).toMatchObject({ event: WS_OPEN_EVENT_PARTIAL, wsKey: WS_KEY_MAP.inverse, }); - - await Promise.all([wsOpenPromise]); }); it('should subscribe to private wallet events', async () => { diff --git a/test/inverse/ws.public.test.ts b/test/inverse/ws.public.test.ts index 709421c..8d02b6d 100644 --- a/test/inverse/ws.public.test.ts +++ b/test/inverse/ws.public.test.ts @@ -30,12 +30,14 @@ describe('Public Inverse Perps Websocket Client', () => { it('should open a public ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.inverse, - }); - - await Promise.all([wsOpenPromise]); + try { + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.inverse, + }); + } catch (e) { + expect(e).toBeFalsy(); + } }); it('should subscribe to public orderBookL2_25 events', async () => { diff --git a/test/linear/ws.private.test.ts b/test/linear/ws.private.test.ts index fca6ea2..09290b1 100644 --- a/test/linear/ws.private.test.ts +++ b/test/linear/ws.private.test.ts @@ -71,12 +71,14 @@ describe('Private Linear Perps Websocket Client', () => { it('should open a ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.linearPrivate, - }); - - await Promise.all([wsOpenPromise]); + try { + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.linearPrivate, + }); + } catch (e) { + expect(e).toBeFalsy(); + } }); it('should subscribe to private wallet events', async () => { diff --git a/test/linear/ws.public.test.ts b/test/linear/ws.public.test.ts index 7d3b195..6281c07 100644 --- a/test/linear/ws.public.test.ts +++ b/test/linear/ws.public.test.ts @@ -23,17 +23,16 @@ describe('Public Linear Perps Websocket Client', () => { afterAll(() => { wsClient.closeAll(); + wsClient.removeAllListeners(); }); it('should open a public ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - expect(wsOpenPromise).resolves.toMatchObject({ + expect(await wsOpenPromise).toMatchObject({ event: WS_OPEN_EVENT_PARTIAL, wsKey: WS_KEY_MAP.linearPublic, }); - - await Promise.all([wsOpenPromise]); }); it('should subscribe to public orderBookL2_25 events', async () => { @@ -41,33 +40,27 @@ describe('Public Linear Perps Websocket Client', () => { const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); const wsTopic = 'orderBookL2_25.BTCUSDT'; - expect(wsResponsePromise).resolves.toMatchObject({ - request: { - args: [wsTopic], - op: 'subscribe', - }, - success: true, - }); - expect(wsUpdatePromise).resolves.toMatchObject({ - topic: wsTopic, - data: { - order_book: expect.any(Array), - }, - }); - wsClient.subscribe(wsTopic); try { - await wsResponsePromise; + expect(await wsResponsePromise).toMatchObject({ + request: { + args: [wsTopic], + op: 'subscribe', + }, + success: true, + }); } catch (e) { - console.error( - `Wait for "${wsTopic}" subscription response exception: `, - e - ); + expect(e).toBeFalsy(); } try { - await wsUpdatePromise; + expect(await wsUpdatePromise).toMatchObject({ + topic: wsTopic, + data: { + order_book: expect.any(Array), + }, + }); } catch (e) { console.error(`Wait for "${wsTopic}" event exception: `, e); } @@ -78,13 +71,6 @@ describe('Public Linear Perps Websocket Client', () => { // const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); const wsTopic = 'wallet'; - expect(wsResponsePromise).resolves.toMatchObject({ - request: { - args: [wsTopic], - op: 'subscribe', - }, - success: true, - }); // No easy way to trigger a private event (other than executing trades) // expect(wsUpdatePromise).resolves.toMatchObject({ @@ -95,9 +81,15 @@ describe('Public Linear Perps Websocket Client', () => { wsClient.subscribe(wsTopic); try { - await Promise.all([wsResponsePromise]); + expect(await wsResponsePromise).toBeFalsy(); } catch (e) { - // + expect(e).toMatchObject({ + request: { + args: [wsTopic], + op: 'subscribe', + }, + success: false, + }); } }); }); diff --git a/test/spot/ws.private.v1.test.ts b/test/spot/ws.private.v1.test.ts index 3cb62f3..7361a36 100644 --- a/test/spot/ws.private.v1.test.ts +++ b/test/spot/ws.private.v1.test.ts @@ -46,15 +46,20 @@ describe('Private Spot V1 Websocket Client', () => { wsClient.connectPrivate(); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.spotPrivate, - }); + try { + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + // wsKey: WS_KEY_MAP.spotPrivate, + // also opens public conn automatically, which can confuse the test + }); + } catch (e) { + expect(e).toBeFalsy(); + } // expect(wsUpdatePromise).resolves.toMatchObject({ // topic: 'wsTopic', // data: expect.any(Array), // }); - await Promise.all([wsOpenPromise]); + // await Promise.all([wsUpdatePromise]); // await promiseSleep(4000); }); diff --git a/test/spot/ws.private.v3.test.ts b/test/spot/ws.private.v3.test.ts index 1a5d614..6fb8442 100644 --- a/test/spot/ws.private.v3.test.ts +++ b/test/spot/ws.private.v3.test.ts @@ -79,13 +79,11 @@ describe('Private Spot V3 Websocket Client', () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.spotV3Private, - }); - try { - await Promise.all([wsOpenPromise]); + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.spotV3Private, + }); } catch (e) { expect(e).toBeFalsy(); } diff --git a/test/spot/ws.public.v1.test.ts b/test/spot/ws.public.v1.test.ts index cdb48d4..3b021b2 100644 --- a/test/spot/ws.public.v1.test.ts +++ b/test/spot/ws.public.v1.test.ts @@ -34,12 +34,14 @@ describe('Public Spot V1 Websocket Client', () => { it('should open a public ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.spotPublic, - }); - - await Promise.all([wsOpenPromise]); + try { + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.spotPublic, + }); + } catch (e) { + expect(e).toBeFalsy(); + } }); it('should subscribe to public orderbook events', async () => { diff --git a/test/spot/ws.public.v3.test.ts b/test/spot/ws.public.v3.test.ts index 0cd86f1..0f2d662 100644 --- a/test/spot/ws.public.v3.test.ts +++ b/test/spot/ws.public.v3.test.ts @@ -34,12 +34,14 @@ describe('Public Spot V3 Websocket Client', () => { it('should open a public ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.spotV3Public, - }); - - await Promise.all([wsOpenPromise]); + try { + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.spotV3Public, + }); + } catch (e) { + expect(e).toBeFalsy(); + } }); it('should subscribe to public orderbook events', async () => { diff --git a/test/usdc/options/ws.private.test.ts b/test/usdc/options/ws.private.test.ts index 4f94136..ae93be4 100644 --- a/test/usdc/options/ws.private.test.ts +++ b/test/usdc/options/ws.private.test.ts @@ -77,7 +77,6 @@ describe('Private USDC Option Websocket Client', () => { wsClientOptions, getSilentLogger('expectSuccess') ); - wsClient.connectPrivate(); // logAllEvents(wsClient); }); @@ -86,16 +85,15 @@ describe('Private USDC Option Websocket Client', () => { }); it('should open a private ws connection', async () => { + wsClient.connectPrivate(); const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.usdcOptionPrivate, - }); - try { - await Promise.all([wsOpenPromise]); + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.usdcOptionPrivate, + }); } catch (e) { expect(e).toBeFalsy(); } @@ -113,6 +111,7 @@ describe('Private USDC Option Websocket Client', () => { }); it(`should subscribe to private "${wsTopic}" events`, async () => { + wsClient.connectPrivate(); const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); diff --git a/test/usdc/options/ws.public.test.ts b/test/usdc/options/ws.public.test.ts index 48c4fbf..90b4822 100644 --- a/test/usdc/options/ws.public.test.ts +++ b/test/usdc/options/ws.public.test.ts @@ -31,13 +31,14 @@ describe('Public USDC Option Websocket Client', () => { it('should open a public ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.usdcOptionPublic, - }); - - await Promise.all([wsOpenPromise]); + try { + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.usdcOptionPublic, + }); + } catch (e) { + expect(e).toBeFalsy(); + } }); it('should subscribe to public trade events', async () => { diff --git a/test/usdc/perpetual/ws.private.test.ts b/test/usdc/perpetual/ws.private.test.ts index 84d0f4b..7508292 100644 --- a/test/usdc/perpetual/ws.private.test.ts +++ b/test/usdc/perpetual/ws.private.test.ts @@ -89,13 +89,11 @@ describe('Private USDC Perp Websocket Client', () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - expect(wsOpenPromise).resolves.toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.usdcPerpPrivate, - }); - try { - await Promise.all([wsOpenPromise]); + expect(await wsOpenPromise).toMatchObject({ + event: WS_OPEN_EVENT_PARTIAL, + wsKey: WS_KEY_MAP.usdcPerpPrivate, + }); } catch (e) { expect(e).toBeFalsy(); } diff --git a/test/usdc/perpetual/ws.public.test.ts b/test/usdc/perpetual/ws.public.test.ts index 5b67c0f..d5bcb87 100644 --- a/test/usdc/perpetual/ws.public.test.ts +++ b/test/usdc/perpetual/ws.public.test.ts @@ -33,12 +33,10 @@ describe('Public USDC Perp Websocket Client', () => { it('should open a public ws connection', async () => { const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - expect(wsOpenPromise).resolves.toMatchObject({ + expect(await wsOpenPromise).toMatchObject({ event: WS_OPEN_EVENT_PARTIAL, wsKey: WS_KEY_MAP.usdcPerpPublic, }); - - await Promise.all([wsOpenPromise]); }); it('should subscribe to public trade events', async () => {