Class in Testing · Effect Testing
Effect service holding a native test client, for applications whose code reads the client from the Fluxer service
Build both services with Fluxer(options) and read the controls with yield* Fluxer
class FluxerTestClientimport { Effect } from "effect"
import { FluxerClient } from "@neontechspace/fluxerly/effect"
import { FluxerTestClient } from "@neontechspace/fluxerly/effect/testing"
// Application code that depends on the FluxerClient service
const registerPing = Effect.gen(function* () {
const client = yield* FluxerClient
yield* client.on("messageCreate", (message) =>
message.content === "!ping" ? client.messages.reply(message, "Pong!") : Effect.void,
)
})
export const pingTest = Effect.gen(function* () {
yield* registerPing
const test = yield* FluxerTestClient
const replies = test.rest.respond("POST /channels/:id/messages", {
body: test.fixtures.message({ content: "Pong!" }),
})
yield* test.ready()
yield* test.emit("MESSAGE_CREATE", test.fixtures.message({ content: "!ping" }))
return yield* replies.next()
}).pipe(Effect.scoped, Effect.provide(FluxerTestClient.layer()))
Constructor#
new FluxerTestClient(_: never): FluxerTestClientnew FluxerTestClient(
_: never
): FluxerTestClientParameters
_-
never
Methods#
static layer#
Build a test client with create and provide it twice: Its client as the Fluxer service, so application code runs unchanged, and the whole test client as the Fluxer service, for the controls
The layer takes the options of create without message, because Fluxer holds full messages. The client is created in the layer's Scope without connecting, and closing that Scope shuts it down and closes the test transport. It dies with Unhandled when a handler or command failed without an on hook and the test did not read that failure from failures(). Invalid options are a defect carrying Configuration, as with create. Each build of the layer creates its own test client
static layer<E = never, R = never>(
options?:
Omit<TestClientOptions<E, R, undefined>, "messageFields">
): Layer<FluxerClient | FluxerTestClient, never, R>static layer<E = never, R = never>(
options?: Omit<
TestClientOptions<
E, R, undefined
>,
"messageFields"
>
): Layer<
FluxerClient | FluxerTestClient,
never,
R
>Parameters
optionsoptional-
Omit<TestClientOptions<E, R, undefined>, "messageFields">Omit< TestClientOptions<E, R, undefined>, "messageFields" >
- Returns
Layer<FluxerClient | FluxerTestClient, never, R>Layer< FluxerClient | FluxerTestClient, never, R >