Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The JUnit style XML report for this project looks like this:
- `include_file_line?` (boolean - default `false`): only has effect when `include_filename?` is `true`. Dictates whether `file` attribute should include line of the test after a colon (e.g. `test/file_test.exs:123`).
- `automatic_create_dir?` (boolean - default `false`): create a directory that defined in `report_dir` before writing report files.
- `project_dir` (string - default `nil`). Specifies which directory the test file paths should be relative to within the XML. If unset or `nil`, the path to the test file is calculated relative to the current working directory.
- `properties` (map - default `%{}`): custom properties to include in the JUnit XML `<properties>` section. These properties will be merged with the default properties (seed and date).

Example configuration:

Expand All @@ -87,7 +88,13 @@ config :junit_formatter,
report_dir: "/tmp",
print_report_file: true,
prepend_project_name?: true,
include_filename?: true
include_filename?: true,
properties: %{
"platform.os" => "linux",
"platform.architecture" => "x86_64",
"test.tier" => "1",
"environment" => "ci"
}
```

This would generate the report at: `/tmp/myapp-report_file_test.xml`.
Expand Down
14 changes: 10 additions & 4 deletions lib/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ defmodule JUnitFormatter do
:ok = File.mkdir_p(report_dir())
end

# Merge default properties with custom properties from configuration
default_properties = %{
seed: opts[:seed],
date: DateTime.to_iso8601(DateTime.utc_now())
}

custom_properties = Application.get_env(:junit_formatter, :properties, %{})
all_properties = Map.merge(default_properties, custom_properties)

{:ok,
%__MODULE__{
properties: %{
seed: opts[:seed],
date: DateTime.to_iso8601(DateTime.utc_now())
}
properties: all_properties
}}
end

Expand Down