Skip to content

Instantly share code, notes, and snippets.

@WMahoney09
Created March 1, 2017 20:08
Show Gist options
  • Save WMahoney09/238c7f0df68f84a85db0dd78074809c5 to your computer and use it in GitHub Desktop.
Save WMahoney09/238c7f0df68f84a85db0dd78074809c5 to your computer and use it in GitHub Desktop.
Custom Loader for Percy
require 'percy/capybara/loaders/sprockets_loader'
require 'digest'
require 'find'
class CustomLoader < Percy::Capybara::Loaders::SprocketsLoader
def build_resources
resources = []
# resource_url = "http://king.dev.imsdev.io/assets/css/app.min.css"
public_path = "#{Dir.pwd}/features/root"
Find.find(public_path).each do |path|
# Skip directories.
next if !FileTest.file?(path)
# Skip certain extensions.
next if SKIP_RESOURCE_EXTENSIONS.include?(File.extname(path))
# # Skip large files, these are hopefully downloads and not used in page rendering.
next if File.size(path) > MAX_FILESIZE_BYTES
# Strip the public_path from the beginning of the resource_url.
# This assumes that everything in the public_path directory is served at the root
# of the app.
resource_url = path.sub(public_path, '')
sha = Digest::SHA256.hexdigest(File.read(path))
resources << Percy::Client::Resource.new(resource_url, sha: sha, path: path)
end
resources
end
end
unless $is_windows
Percy::Capybara.use_loader(CustomLoader)
Percy::Capybara.initialize_build
at_exit { Percy::Capybara.finalize_build }
end
@fotinakis
Copy link

fotinakis commented Mar 1, 2017

Try:

require 'percy/capybara'

unless $is_windows
  Percy::Capybara.use_loader(:filesystem, assets_dir: "#{Dir.pwd}/features/root")
  Percy::Capybara.initialize_build
  at_exit  { Percy::Capybara.finalize_build }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment