victorolinasc / junit-formatter

A JUnit XML report exporter for Elixir's ExUnit
https://hexdocs.pm/junit_formatter/
Apache License 2.0
110 stars 37 forks source link

Umbrella application different file names #31

Closed axelson closed 6 years ago

axelson commented 6 years ago

In an umbrella application is it possible to have a report directory that is relative to the project root (i.e. not in a project-specific directory) but have each individual report file include the name of the project?

I'm not sure how since the junit formatter configuration appears to be global to the entire umbrella project, so it seems like I would need more dynamism within the junit configuration. For example if this worked:

config :junit_formatter,
  report_file: "test-junit-$APP.xml"

I can't just set a separate report file configuration per project because there is only one global configuration.

My specific problem is that I am trying to get junit formatter to work with bitbucket pipelines.

https://confluence.atlassian.com/bitbucket/test-reporting-in-pipelines-939708543.html

And the requirements are:

Since I need to over-write the default directory (since the default directory name does not match the required names) I need to over-write the file-name per project as well.

Any ideas on what to try? I'd be glad to add a PR to add additional functionality, just not sure what would be best. Perhaps the config could allow specifying a module that would support get_file_name/1?

victorolinasc commented 6 years ago

Ouch! That is a tricky one... I'll have to investigate. It seems like this is a somewhat common issue in umbrella, so even if we do support "test-junit-$APP.xml" the later one would overwrite the first one.

Example of same issue here.

This stems from this line in the root config:

import_config "../apps/*/config/config.exs"

Where all apps overwrite each other. Even this ugly HACK won't work:

unless Mix.Project.umbrella? do
  config :junit_formatter,
    report_file: Mix.Project.app_path() <> "_report_file_test.xml"
end

I'll have to dig deeper... sorry for not providing a workaround now =/ and thanks for bringing the issue. I'll take a look at it later.

axelson commented 6 years ago

Okay, thanks for beginning to look into it. Would be nice to get this all working nicely.

axelson commented 6 years ago

@victorolinasc any updates on this?

victorolinasc commented 6 years ago

Sorry for the delay @axelson. I've fixed this and pushed to hex versino 2.2.0. Please, see the changelog and the updated README for the new umbrella section.

Basically, I went with the easier way of adding an option of prepending the project name to the report file through a config switch. So, you add this now:

config :junit_formatter, 
  prepend_project_name?: true # defaults to false for backwards compatibility

Now the report will be generated like: _build/test/lib/my_app/my_app-report_file.xml.

Hope this helps and solves your issues. Now you can pass the report_dir config plus this one and you will have different files for each of your sub-projects. So, just update your dependency to 2.2.0 :)

axelson commented 6 years ago

That works great, thanks!