ExUnitJSON.CompactOutput (ex_unit_json v0.4.2)

Copy Markdown View Source

Compact JSONL output format for ExUnitJSON.

Provides functionality for the --compact option, which outputs one JSON object per line with minimal fields for efficient streaming and parsing.

Format

Each test is output as a single line JSON object with compact keys:

  • f - File path with line number (e.g., "test/my_test.exs:42")
  • n - Test name
  • s - Test state (passed, failed, skipped, excluded, invalid)
  • e - Error message first line (only for failed tests)
  • x - Filtered flag (only when true)

The last line is a summary object: {"summary": {...}}

Summary

Types

A JSON-encoded test result map

Summary statistics map

Functions

Builds compact JSONL output from tests and summary.

Encodes a single test as a compact JSON object.

Types

encoded_test()

@type encoded_test() :: map()

A JSON-encoded test result map

summary()

@type summary() :: map()

Summary statistics map

Functions

build_compact_output(tests, summary, opts)

@spec build_compact_output([encoded_test()] | nil, summary(), keyword()) :: iodata()

Builds compact JSONL output from tests and summary.

Returns iodata with one JSON object per line, ending with summary.

Examples

tests = [%{name: "test", file: "test.exs", line: 1, state: "passed", ...}]
summary = %{total: 1, passed: 1, ...}
build_compact_output(tests, summary, [])
#=> "{\"f\":\"test.exs:1\",\"n\":\"test\",\"s\":\"passed\"}\n{\"summary\":{...}}\n"

encode_compact_test(test)

@spec encode_compact_test(encoded_test()) :: String.t()

Encodes a single test as a compact JSON object.

Keys

  • f - file:line
  • n - name
  • s - state
  • e - error (first line only, only if failed)
  • x - filtered (only if true)

Examples

test = %{file: "test.exs", line: 10, name: "passes", state: "passed", failures: []}
encode_compact_test(test)
#=> "{\"f\":\"test.exs:10\",\"n\":\"passes\",\"s\":\"passed\"}"