diff --git a/README.md b/README.md index cc5d940..77ca840 100644 --- a/README.md +++ b/README.md @@ -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 `` section. These properties will be merged with the default properties (seed and date). Example configuration: @@ -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`. diff --git a/lib/formatter.ex b/lib/formatter.ex index 7483d8d..037e395 100644 --- a/lib/formatter.ex +++ b/lib/formatter.ex @@ -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