On This Page

FluxerTestClient

Class in Testing · Effect Testing

Effect service holding a native test client, for applications whose code reads the client from the FluxerClient service

Build both services with FluxerTestClient.layer(options) and read the controls with yield* FluxerTestClient

class FluxerTestClient
TypeScript
import { 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
): FluxerTestClient

Parameters

_
never

Methods#

static layer#

Build a test client with createTestClient and provide it twice: Its client as the FluxerClient service, so application code runs unchanged, and the whole test client as the FluxerTestClient service, for the controls

The layer takes the options of createTestClient without messageFields, because FluxerClient 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 UnhandledTestFailuresError when a handler or command failed without an onError hook and the test did not read that failure from failures(). Invalid options are a defect carrying ConfigurationError, as with createTestClient. 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

options optional
Omit<TestClientOptions<E, R, undefined>, "messageFields">Omit<
  TestClientOptions<E, R, undefined>,
  "messageFields"
>