# `Playwright.Test.JSONFormatter`
[🔗](https://github.com/ftes/playwright_ex/blob/v1.65.0-rc.5/lib/playwright/test/json_formatter.ex#L5)

Playwright Test's `json` reporter as an ExUnit formatter: one JSON report of the run, written
when the suite finishes. It prints nothing else, so it runs next to `ExUnit.CLIFormatter`:

    mix test --formatter ExUnit.CLIFormatter --formatter Playwright.Test.JSONFormatter

`--formatter` replaces the configured formatters, so name `ExUnit.CLIFormatter` too. Or add it
in `test/test_helper.exs`:

    ExUnit.start(formatters: [ExUnit.CLIFormatter, Playwright.Test.JSONFormatter])

The report goes to the first of:

  * `PLAYWRIGHT_JSON_OUTPUT_FILE`, a path;
  * `config :playwright, :test, json_output_file: "test-results/results.json"`, upstream's
    `reporter: [['json', { outputFile }]]`;
  * `PLAYWRIGHT_JSON_OUTPUT_NAME` in `PLAYWRIGHT_JSON_OUTPUT_DIR` (default: the working
    directory);
  * else standard output, as upstream's without an output file.

Relative paths are relative to the working directory. The report's strings must be valid UTF-8:
a binary that isn't (in a failure's message, a step's title) raises at the suite's end. Next to
`ExUnit.CLIFormatter`, a report on standard output is mixed with its output: there, run the
formatter on its own, or set an output file.

The report has upstream's `JSONReport` shape: `config`, `suites` (a suite per test file
relative to `test/`, the `rootDir`, with a suite per `describe`), each with its `specs` (a
test, its `tests` one per project of `parameterize:`), each test's `results`, `errors` (a
failed `setup_all`) and `stats`. A result has its `status` (`passed`, `failed`, `timedOut`,
`skipped`), `duration` (ms, ExUnit's time of the test and its setup), `errors` (ExUnit's text
of each failure, without its header, and its location in your code), `error` (the first, as
upstream's `TestError`: `message` and `stack`, or `value` for an exit or throw), `steps`
(those of `Playwright.Test.step/2,3`, nested), `retry` and `attachments`: upstream's
`name`, `contentType` and `path` (absolute) or `body` (base64), the `Playwright.Test.attach/2`
ones and the artifacts' (`trace`, `screenshot`, `video`, `error-context`), complete when ExUnit
reports the test. A test not run after a failed `setup_all` has no results; an excluded one is
left out.

    # Each test's status and trace (a describe's specs are in its file suite's `suites`).
    report = JSON.decode!(File.read!("test-results/results.json"))

    for file <- report["suites"], suite <- [file | file["suites"] || []], spec <- suite["specs"],
        test <- spec["tests"], result <- test["results"],
        %{"name" => "trace", "path" => path} <- result["attachments"],
        do: {spec["title"], result["status"], path}

A test of a module without `use Playwright.Test` has ExUnit's fields only: no steps or
attachments, and its start time is its end (after its `on_exit` callbacks) less its duration.

ExUnit has no retries in a run: `retry` is 1 under `mix test --failed`, as
`Playwright.Test.info/0`'s, and a test passing there is `flaky`, as in
`Playwright.Test.GitHubFormatter`. Not ported: `stdout` and `stderr` are empty, `annotations`
and `tags` (ExUnit's tags aren't Playwright's) too; the results have no `workerIndex`,
`parallelIndex` or `shardIndex` (ExUnit runs modules, not workers); the `config` has only
`rootDir`, `version`, `workers`, `maxFailures`, `preserveOutput`, `reportSlowTests`,
`metadata` and the projects the tests ran in (without `testIgnore` and `testMatch`).

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
