percy / percy-capybara

Visual testing for Capybara with Percy.
https://docs.percy.io/docs/capybara
MIT License
45 stars 23 forks source link

Assets missing with custom sprockets config #39

Closed fotinakis closed 5 years ago

fotinakis commented 7 years ago

With this config:

config.assets.paths << Rails.root.join(
  "vendor/assets/bower_components/app-assets/dist/assets/images").to_s

Then image is then correctly referenced like:

image_path('some-image.svg')

For some reason, the Percy resource URL ends up being:

/app-assets/dist/assets/images/some-image.svg

instead of:

/assets/images/some-image.svg

so the images are broken in percy.

We use ActionController::Base.helpers.asset_path (https://github.com/percy/percy-capybara/blob/v3.0.2/lib/percy/capybara/loaders/sprockets_loader.rb#L50) to find the asset path, perhaps it is wrong in this case?

akshayrawat commented 7 years ago

Sounds right. Let me know if you need help reproducing this. 👍

fotinakis commented 7 years ago

Temporarily fixed with custom loader workaround:

assets_dir = 'vendor/assets/bower_components/app-assets/dist/assets/images'

class CustomLoader < Percy::Capybara::Loaders::SprocketsLoader
  def build_resources
    resources = Percy::Capybara::Loaders::BaseLoader.new._resources_from_dir(
      assets_dir,
      base_url: '/assets',
    )
    super + resources
  end
end

# Then, in spec_helper.rb:
Percy::Capybara.use_loader(CustomLoader)
djones commented 5 years ago

I'm closing this issue as the new percy-capybara 4.x version does not use loaders and therefore avoids these issues 🎉

An upgrade guide from v3 to v4 is available for those interested in upgrading.