Module
poke/snapshot
src/poke/snapshot.pookaLeave a candidate by the door; acceptance is a separate decision.
Matching snapshots pass. Missing or changed snapshots write a .new file and fail until reviewed. Tests never accept their own output, including in CI. Accepted files contain exact UTF-8 text, without headers or terminal colours.
API reference
enum Kind
Kind.Missing
Kind.Changed
Kind.Io
Kind.InvalidName
class SnapshotError(kind: Kind, path: String, message: String)
kind: Kind
poke/snapshot.Kindpath: String
Stringmessage: String
String
fn(poke/snapshot.Kind, String, String) -> poke/snapshot.SnapshotErrorclass Store(directory: String)
A caller-chosen directory. Names use ASCII letters/digits, '-' or '_', at most 120 characters. Use unique names for simultaneously running tests.
directory: String
String
fn(String) -> poke/snapshot.Storecheck(content: String, name: String) -> Result(Nil, SnapshotError)
fn(String, String) -> Result(Nil, poke/snapshot.SnapshotError)Compare exact text. A matching accepted file removes a stale candidate.
accept(name: String) -> Result(Nil, SnapshotError)
fn(String) -> Result(Nil, poke/snapshot.SnapshotError)Copy the reviewed candidate into place atomically, then remove it.
reject(name: String) -> Result(Nil, SnapshotError)
fn(String) -> Result(Nil, poke/snapshot.SnapshotError)Discard the candidate, keeping any accepted snapshot untouched.
pending() -> Result(List(String), SnapshotError)
fn() -> Result(List(String), poke/snapshot.SnapshotError)Pending safe file names in stable order. Missing directories are empty.
versions(name: String) -> Result(#(Option(String), String), SnapshotError)
fn(String) -> Result(#(Option(String), String), poke/snapshot.SnapshotError)Read both versions once for a review screen. No files are changed.
preview(name: String, mode: Mode) -> Result(String, SnapshotError)
fn(String, poke/palette.Mode) -> Result(String, poke/snapshot.SnapshotError)A coloured or plain preview. Reading it never changes either file.
default_store() -> Store
fn() -> poke/snapshot.StoreThe default store, relative to the package where pooka test is run.
snap(content: String, name: String) -> Nil
fn(String, String) -> NilA snapshot assertion that fits an ordinary test declaration.
snapshot.snap("hello\n", "greeting")
describe(problem: SnapshotError) -> String
fn(poke/snapshot.SnapshotError) -> Stringvalue(actual: a, name: String) -> Nil
fn(a, String) -> NilSnapshot a complete value with fixed-width, colour-free formatting.
snapshot.value(Ok([1, 2, 3]), "numbers")
value_with(actual: a, name: String, options: pretty.Options) -> Nil
fn(a, String, poke/pretty.Options) -> NilChoose layout width and indentation. Snapshot values are never truncated even when display limits are supplied. Output is always plain.