zachallaun / mneme

Snapshot testing for Elixir
https://hex.pm/packages/mneme
95 stars 5 forks source link

Mneme overrides previously configured formatters, causing incompatibility with JUnitFormatter #87

Closed bvobart closed 4 weeks ago

bvobart commented 1 month ago

Hi :)

I want to use JUnitFormatter to produce JUnit-style XML reports of my test runs on CI, but I couldn't get it working. It's supposed to work by setting it as an ExUnit formatter, i.e. putting ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter]) in test_helper.exs before ExUnit.start()

However, I found that this conflicts with Mneme, as Mneme requires Mneme.start() after ExUnit.start() and, more problematically, overwrites any previously configured formatters, see https://github.com/zachallaun/mneme/blob/0b68247c910ad4402b08d74ce0ee287734b061f4/lib/mneme.ex#L411:

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

Could you fix this? I believe the fix would be as simple as retrieving any already configured formatters and then appending Mneme's formatter to that in this call to ExUnit.configure.

zachallaun commented 1 month ago

Thanks for the report! Yes, I can definitely get this resolved. I'll try to get it addressed either later today or this weekend. 🙂

zachallaun commented 1 month ago

@bvobart Would you mind trying out main and seeing if the issue is resolved?

{:mneme, github: "zachallaun/mneme", ref: "main", only: :test}
bvobart commented 4 weeks ago

Hi @zachallaun, great, thanks for the fix!! I've tested with main and the issue is indeed resolved: JUnitFormatter is now initialized and run properly! 🥳

Thanks for your work and I'm looking forward to the release so we can close this issue!

zachallaun commented 4 weeks ago

Thanks @bvobart!

Closed by 524ccc94879da473ffa8de0e669dc1734353a350, released as 0.9.1.