simplecov icon indicating copy to clipboard operation
simplecov copied to clipboard

feature: provide support to mount simplecov as engine

Open cmacduff opened this issue 3 years ago • 1 comments

I'd really like to serve the coverage report as a mounted Rails engine. The static files locally is a fine first step, but as the rails project gets bigger and bigger it gets impractical to run all test locally (see framesworks and test utilities). The only option right now seems to be to collate the report and then download the zip of that collation.

Instead of doing that I'd much rather setup my CD part to grab the reports CI create and serve it via the Rails app directly. Having it as a route in Rails would let me enforce authentication/authorizaion so it isn't available to the public. Being able to go to myapp.com/admin/simplecov seems much more straight forward and hassle free then download a zip and browsing to that file locally.

I think I can get this worked out as-is but it's going to be clunky. Poking around locally, I think this would work out:

  1. copy coverage/assets/* to public/assets/ and commit that
  2. use high_voltage to serve static html files (to achieve authentication), serves things out of app/views/pages
  3. collate the report in CI
  4. sed -i 's|./asset/|/asset|g' coverage/index.html # gets the index.html to use assets from public/assets from step 1.
  5. save coverage/index.html somewhere for CD to grab it and put it onto the nodes
  6. During CD, grab index.html and save to app/views/pages/

Steps 1, 2 and 4 rather bug me and seem fragile. It seems like I should be able to mount simplecov as an engine and tell it where to find the generated files.

cmacduff avatar Mar 31 '21 00:03 cmacduff

I haven’t tried this but could you mount a rack app in rails to handle serving the static files? You could then apply your authorisation scheme as you wanted.

Rails.application.routes.draw do
  ...
  mount Rack::Directory.new('coverage/') => '/admin/simplecov'
end

721p avatar Apr 21 '21 22:04 721p