Bring back typedoc
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Tracker} from "../src/Tracker"
|
||||
import {vi, describe, it, expect, beforeEach} from "vitest"
|
||||
import {Tracker} from "../src/tracker"
|
||||
|
||||
describe("Tracker", () => {
|
||||
let tracker: Tracker
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import EventEmitter from "events"
|
||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest"
|
||||
import { isRelayUrl } from "@welshman/util"
|
||||
import { LocalRelay, LOCAL_RELAY_URL } from "@welshman/relay"
|
||||
import { LocalRelay, Repository, LOCAL_RELAY_URL } from "@welshman/relay"
|
||||
import { AdapterEvent, SocketAdapter, LocalAdapter, getAdapter } from "../src/adapter"
|
||||
import { ClientMessage, RelayMessage } from "../src/message"
|
||||
import { Socket, SocketEvent } from "../src/socket"
|
||||
import { Pool } from "../src/pool"
|
||||
|
||||
vi.mock('isomorphic-ws', () => {
|
||||
const WebSocket = vi.fn(function () {
|
||||
const WebSocket = vi.fn(function (this: any) {
|
||||
setTimeout(() => this.onopen())
|
||||
})
|
||||
|
||||
WebSocket.prototype.send = vi.fn()
|
||||
|
||||
WebSocket.prototype.close = vi.fn(function () {
|
||||
WebSocket.prototype.close = vi.fn(function (this: any) {
|
||||
this.onclose()
|
||||
})
|
||||
|
||||
@@ -120,12 +120,14 @@ describe("LocalAdapter", () => {
|
||||
|
||||
describe("getAdapter", () => {
|
||||
let pool: Pool
|
||||
let relay: LocalRelay
|
||||
let repository: Repository
|
||||
|
||||
beforeEach(() => {
|
||||
pool = new Pool()
|
||||
relay = new LocalRelay()
|
||||
pool.get = vi.fn().mockReturnValue(new Socket("wss://test.relay"))
|
||||
pool = new Pool({
|
||||
makeSocket: () => new Socket("wss://test.relay"),
|
||||
})
|
||||
|
||||
repository = new Repository()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -134,7 +136,7 @@ describe("getAdapter", () => {
|
||||
|
||||
it("should return LocalAdapter for local relay URL", () => {
|
||||
const url = LOCAL_RELAY_URL
|
||||
const adapter = getAdapter(url, { relay })
|
||||
const adapter = getAdapter(url, { repository })
|
||||
expect(adapter).toBeInstanceOf(LocalAdapter)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest"
|
||||
import { Socket, SocketStatus, SocketEvent } from "../src/socket"
|
||||
import { makeEvent, CLIENT_AUTH } from "@welshman/util"
|
||||
import { makeEvent, StampedEvent, CLIENT_AUTH } from "@welshman/util"
|
||||
import { Nip01Signer } from "@welshman/signer"
|
||||
import { AuthState, AuthStatus, AuthStateEvent, makeAuthEvent } from "../src/auth"
|
||||
import EventEmitter from "events"
|
||||
@@ -146,7 +146,7 @@ describe('auth', () => {
|
||||
socket.auth.challenge = "challenge123"
|
||||
socket.auth.status = AuthStatus.Requested
|
||||
|
||||
const sign = async e => {
|
||||
const sign = async (e: StampedEvent) => {
|
||||
event = await Nip01Signer.ephemeral().sign(e)
|
||||
|
||||
return event
|
||||
@@ -154,7 +154,7 @@ describe('auth', () => {
|
||||
|
||||
await socket.auth.authenticate(sign)
|
||||
|
||||
expect(socket.auth.request).toStrictEqual(event.id)
|
||||
expect(socket.auth.request).toStrictEqual(event!.id)
|
||||
expect(sendSpy).toHaveBeenCalledWith(["AUTH", event])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,13 +4,13 @@ import { Pool, makeSocket } from "../src/pool"
|
||||
import { normalizeRelayUrl } from "@welshman/util"
|
||||
|
||||
vi.mock('isomorphic-ws', () => {
|
||||
const WebSocket = vi.fn(function () {
|
||||
const WebSocket = vi.fn(function (this: any) {
|
||||
setTimeout(() => this.onopen())
|
||||
})
|
||||
|
||||
WebSocket.prototype.send = vi.fn()
|
||||
|
||||
WebSocket.prototype.close = vi.fn(function () {
|
||||
WebSocket.prototype.close = vi.fn(function (this: any) {
|
||||
this.onclose()
|
||||
})
|
||||
|
||||
@@ -97,7 +97,7 @@ describe("Pool", () => {
|
||||
it("should remove and cleanup existing socket", () => {
|
||||
const mockSocket = { url: "wss://test.relay", cleanup: vi.fn() }
|
||||
|
||||
pool._data.set(mockSocket.url, mockSocket)
|
||||
pool._data.set(mockSocket.url, mockSocket as unknown as Socket)
|
||||
pool.remove(mockSocket.url)
|
||||
|
||||
expect(mockSocket.cleanup).toHaveBeenCalled()
|
||||
@@ -116,7 +116,7 @@ describe("Pool", () => {
|
||||
const mockSockets = urls.map(url => ({ url, cleanup: vi.fn() }))
|
||||
|
||||
for (const mockSocket of mockSockets) {
|
||||
pool._data.set(mockSocket.url, mockSocket)
|
||||
pool._data.set(mockSocket.url, mockSocket as unknown as Socket)
|
||||
}
|
||||
|
||||
pool.clear()
|
||||
|
||||
@@ -103,14 +103,14 @@ describe("SinglePublish", () => {
|
||||
pub.on(PublishEvent.Complete, completeSpy)
|
||||
pub.on(PublishEvent.Timeout, timeoutSpy)
|
||||
|
||||
await vi.runAllTimers(200)
|
||||
await vi.runAllTimers()
|
||||
|
||||
expect(sendSpy).toHaveBeenCalledWith([ClientMessageType.Event, event])
|
||||
|
||||
await vi.runAllTimers()
|
||||
|
||||
expect(successSpy).not.toHaveBeenCalled()
|
||||
expect(failureSpy).not.toHaveBeenCalled(event.id, "hi")
|
||||
expect(failureSpy).not.toHaveBeenCalled()
|
||||
expect(completeSpy).toHaveBeenCalled()
|
||||
expect(timeoutSpy).toHaveBeenCalled()
|
||||
})
|
||||
@@ -137,7 +137,7 @@ describe("SinglePublish", () => {
|
||||
pub.on(PublishEvent.Complete, completeSpy)
|
||||
pub.on(PublishEvent.Timeout, abortSpy)
|
||||
|
||||
await vi.runAllTimers(200)
|
||||
await vi.runAllTimers()
|
||||
|
||||
expect(sendSpy).toHaveBeenCalledWith([ClientMessageType.Event, event])
|
||||
|
||||
@@ -146,7 +146,7 @@ describe("SinglePublish", () => {
|
||||
await vi.runAllTimers()
|
||||
|
||||
expect(successSpy).not.toHaveBeenCalled()
|
||||
expect(failureSpy).not.toHaveBeenCalled(event.id, "hi")
|
||||
expect(failureSpy).not.toHaveBeenCalled()
|
||||
expect(completeSpy).toHaveBeenCalled()
|
||||
expect(abortSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -5,13 +5,13 @@ import { Socket, SocketStatus, SocketEvent } from "../src/socket"
|
||||
import { ClientMessage, RelayMessage } from "../src/message"
|
||||
|
||||
vi.mock('isomorphic-ws', () => {
|
||||
const WebSocket = vi.fn(function () {
|
||||
const WebSocket = vi.fn(function (this: any) {
|
||||
setTimeout(() => this.onopen())
|
||||
})
|
||||
|
||||
WebSocket.prototype.send = vi.fn()
|
||||
|
||||
WebSocket.prototype.close = vi.fn(function () {
|
||||
WebSocket.prototype.close = vi.fn(function (this: any) {
|
||||
this.onclose()
|
||||
})
|
||||
|
||||
@@ -77,11 +77,9 @@ describe("Socket", () => {
|
||||
|
||||
socket.open()
|
||||
|
||||
const ws = socket._ws
|
||||
|
||||
socket.close()
|
||||
|
||||
expect(ws.close).toHaveBeenCalled()
|
||||
expect(socket._ws!.close).toHaveBeenCalled()
|
||||
expect(statusSpy).toHaveBeenCalledWith(SocketStatus.Closed, "wss://test.relay")
|
||||
})
|
||||
})
|
||||
@@ -102,14 +100,14 @@ describe("Socket", () => {
|
||||
socket.on(SocketEvent.Send, sendSpy)
|
||||
|
||||
socket.open()
|
||||
socket._ws.onopen()
|
||||
socket._ws?.onopen?.(undefined as unknown as any)
|
||||
|
||||
const message: ClientMessage = ["EVENT", { id: "123", kind: 1 }]
|
||||
socket.send(message)
|
||||
|
||||
await vi.runAllTimers()
|
||||
|
||||
expect(socket._ws.send).toHaveBeenCalledWith(JSON.stringify(message))
|
||||
expect(socket._ws!.send).toHaveBeenCalledWith(JSON.stringify(message))
|
||||
expect(sendSpy).toHaveBeenCalledWith(message, "wss://test.relay")
|
||||
})
|
||||
})
|
||||
@@ -121,9 +119,8 @@ describe("Socket", () => {
|
||||
|
||||
socket.open()
|
||||
const message: RelayMessage = ["EVENT", "123", { id: "123", kind: 1 }]
|
||||
socket._ws.onmessage({ data: JSON.stringify(message) })
|
||||
socket._ws?.onmessage?.({data: JSON.stringify(message)} as unknown as any)
|
||||
|
||||
// Allow task queue to process
|
||||
await vi.runAllTimers()
|
||||
|
||||
expect(receiveSpy).toHaveBeenCalledWith(message, "wss://test.relay")
|
||||
@@ -134,7 +131,7 @@ describe("Socket", () => {
|
||||
socket.on(SocketEvent.Error, errorSpy)
|
||||
|
||||
socket.open()
|
||||
socket._ws.onmessage({ data: "invalid json" })
|
||||
socket._ws?.onmessage?.({data: "invalid json"} as unknown as any)
|
||||
|
||||
expect(errorSpy).toHaveBeenCalledWith("Invalid message received", "wss://test.relay")
|
||||
})
|
||||
@@ -144,7 +141,7 @@ describe("Socket", () => {
|
||||
socket.on(SocketEvent.Error, errorSpy)
|
||||
|
||||
socket.open()
|
||||
socket._ws.onmessage({ data: JSON.stringify({ not: "an array" }) })
|
||||
socket._ws?.onmessage?.({data: JSON.stringify({not: "an array"})} as unknown as any)
|
||||
|
||||
expect(errorSpy).toHaveBeenCalledWith("Invalid message received", "wss://test.relay")
|
||||
})
|
||||
@@ -158,7 +155,7 @@ describe("Socket", () => {
|
||||
|
||||
socket.cleanup()
|
||||
|
||||
expect(ws.close).toHaveBeenCalled()
|
||||
expect(ws!.close).toHaveBeenCalled()
|
||||
expect(socket.listenerCount(SocketEvent.Send)).toBe(0)
|
||||
})
|
||||
})
|
||||
@@ -169,7 +166,7 @@ describe("Socket", () => {
|
||||
socket.on(SocketEvent.Status, statusSpy)
|
||||
|
||||
socket.open()
|
||||
socket._ws.onerror()
|
||||
socket._ws?.onerror?.(undefined as unknown as any)
|
||||
|
||||
expect(statusSpy).toHaveBeenCalledWith(SocketStatus.Error, "wss://test.relay")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user