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'sreporter: [['json', { outputFile }]];PLAYWRIGHT_JSON_OUTPUT_NAMEinPLAYWRIGHT_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; an empty one is unset, as upstream's. The
report's strings are text, as JavaScript's are: the bytes of a binary that aren't UTF-8 (in a
failure's message, a step's title) are replaced (U+FFFD). 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. A test's and its result's annotations are those of
Playwright.Test.annotate/1 and Playwright.Test.fail/2 (without their location); a test of
fail/2 has expectedStatus failed, its result is its body's and its outcome goes by both,
as upstream's. A result's stdout is the test's (see "Output" in Playwright.Test). Not
ported: stderr is empty, tags too (ExUnit's tags aren't Playwright's); 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).
Ported from upstream's packages/playwright/src/reporters/json.ts.
Summary
Functions
Returns a specification to start this module under a supervisor.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.