-
-
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.
- Loading branch information
Showing
11 changed files
with
192 additions
and
147 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
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,3 +1,4 @@ | ||
export * from "./clients.ts"; | ||
export * from "./nodes.ts"; | ||
export * from "./protocol.ts"; | ||
export * from "./relays.ts"; | ||
export * from "./clients.ts"; |
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 |
---|---|---|
@@ -1,33 +1,43 @@ | ||
import { assertEquals } from "@std/assert"; | ||
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; | ||
import { assert, assertEquals } from "@std/assert"; | ||
import { assertType, Has } from "@std/testing/types"; | ||
import { describe, it } from "@std/testing/bdd"; | ||
import { MockWebSocket } from "@lophus/lib/testing"; | ||
import { NostrNode, NostrNodeBase } from "./nodes.ts"; | ||
import { NostrNode, NostrNodeBase, NostrNodeModule } from "./nodes.ts"; | ||
|
||
describe("NostrNodeBase", () => { | ||
let node: NostrNode; | ||
let writer: WritableStreamDefaultWriter; | ||
describe("constructor", () => { | ||
it("should create a NostrNodeBase instance", () => { | ||
const node = new NostrNodeBase(new MockWebSocket()); | ||
assert(node instanceof NostrNodeBase); | ||
}); | ||
|
||
beforeAll(() => { | ||
node = new NostrNodeBase(new MockWebSocket()); | ||
it("should infer the type of `modules` option", () => { | ||
const node = new NostrNodeBase(new MockWebSocket(), { | ||
modules: [{} as NostrNodeModule<1>, {} as NostrNodeModule<2>] as const, | ||
nbuffer: 64, | ||
}); | ||
assertType<Has<typeof node, NostrNode<1 | 2>>>(true); | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await node.close().catch((err) => { | ||
if (err.message !== "Writable stream is closed or errored.") { | ||
throw err; | ||
} | ||
describe("writable", () => { | ||
const node = new NostrNodeBase(new MockWebSocket()); | ||
let writer: WritableStreamDefaultWriter; | ||
|
||
it("should open the WebSocket connection", async () => { | ||
writer = node.writable.getWriter(); | ||
await writer.write(["NOTICE", "test"]); | ||
writer.releaseLock(); | ||
assertEquals(node.status, WebSocket.OPEN); | ||
}); | ||
}); | ||
|
||
it("should be connected to the WebSocket after a message is sent", async () => { | ||
writer = node.writable.getWriter(); | ||
await writer.write(["NOTICE", "test"]); | ||
writer.releaseLock(); | ||
assertEquals(node.status, WebSocket.OPEN); | ||
}); | ||
describe("close", () => { | ||
const node = new NostrNodeBase(new MockWebSocket()); | ||
|
||
it("should close the WebSocket when the node is closed", async () => { | ||
await node.close(); | ||
assertEquals(node.status, WebSocket.CLOSED); | ||
it("should close the WebSocket connection", async () => { | ||
await node.close(); | ||
assertEquals(node.status, WebSocket.CLOSED); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.