Excessibility.TelemetryCapture (Excessibility v0.18.1)

Copy Markdown View Source

Telemetry-based automatic snapshot capture for LiveView tests.

Attaches to Phoenix LiveView telemetry events to automatically capture snapshots when LiveView events occur, with no test code changes required.

Summary

Functions

Attaches telemetry handlers for automatic snapshot capture.

Clears all captured snapshots.

Detaches telemetry handlers.

The Ecto [..., :query] telemetry events for the configured :ecto_repos.

Returns and clears the Ecto queries accumulated in the current process since the last flush, oldest first. Called at each captured event so queries are attributed to the event that ran them.

Retrieves all captured snapshots and clears the table.

Handles telemetry events and captures snapshots.

An opt-in on_mount hook that records a LiveView's handle_info messages as timeline events.

Writes captured snapshots to timeline.json.

Functions

attach()

Attaches telemetry handlers for automatic snapshot capture.

Call this before running tests to enable auto-capture.

clear_snapshots(test_name \\ nil)

Clears all captured snapshots.

detach()

Detaches telemetry handlers.

ecto_query_events()

The Ecto [..., :query] telemetry events for the configured :ecto_repos.

flush_ecto_queries()

Returns and clears the Ecto queries accumulated in the current process since the last flush, oldest first. Called at each captured event so queries are attributed to the event that ran them.

get_snapshots()

Retrieves all captured snapshots and clears the table.

handle_event(list, measurements, metadata, config)

Handles telemetry events and captures snapshots.

on_mount(name, params, session, socket)

An opt-in on_mount hook that records a LiveView's handle_info messages as timeline events.

Phoenix LiveView emits telemetry for mount/handle_params/handle_event/ render but not for the message-driven callbacks, so there is no global event to attach to (issue #147). This hook is the seam: it uses Phoenix.LiveView.attach_hook/4 on the :handle_info stage, which does need to be installed per LiveView — so it is opt-in, never forced.

Wire it wherever you want that coverage — a router live_session covers every route in the session in one line:

live_session :default, on_mount: [Excessibility.TelemetryCapture] do
  # ...routes...
end

or your web module's live_view/0 to cover every LiveView. It attaches nothing unless telemetry capture is running (mix excessibility.debug) and the socket is connected, so it is safe to leave wired in all environments. Pair it with the (also opt-in) message_flooding analyzer.

write_snapshots(test_name)

Writes captured snapshots to timeline.json.

Note: HTML snapshot files are NOT generated from telemetry capture. For real accessibility testing, use html_snapshot(view) in your tests to capture actual rendered HTML.

Runs in the on_exit installed by use Excessibility, so a failure here is logged rather than raised — instrumentation must not fail the test it observes.