SandboxCase.Sandbox.Adapter behaviour (sandbox_case v0.4.0)

Copy Markdown View Source

Behaviour for sandbox adapters.

Each adapter handles setup (once in test_helper), checkout (per test), and checkin (on_exit). The adapter returns an opaque token from checkout that is passed back to checkin.

Adapters can optionally declare plug and on_mount modules to be registered in endpoints and LiveViews via sandbox_plugs() and sandbox_on_mount().

Summary

Callbacks

Whether this adapter is available (deps loaded).

Per-test checkin. Receives the token from checkout.

Per-test checkout. Returns an opaque token or nil.

on_mount modules to register in LiveViews. Return [] if none.

Plug modules to register in the endpoint. Return [] if none.

Process dictionary keys to propagate to child processes. Return [] if none.

One-time setup in test_helper. Receives adapter-specific config.

Callbacks

available?()

@callback available?() :: boolean()

Whether this adapter is available (deps loaded).

checkin(token)

@callback checkin(token :: term()) :: :ok

Per-test checkin. Receives the token from checkout.

checkout(config)

@callback checkout(config :: term()) :: term() | nil

Per-test checkout. Returns an opaque token or nil.

hooks()

(optional)
@callback hooks() :: [module()]

on_mount modules to register in LiveViews. Return [] if none.

plugs()

(optional)
@callback plugs() :: [module()]

Plug modules to register in the endpoint. Return [] if none.

propagate_keys(config)

(optional)
@callback propagate_keys(config :: term()) :: [term()]

Process dictionary keys to propagate to child processes. Return [] if none.

setup config

@callback setup(config :: term()) :: :ok

One-time setup in test_helper. Receives adapter-specific config.