From 62e57309650955ba7ea4d2b8431da8975eb6cb89 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 14 Feb 2024 13:26:38 -0300 Subject: [PATCH] call useWebSocketImplementation() on relay and pool tests. --- pool.test.ts | 5 ++++- relay.test.ts | 6 ++++-- test-helpers.ts | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pool.test.ts b/pool.test.ts index 85659b1..09fd0d1 100644 --- a/pool.test.ts +++ b/pool.test.ts @@ -2,7 +2,10 @@ import { afterEach, beforeEach, expect, test } from 'bun:test' import { SimplePool } from './pool.ts' import { finalizeEvent, generateSecretKey, getPublicKey, type Event } from './pure.ts' -import { MockRelay } from './test-helpers.ts' +import { useWebSocketImplementation } from './relay.ts' +import { MockRelay, MockWebSocketClient } from './test-helpers.ts' + +useWebSocketImplementation(MockWebSocketClient) let pool: SimplePool let mockRelays: MockRelay[] diff --git a/relay.test.ts b/relay.test.ts index 73b3ae3..fde6982 100644 --- a/relay.test.ts +++ b/relay.test.ts @@ -1,8 +1,10 @@ import { expect, test } from 'bun:test' import { finalizeEvent, generateSecretKey, getPublicKey } from './pure.ts' -import { Relay } from './relay.ts' -import { MockRelay } from './test-helpers.ts' +import { Relay, useWebSocketImplementation } from './relay.ts' +import { MockRelay, MockWebSocketClient } from './test-helpers.ts' + +useWebSocketImplementation(MockWebSocketClient) test('connectivity', async () => { const mockRelay = new MockRelay() diff --git a/test-helpers.ts b/test-helpers.ts index 4ba1f7d..2f3bca4 100644 --- a/test-helpers.ts +++ b/test-helpers.ts @@ -1,8 +1,10 @@ -import { Server } from 'mock-socket' +import { Server, WebSocket } from 'mock-socket' import { finalizeEvent, type Event, getPublicKey, generateSecretKey } from './pure.ts' import { matchFilters, type Filter } from './filter.ts' +export const MockWebSocketClient = WebSocket + export function buildEvent(params: Partial): Event { return { id: '',