drift/record
Records the inputs an outputs of a drift stepper, given a pre-defined set of inputs. Intended for snapshot testing.
Types
The union of inputs, outputs and errors, to help with formatting.
pub type Message(i, o, e) {
Input(i)
Output(o)
Error(e)
}
Constructors
-
Input(i) -
Output(o) -
Error(e)
Values
pub fn discard() -> drift.Effect(a)
A utility function that creates an effect which only discards its input. You usually would not want to apply any side effects during snapshot testing.
pub fn flush(
recorder: Recorder(s, i, o, e),
what: String,
) -> Recorder(s, i, o, e)
Flushes all previous recorded inputs and outputs, and replaces the log with a message containing the provided description.
pub fn input(
recorder: Recorder(s, i, o, e),
input: i,
) -> Recorder(s, i, o, e)
Applies the given input to the stepper, and returns a new recorder with the step recorded.
pub fn new(
state: s,
apply_input: fn(drift.Context(i, o), s, i) -> drift.Step(
s,
i,
o,
e,
),
formatter: fn(Message(i, o, e)) -> String,
final_state_formatter: option.Option(fn(s) -> String),
) -> Recorder(s, i, o, e)
Creates a new recorder, with the given state, behavior, and formatting.
pub fn time_advance(
recorder: Recorder(s, i, o, e),
duration: Int,
) -> Recorder(s, i, o, e)
Advances the simulated time, and returns a new recorder with the results of the possible timers being processed. Note that if the time encompasses multiple timer due times, all of them will be fired at the given time, not at their due time. This enables testing what happens if the timers fire late.
pub fn to_log(recorder: Recorder(s, i, o, e)) -> String
Turns the recorded steps into a string, which can be used with snapshot testing libraries (e.g. birdie).
pub fn use_latest_outputs(
recorder: Recorder(s, i, o, e),
with: fn(Recorder(s, i, o, e), List(o)) -> Recorder(s, i, o, e),
) -> Recorder(s, i, o, e)
Applies the given function that produces the next state of the recorder from the outputs of the previously executed step. This is mostly required for testing continuations.