ChristianAlexander
Hi there!
Is there a way to include heex files in code coverage reporting? It appears that ~H sections within .ex files such as views and components are reported, but when the templates are in .html.heex files, they are not considered. This can lead to a situation where if statements exist within a template that is not fully exercised by tests, but 100% test coverage is “achieved”.
I also recognize that having many conditionals or branches in a template might be an anti-pattern, but sometimes it seems like a quick way to implement some functionality. Ideally, I could rely on code coverage metrics to ensure those branches are hit.
I’ve observed this behavior using the basic mix test --cover, as well as using ExCoveralls as the project’s test_coverage.tool, in case that helps!
I hope there’s just some configuration option that I’ve missed.
Thanks!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
thbar
I have the same question today ; the use case is as follows: I detected small errors introduced while migrating our templates to HEEX, and wanted to verify which heex files were ran through one test.
I will try to figure this out, but if you already managed to achieve that, I’m interested!
thbar
I have created an issue here Is it possible to include HEEX files in the coverage? · Issue #288 · parroty/excoveralls · GitHub to give this problem a bit more visibility, since it looks important from a maintenance point of view.
LostKobrakai
By my understanding
coverworks with modules. And templates are not modules, but external files converted into functions on a module. So I don’t think you can get line-by-line coverage for templates out of it. The other problem is thatcoverworks based on compiled.beamfiles for elixir and it’s still an erlang tool, so it’s completely unaware of macros and what they do. So coverage around macro’ed code can be rather strange.You could manually add lines like this to your view modules to get a per template coverage though:
That’s basically what phoenix generates for you, just explicitly defined for
coverto deal with functions not generated by a macro. That does also only help for code callingrender/2and notrender_template/2directly. Phoenix by default callsrender_template/2only fromrender/2andrender_templateis a private function, so it should be fine, but something to be aware of.You could probably even put the raising function head to be generated by a macro, so it’s automatically part of your view modules and therefore forces people to explicitly define
renderfunctions.nivanson
Keeping the template code in a render function and checking to see if functional components gets called will give you some idea of coverage. This is useful for complicated template logic.
See the difference when no functional components are used in the code branching.