victorolinasc / junit-formatter

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

JUnitFormatter does not load and does not do anything when used together with Mneme #51

Closed bvobart closed 1 month ago

bvobart commented 3 months ago

Hi, I'm trying to use JUnitFormatter in my Elixir 1.17 project, so I followed the steps in the ReadMe, but I notice that no JUnit XML file is being produced, even after setting the relevant config options. I even set print_report_file: true, but I don't see anything about JUnit being printed. Even if I monkey-patch JUnitFormatter's init/1 to do an IO.puts("JUnitFormatter initialized") I do not see this being printed, which leads me to believe that for some reason, JUnitFormatter is not loading.

Here's the relevant parts from my mix.exs:

defmodule NLdoc.MixProject do
  use Mix.Project

  ...

  def test_coverage() do
    [
      # ignore modules generated by libraries that we use.
      ignore_modules: [
        ~r/NLdoc\.Validation\.Severity\..*/,
        ~r/Jason\.Encoder\..*/
      ],
      # TODO: increase eventually
      summary: [threshold: 75]
    ]
  end

  defp deps do
    [
      ...

      # Testing: mocking, snapshot testing, reporting
      {:mimic, "~> 1.7", only: :test},
      {:mneme, ">= 0.0.0", only: [:test]},
      {:junit_formatter, "~> 3.4", only: [:test]},

      ...
    ]
  end
end

My test/test_helper.exs:

Mimic.copy(NLdoc.Spec.Document)
Mimic.copy(NLdoc.Validation)

ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter])
ExUnit.start()
Mneme.start()

The JUnitFormatter config in my config.exs file:

if config_env() == :test do
  config :junit_formatter,
    automatic_create_dir?: true,
    include_filename?: true,
    include_file_line?: true,
    print_report_file: true,
    report_dir: Mix.Project.project_file() |> Path.dirname() |> Path.join("cover"),
    report_file: "junit.xml"
end

Is this a bug in JUnitFormatter or am I doing something wrong here?

bvobart commented 1 month ago

I just found something that indicates it could well be an interaction with Mneme. Apparently, Mneme.start() indirectly also calls ExUnit.configure, overriding the formatters option, thus also discarding the JUnitFormatter that I'm trying to configure:

    ExUnit.configure(
      formatters: [Mneme.Server.ExUnitFormatter],
      default_formatter: ExUnit.CLIFormatter,
      timeout: :infinity
    )

See https://github.com/zachallaun/mneme/blob/0b68247c910ad4402b08d74ce0ee287734b061f4/lib/mneme.ex#L411

EDIT: made an issue on Mneme's repo: https://github.com/zachallaun/mneme/issues/87

bvobart commented 1 month ago

This issue was indeed caused by an issue with Mneme versions 0.9.0 and below. A new version of Mneme will soon be released that fixes this.