Module

poke/snapshot

src/poke/snapshot.pooka

Leave 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

src/poke/snapshot.pooka:20
enum Kind
variant

Missing

src/poke/snapshot.pooka:21
Kind.Missing
variant

Changed

src/poke/snapshot.pooka:22
Kind.Changed
variant

Io

src/poke/snapshot.pooka:23
Kind.Io
variant

InvalidName

src/poke/snapshot.pooka:24
Kind.InvalidName
class

SnapshotError

src/poke/snapshot.pooka:27
class SnapshotError(kind: Kind, path: String, message: String)
field

kind

src/poke/snapshot.pooka:27
kind: Kind
field

path

src/poke/snapshot.pooka:27
path: String
INFERREDString
field

message

src/poke/snapshot.pooka:27
message: String
INFERREDString
constructor

new

src/poke/snapshot.pooka:27
INFERREDfn(poke/snapshot.Kind, String, String) -> poke/snapshot.SnapshotError
class

Store

src/poke/snapshot.pooka:35
class Store(directory: String)

A caller-chosen directory. Names use ASCII letters/digits, '-' or '_', at most 120 characters. Use unique names for simultaneously running tests.

field

directory

src/poke/snapshot.pooka:35
directory: String
INFERREDString
constructor

new

src/poke/snapshot.pooka:35
INFERREDfn(String) -> poke/snapshot.Store
method

check

src/poke/snapshot.pooka:37
check(content: String, name: String) -> Result(Nil, SnapshotError)
INFERREDfn(String, String) -> Result(Nil, poke/snapshot.SnapshotError)

Compare exact text. A matching accepted file removes a stale candidate.

method

accept

src/poke/snapshot.pooka:71
accept(name: String) -> Result(Nil, SnapshotError)
INFERREDfn(String) -> Result(Nil, poke/snapshot.SnapshotError)

Copy the reviewed candidate into place atomically, then remove it.

method

reject

src/poke/snapshot.pooka:80
reject(name: String) -> Result(Nil, SnapshotError)
INFERREDfn(String) -> Result(Nil, poke/snapshot.SnapshotError)

Discard the candidate, keeping any accepted snapshot untouched.

method

pending

src/poke/snapshot.pooka:86
pending() -> Result(List(String), SnapshotError)
INFERREDfn() -> Result(List(String), poke/snapshot.SnapshotError)

Pending safe file names in stable order. Missing directories are empty.

method

versions

src/poke/snapshot.pooka:122
versions(name: String) -> Result(#(Option(String), String), SnapshotError)
INFERREDfn(String) -> Result(#(Option(String), String), poke/snapshot.SnapshotError)

Read both versions once for a review screen. No files are changed.

method

preview

src/poke/snapshot.pooka:137
preview(name: String, mode: Mode) -> Result(String, SnapshotError)
INFERREDfn(String, poke/palette.Mode) -> Result(String, poke/snapshot.SnapshotError)

A coloured or plain preview. Reading it never changes either file.

function

default_store

src/poke/snapshot.pooka:144
default_store() -> Store
INFERREDfn() -> poke/snapshot.Store

The default store, relative to the package where pooka test is run.

function

snap

src/poke/snapshot.pooka:153
snap(content: String, name: String) -> Nil
INFERREDfn(String, String) -> Nil

A snapshot assertion that fits an ordinary test declaration.

Pooka
snapshot.snap("hello\n", "greeting")
function

describe

src/poke/snapshot.pooka:162
describe(problem: SnapshotError) -> String
INFERREDfn(poke/snapshot.SnapshotError) -> String
function

value

src/poke/snapshot.pooka:226
value(actual: a, name: String) -> Nil
INFERREDfn(a, String) -> Nil

Snapshot a complete value with fixed-width, colour-free formatting.

Pooka
snapshot.value(Ok([1, 2, 3]), "numbers")
function

value_with

src/poke/snapshot.pooka:232
value_with(actual: a, name: String, options: pretty.Options) -> Nil
INFERREDfn(a, String, poke/pretty.Options) -> Nil

Choose layout width and indentation. Snapshot values are never truncated even when display limits are supplied. Output is always plain.