Test helpers for Plushie applications.
Setup
Call Plushie.Test.setup!() in your test/test_helper.exs before
ExUnit.start():
# test/test_helper.exs
Plushie.Test.setup!()
ExUnit.start()This starts the shared renderer session pool and configures ExUnit to exclude tests tagged for backends not currently active.
Backend selection
Set PLUSHIE_TEST_BACKEND to choose the backend:
mix test # mock (default)
PLUSHIE_TEST_BACKEND=headless mix test # headless rendering
PLUSHIE_TEST_BACKEND=windowed mix test # real windowsBackend-specific tests
Tag tests with the minimum backend they require:
@tag backend: :headless # runs in headless + windowed, skipped in mock
test "renders correctly" do ... end
@tag backend: :windowed # runs only in windowed
test "screenshot matches" do ... endBackend capability is hierarchical: mock < headless < windowed. Tag with the lowest backend that provides what the test needs. Untagged tests run in all modes.
Tree snapshot testing
test "initial view snapshot" do
model = MyApp.init([])
tree = MyApp.view(model)
Plushie.Test.assert_tree_snapshot(tree, "test/snapshots/initial_view.json")
endOn first run, assert_tree_snapshot/2 writes the snapshot file. On subsequent
runs, it compares against the stored snapshot. Update snapshots with:
PLUSHIE_UPDATE_SNAPSHOTS=1 mix test
Summary
Functions
Asserts that tree matches the stored structural snapshot at path.
Sets up the Plushie test infrastructure.
Functions
Asserts that tree matches the stored structural snapshot at path.
On first run (file does not exist), writes the snapshot.
On subsequent runs, compares and fails with a diff if different.
Set PLUSHIE_UPDATE_SNAPSHOTS=1 to overwrite existing snapshots.
Sets up the Plushie test infrastructure.
Call this from your test/test_helper.exs before ExUnit.start().
Starts the shared renderer session pool and configures backend-based
test exclusions.
Returns the ExUnit exclusion options -- pass them to ExUnit.start/1:
# test/test_helper.exs
plushie_opts = Plushie.Test.setup!()
ExUnit.start(plushie_opts)