fxn/zeitwerk

Autoloaded files arent tracked by simplecov

faraaz-deepsource opened this issue · 3 comments

When I autoload a file using Zeitwerk it stops being tracked by simplecov. I created a repo with reproducible example this repo.

In the above repo, if you run the test with bundle exec rspec at the end it outputs

Coverage report generated for RSpec to <some_path>/experminents/zeitest/coverage. 0 / 0 LOC (100.0%) covered.

even though it does run the test (fails when I change the test expectation or method's return string).

However, in spec_helper.rb if I remove autoloading and manually require_relative the file to test(lib/main.rb), the file starts getting tracked again, as i can see the output:

Coverage report generated for RSpec to /Users/faraaz/experminents/zeitest/coverage. 3 / 3 LOC (100.0%) covered.

Is this a bug? Am I setting up something(simplecov) wrongly?

fxn commented

In that repository things happen in this order:

  1. Loads lib/autoloader.rb,
  2. which configures a loader,
  3. which is told to eager load,
  4. which eager loads lib/main.rb.
  5. SimpleCov.start is called.

As you see, by the time simplecov starts tracking, the file defining Main was already loaded.

If you remove loader.eager_load to lazy load Main, you'll see it is reported.

Yes that fixed it thank you so much! Should I add this to README of zeitwerk or simplecov incase someone else faces a similar issue?

fxn commented

@faraaz-deepsource certainly not here.

I don't know in SimpleCov's. To me, this seems more like an overlook. But you can ask them if you wish anyway.