dream_test/reporter/json
JSON test reporter for dream_test.
This reporter outputs test results as JSON for CI/CD integration, test aggregation, and tooling.
Example Output
{
"version": "1.0",
"timestamp_ms": 1733151045123,
"duration_ms": 315,
"system": {
"os": "darwin",
"otp_version": "27",
"gleam_version": "0.67.0"
},
"summary": {
"total": 3,
"passed": 2,
"failed": 1,
"skipped": 0,
"pending": 0,
"timed_out": 0,
"setup_failed": 0
},
"tests": [
{
"name": "adds numbers",
"full_name": ["Calculator", "add", "adds numbers"],
"status": "passed",
"duration_ms": 2,
"tags": [],
"kind": "unit",
"failures": []
}
]
}
Usage
import dream_test/reporter/json
import gleam/io
pub fn main() {
to_test_cases("my_test", tests())
|> run_all()
|> json.report(io.print)
|> exit_on_failure()
}
Combining with BDD Reporter
results
|> bdd.report(io.print) // Human-readable to stdout
|> json.report(write_to_file) // JSON to file
|> exit_on_failure()
Values
pub fn format(results: List(types.TestResult)) -> String
Format test results as a compact JSON string.
Returns a single-line JSON string suitable for machine parsing.
Example
let json_string = format(results)
file.write("test-results.json", json_string)
pub fn format_pretty(results: List(types.TestResult)) -> String
Format test results as pretty-printed JSON.
Returns an indented, human-readable JSON string with 2-space indentation.
Example
let json_string = format_pretty(results)
io.println(json_string)
pub fn report(
results: List(types.TestResult),
write: fn(String) -> Nil,
) -> List(types.TestResult)
Print test results as JSON using a provided writer function.
This is the main entry point for JSON reporting. The writer function receives the JSON string and can print it, log it, or write it to a file.
Example
// Print to stdout
results |> json.report(io.print)
// Write to file
results |> json.report(fn(s) { file.write("results.json", s) })
Returns
Returns the input results unchanged, enabling pipeline composition:
to_test_cases("my_test", tests())
|> run_all()
|> bdd.report(io.print)
|> json.report(write_to_file)
|> exit_on_failure()
pub fn report_pretty(
results: List(types.TestResult),
write: fn(String) -> Nil,
) -> List(types.TestResult)
Print test results as pretty-printed JSON using a provided writer function.
Same as report but with indented, human-readable output.
Example
results |> json.report_pretty(io.print)