Created
March 1, 2017 20:08
-
-
Save WMahoney09/238c7f0df68f84a85db0dd78074809c5 to your computer and use it in GitHub Desktop.
Custom Loader for Percy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try: