lib/percy/capybara/loaders/native_loader.rb in percy-capybara-2.4.1 vs lib/percy/capybara/loaders/native_loader.rb in percy-capybara-2.4.2

- old
+ new

@@ -15,10 +15,16 @@ 'localhost', '127.0.0.1', '0.0.0.0', ].freeze + def initialize(options = {}) + super(options) + + @asset_hostnames = options[:asset_hostnames] || [] + end + def snapshot_resources resources = [] resources << root_html_resource resources += _get_css_resources resources += _get_image_resources @@ -75,11 +81,11 @@ next unless _should_include_url?(url) response = _fetch_resource_url(url) _absolute_url_to_relative!(url, _current_host_port) next unless response resources << Percy::Client::Resource.new( - url, mimetype: 'text/css', content: response.body + url, mimetype: 'text/css', content: response.body, ) end resources end private :_get_css_resources @@ -162,11 +168,11 @@ response = _fetch_resource_url(resource_url) _absolute_url_to_relative!(resource_url, _current_host_port) next unless response resources << Percy::Client::Resource.new( - resource_url, mimetype: response.content_type, content: response.body + resource_url, mimetype: response.content_type, content: response.body, ) end resources end private :_get_image_resources @@ -202,31 +208,38 @@ result = (url_match || PATH_REGEX.match(url)) && !data_url_match # Is not a remote URL. if url_match && !data_url_match host = url_match[2] - result = LOCAL_HOSTNAMES.include?(host) || _same_server?(url, _current_host_port) + result = asset_hostnames.include?(host) || _same_server?(url, _current_host_port) end !!result end # @private def _current_host_port url_match = URL_REGEX.match(page.current_url) url_match[1] + url_match[2] + (url_match[3] || '') end + private :_current_host_port # @private def _same_server?(url, host_port) url.start_with?(host_port + '/') || url == host_port end + private :_same_server? # @private def _absolute_url_to_relative!(url, host_port) url.gsub!(host_port + '/', '/') if url.start_with?(host_port + '/') end private :_absolute_url_to_relative! + + def asset_hostnames + LOCAL_HOSTNAMES + @asset_hostnames + end + private :asset_hostnames end end end end