DiscordStub
One local Discord world: a clock, an HTTP server, a gateway websocket server and a voice server with its UDP
server. clock = "virtual" runs the world 100x faster than real time. discordStub.recordEmits(emitter) records
every call an emitter fires, and discordStub.VoiceServer and discordStub.UdpServer build voice doubles outside
a world.
Summary
Properties
DiscordStub.clock :: ClockDiscordStub.httpServer :: HttpServer?DiscordStub.webSocketServer :: WebsocketServer?DiscordStub.restUrl :: string?DiscordStub.voiceServer :: VoiceServer?DiscordStub.udpServer :: UdpServer?Methods
DiscordStub:stop()DiscordStub:createHttpServer(handler: httpServer.Handler?) → httpServer.HttpServerDiscordStub:createWebsocketServer(handler: webSocketServer.Handler?) → webSocketServer.WebsocketServerDiscordStub:createVoiceServer(options: VoiceServerOptions?) → voiceServer.VoiceServerDiscordStub:runScenario(scenario: () -> ...any, teardown: (() -> ())?) → string?Properties
Section titled “Properties”The clock the world runs on.
httpServer
Section titled “httpServer”The HTTP server, once createHttpServer has run.
webSocketServer
Section titled “webSocketServer”The gateway websocket server, once createWebsocketServer has run.
restUrl
Section titled “restUrl”The REST base URL of the HTTP server, nil before it exists.
voiceServer
Section titled “voiceServer”The voice gateway server, once createVoiceServer has run.
udpServer
Section titled “udpServer”The voice UDP server createVoiceServer started alongside the voice gateway server.
Methods
Section titled “Methods”DiscordStub : stop ( ) -> ()
Stops every server and puts the real clock back. Safe to call twice.
createHttpServer
Section titled “createHttpServer”DiscordStub : createHttpServer ( handler ) -> HttpServer
Starts an HTTP server on 127.0.0.1 with an ephemeral port. The handler may return a response or a raw string;
nil falls through to the default routes.
Parameters
| handler: Handler? |
Returns
| HttpServer |
createWebsocketServer
Section titled “createWebsocketServer”DiscordStub : createWebsocketServer ( handler ) -> WebsocketServer
Starts a gateway websocket server on 127.0.0.1 with an ephemeral port. The handler receives the connection and
the payload, and may return a payload to send instead of the default reply or false to send nothing; nil falls
through.
Parameters
| handler: Handler? |
Returns
| WebsocketServer |
createVoiceServer
Section titled “createVoiceServer”DiscordStub : createVoiceServer ( options ) -> VoiceServer
Starts a voice UDP server and a voice gateway server on 127.0.0.1, both on the world clock, and attaches the
voice server to the gateway websocket server, now or when it is created, so Voice State Update is answered with
the voice dispatches.
Parameters
| options: VoiceServerOptions? |
Returns
| VoiceServer |
runScenario
Section titled “runScenario”DiscordStub : runScenario ( scenario , teardown ) -> string?
Runs one test scenario, then teardown (the caller's own cleanup, such as closing a shard), then stops the world,
even when either of them throws. Returns the scenario's error, else the teardown's error, else the first error a
websocket handler, the voice server or the UDP server raised, else nil.
Parameters
| scenario: any | |
| teardown: (() -> ())? |
Returns
| string? |
Functions
Section titled “Functions”DiscordStub . new ( options ) -> DiscordStub
Creates a stub world.
Parameters
| options: { clock: "real" | "virtual"?, polyfills: any?, } |
Returns
| DiscordStub |