Skip to content

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.

DiscordStub.clock  :: Clock

The clock the world runs on.

DiscordStub.httpServer  :: HttpServer?

The HTTP server, once createHttpServer has run.

DiscordStub.webSocketServer  :: WebsocketServer?

The gateway websocket server, once createWebsocketServer has run.

DiscordStub.restUrl  :: string?

The REST base URL of the HTTP server, nil before it exists.

DiscordStub.voiceServer  :: VoiceServer?

The voice gateway server, once createVoiceServer has run.

DiscordStub.udpServer  :: UdpServer?

The voice UDP server createVoiceServer started alongside the voice gateway server.

DiscordStub : stop ( )  -> ()

Stops every server and puts the real clock back. Safe to call twice.

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
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
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
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?
DiscordStub . new ( options )  -> DiscordStub

Creates a stub world.

Parameters

options: {
clock: "real" | "virtual"?,
polyfills: any?,
}