-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!(lib/events): modify the interface of EventPublisher (#21)
- Loading branch information
Showing
5 changed files
with
55 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { afterAll, beforeAll, describe, it } from "./std/testing.ts"; | ||
import { assertEquals, assertInstanceOf } from "./std/assert.ts"; | ||
import { pipeThroughFrom } from "./x/streamtools.ts"; | ||
import type {} from "../core/protocol.d.ts"; | ||
import { Relay } from "../core/relays.ts?nips=1"; | ||
import { PrivateKey, Signer } from "./signs.ts"; | ||
import { EventInit, EventPublisher } from "./events.ts"; | ||
import { MockWebSocket } from "../lib/testing.ts"; | ||
|
||
describe("EventPublisher", () => { | ||
let relay: Relay; | ||
let signer: Signer; | ||
let publisher: EventPublisher<1>; | ||
|
||
beforeAll(() => { | ||
globalThis.WebSocket = MockWebSocket; | ||
signer = new Signer(PrivateKey.generate()); | ||
}); | ||
afterAll(() => { | ||
relay?.close(); | ||
}); | ||
|
||
it("should be a TransformStream", () => { | ||
publisher = new EventPublisher(signer); | ||
assertInstanceOf(publisher, TransformStream); | ||
}); | ||
|
||
// FIXME: dangling promise | ||
it.ignore("should transform EventInit to ClientToRelayMessage", async () => { | ||
const { readable, writable } = publisher; | ||
const reader = readable.getReader(); | ||
const writer = writable.getWriter(); | ||
const init = { kind: 1, content: "hello" } satisfies EventInit<1>; | ||
await writer.write(init); | ||
const { value } = await reader.read(); | ||
assertEquals(value, ["EVENT", signer.sign(init)]); | ||
await writer.close(); | ||
await reader.cancel(); | ||
}); | ||
|
||
// FIXME: runtime error | ||
it.ignore("should be connectable to a relay", () => { | ||
relay = new Relay("wss://example.com"); | ||
const writable = pipeThroughFrom(relay, publisher); | ||
assertInstanceOf(writable, WritableStream); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { collect } from "https://deno.land/x/[email protected]/collect.ts"; | ||
export { pop } from "https://deno.land/x/[email protected]/pop.ts"; | ||
export { pipeThroughFrom } from "https://deno.land/x/[email protected]/pipe_through_from.ts"; |