percy-capybara 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/percy/capybara/loaders/native_loader.rb +67 -25
- data/lib/percy/capybara/version.rb +1 -1
- data/spec/lib/percy/capybara/client/testdata/css/font.css +8 -0
- data/spec/lib/percy/capybara/client/testdata/test-font.html +9 -0
- data/spec/lib/percy/capybara/loaders/filesystem_loader_spec.rb +6 -2
- data/spec/lib/percy/capybara/loaders/native_loader_spec.rb +13 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b682acae89bc22e76727f90e4a8eacc13cb06f3
|
4
|
+
data.tar.gz: 6fddf05fddf696bda096ab56533c195412fc8216
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6996c928ef1e601e55b9e48266af607a18d8a9041a927a2ffcebb42d2511fb6b6f70addaf48c5f2a720710a9f1154f7d5e28c0994969120f0c8fce49727486
|
7
|
+
data.tar.gz: 121acaf58a0d651e5f14dd7983885b34847431ddde44417f7eee93746c21a6335e2c35f4ccb44f030ace83cdc3b6f235aa203b032828b7fc792b49d75d82b562
|
@@ -8,7 +8,7 @@ module Percy
|
|
8
8
|
# Resource loader that uses the native Capybara browser interface to discover resources.
|
9
9
|
# This loader uses JavaScript to discover page resources, so specs must be tagged with
|
10
10
|
# "js: true" because the default Rack::Test driver does not support executing JavaScript.
|
11
|
-
class NativeLoader < BaseLoader
|
11
|
+
class NativeLoader < BaseLoader # rubocop:disable ClassLength
|
12
12
|
PATH_REGEX = /\A\/[^\\s\"']*/
|
13
13
|
DATA_URL_REGEX = /\Adata:/
|
14
14
|
LOCAL_HOSTNAMES = [
|
@@ -21,6 +21,8 @@ module Percy
|
|
21
21
|
super(options)
|
22
22
|
|
23
23
|
@asset_hostnames = options[:asset_hostnames] || []
|
24
|
+
@assets_from_stylesheets = options[:include_assets_from_stylesheets] || :all
|
25
|
+
@assets_from_stylesheets = ->(_) { true } if @assets_from_stylesheets == :all
|
24
26
|
end
|
25
27
|
|
26
28
|
def snapshot_resources
|
@@ -76,16 +78,19 @@ module Percy
|
|
76
78
|
return css_urls;
|
77
79
|
JS
|
78
80
|
resource_urls = _evaluate_script(page, script)
|
81
|
+
urls_referred_by_css = []
|
79
82
|
|
80
83
|
resource_urls.each do |url|
|
81
84
|
next unless _should_include_url?(url)
|
82
85
|
response = _fetch_resource_url(url)
|
86
|
+
urls_referred_by_css.concat(_parse_urls_from_css(response.body))
|
83
87
|
_absolute_url_to_relative!(url, _current_host_port)
|
84
88
|
next unless response
|
85
89
|
resources << Percy::Client::Resource.new(
|
86
90
|
url, mimetype: 'text/css', content: response.body,
|
87
91
|
)
|
88
92
|
end
|
93
|
+
@urls_referred_by_css = urls_referred_by_css
|
89
94
|
resources
|
90
95
|
end
|
91
96
|
private :_get_css_resources
|
@@ -111,30 +116,7 @@ module Percy
|
|
111
116
|
end
|
112
117
|
end
|
113
118
|
|
114
|
-
|
115
|
-
script = <<-JS
|
116
|
-
var raw_image_urls = [];
|
117
|
-
|
118
|
-
var tags = document.getElementsByTagName('*');
|
119
|
-
var el;
|
120
|
-
var rawValue;
|
121
|
-
|
122
|
-
for (var i = 0; i < tags.length; i++) {
|
123
|
-
el = tags[i];
|
124
|
-
if (el.currentStyle) {
|
125
|
-
rawValue = el.currentStyle['backgroundImage'];
|
126
|
-
} else if (window.getComputedStyle) {
|
127
|
-
rawValue = window.getComputedStyle(el).getPropertyValue('background-image');
|
128
|
-
}
|
129
|
-
if (!rawValue || rawValue === "none") {
|
130
|
-
continue;
|
131
|
-
} else {
|
132
|
-
raw_image_urls.push(rawValue);
|
133
|
-
}
|
134
|
-
}
|
135
|
-
return raw_image_urls;
|
136
|
-
JS
|
137
|
-
raw_image_urls = _evaluate_script(page, script)
|
119
|
+
raw_image_urls = _evaluate_script(page, _find_all_css_loaded_background_image_js)
|
138
120
|
raw_image_urls.each do |raw_image_url|
|
139
121
|
temp_urls = raw_image_url.scan(/url\(["']?(.*?)["']?\)/)
|
140
122
|
# background-image can accept multiple url()s, so temp_urls is an array of URLs.
|
@@ -144,6 +126,10 @@ module Percy
|
|
144
126
|
end
|
145
127
|
end
|
146
128
|
|
129
|
+
if @assets_from_stylesheets && @assets_from_stylesheets != :none
|
130
|
+
image_urls.merge(@urls_referred_by_css.select { |path| @assets_from_stylesheets[path] })
|
131
|
+
end
|
132
|
+
|
147
133
|
image_urls.each do |image_url|
|
148
134
|
# If url references are blank, browsers will often fill them with the current page's
|
149
135
|
# URL, which makes no sense and will never be renderable. Strip these.
|
@@ -177,6 +163,62 @@ module Percy
|
|
177
163
|
end
|
178
164
|
private :_get_image_resources
|
179
165
|
|
166
|
+
# @private
|
167
|
+
def _find_all_css_loaded_background_image_js
|
168
|
+
<<-JS
|
169
|
+
var raw_image_urls = [];
|
170
|
+
|
171
|
+
var tags = document.getElementsByTagName('*');
|
172
|
+
var el;
|
173
|
+
var rawValue;
|
174
|
+
|
175
|
+
for (var i = 0; i < tags.length; i++) {
|
176
|
+
el = tags[i];
|
177
|
+
if (el.currentStyle) {
|
178
|
+
rawValue = el.currentStyle['backgroundImage'];
|
179
|
+
} else if (window.getComputedStyle) {
|
180
|
+
rawValue = window.getComputedStyle(el).getPropertyValue('background-image');
|
181
|
+
}
|
182
|
+
if (!rawValue || rawValue === "none") {
|
183
|
+
continue;
|
184
|
+
} else {
|
185
|
+
raw_image_urls.push(rawValue);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
return raw_image_urls;
|
189
|
+
JS
|
190
|
+
end
|
191
|
+
|
192
|
+
# @private
|
193
|
+
def _parse_urls_from_css(css_content)
|
194
|
+
css_content.scan(/url\(([^\)]+)\)/)
|
195
|
+
.map { |i| _remove_quotes(i.first) }
|
196
|
+
.select { |path| _should_include_url?(path) }
|
197
|
+
.map { |path| _remove_hash_from_url(path) }
|
198
|
+
end
|
199
|
+
|
200
|
+
# @private
|
201
|
+
def _remove_hash_from_url(string)
|
202
|
+
if /^(?<url_base>.+)?\#[^#]+$/ =~ string
|
203
|
+
if url_base.end_with?('?')
|
204
|
+
url_base[0...-1]
|
205
|
+
else
|
206
|
+
url_base
|
207
|
+
end
|
208
|
+
else
|
209
|
+
string
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# @private
|
214
|
+
def _remove_quotes(string)
|
215
|
+
if string.length >= 2 && (string[0] == string[-1]) && ['"', "'"].include?(string[0])
|
216
|
+
string[1...-1]
|
217
|
+
else
|
218
|
+
string
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
180
222
|
# @private
|
181
223
|
def _fetch_resource_url(url)
|
182
224
|
response = Percy::Capybara::HttpFetcher.fetch(url)
|
@@ -49,6 +49,7 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
|
|
49
49
|
'/assets/css/digested-f3420c6aee71c137a3ca39727052811ba' \
|
50
50
|
'e84b2f37d898f4db242e20656a1579e.css',
|
51
51
|
'/css/base.css',
|
52
|
+
'/css/font.css',
|
52
53
|
'/css/digested.css',
|
53
54
|
'/css/imports.css',
|
54
55
|
'/css/level0-imports.css',
|
@@ -69,11 +70,12 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
|
|
69
70
|
'/js/base.js',
|
70
71
|
'/public/percy-from-public.svg',
|
71
72
|
'/test-css.html',
|
73
|
+
'/test-font.html',
|
72
74
|
'/test-iframe.html',
|
73
75
|
'/test-images.html',
|
74
76
|
'/test-localtest-me-images.html',
|
75
77
|
]
|
76
|
-
expect(actual_paths).to
|
78
|
+
expect(actual_paths).to match_array(expected_paths)
|
77
79
|
|
78
80
|
expected_urls = loader.build_resources.collect(&:resource_url)
|
79
81
|
actual_urls = [
|
@@ -86,6 +88,7 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
|
|
86
88
|
'/url-prefix/css/level1-imports.css',
|
87
89
|
'/url-prefix/css/level2-imports.css',
|
88
90
|
'/url-prefix/css/simple-imports.css',
|
91
|
+
'/url-prefix/css/font.css',
|
89
92
|
'/url-prefix/iframe.html',
|
90
93
|
'/url-prefix/images/bg-relative-to-root.png',
|
91
94
|
'/url-prefix/images/bg-relative.png',
|
@@ -100,11 +103,12 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
|
|
100
103
|
'/url-prefix/js/base.js',
|
101
104
|
'/url-prefix/public/percy-from-public.svg',
|
102
105
|
'/url-prefix/test-css.html',
|
106
|
+
'/url-prefix/test-font.html',
|
103
107
|
'/url-prefix/test-iframe.html',
|
104
108
|
'/url-prefix/test-images.html',
|
105
109
|
'/url-prefix/test-localtest-me-images.html',
|
106
110
|
]
|
107
|
-
expect(actual_urls).to
|
111
|
+
expect(actual_urls).to match_array(expected_urls)
|
108
112
|
end
|
109
113
|
end
|
110
114
|
context 'assets_dir with only skippable resources' do
|
@@ -30,6 +30,18 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
30
30
|
],
|
31
31
|
)
|
32
32
|
end
|
33
|
+
it 'returns the font resources' do
|
34
|
+
visit '/test-font.html'
|
35
|
+
loader = described_class.new(page: page)
|
36
|
+
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
37
|
+
expect(resource_urls).to match_array(
|
38
|
+
[
|
39
|
+
'/test-font.html',
|
40
|
+
'/css/font.css',
|
41
|
+
'/assets/bootstrap/glyphicons-halflings-regular-13634da.eot',
|
42
|
+
],
|
43
|
+
)
|
44
|
+
end
|
33
45
|
it 'returns the root HTML and image resources' do
|
34
46
|
visit '/test-images.html'
|
35
47
|
loader = described_class.new(page: page)
|
@@ -184,6 +196,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
184
196
|
visit '/test-images.html'
|
185
197
|
|
186
198
|
loader = described_class.new(page: page)
|
199
|
+
loader.instance_variable_set(:@urls_referred_by_css, [])
|
187
200
|
resources = loader.send(:_get_image_resources)
|
188
201
|
|
189
202
|
# The order of these is just for convenience, they match the order in test-images.html.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: percy-client
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- spec/lib/percy/capybara/client/testdata/assets/images/large-file-skipped.png
|
208
208
|
- spec/lib/percy/capybara/client/testdata/css/base.css
|
209
209
|
- spec/lib/percy/capybara/client/testdata/css/digested.css
|
210
|
+
- spec/lib/percy/capybara/client/testdata/css/font.css
|
210
211
|
- spec/lib/percy/capybara/client/testdata/css/imports.css
|
211
212
|
- spec/lib/percy/capybara/client/testdata/css/level0-imports.css
|
212
213
|
- spec/lib/percy/capybara/client/testdata/css/level1-imports.css
|
@@ -228,6 +229,7 @@ files:
|
|
228
229
|
- spec/lib/percy/capybara/client/testdata/public/large-file-skipped.png
|
229
230
|
- spec/lib/percy/capybara/client/testdata/public/percy-from-public.svg
|
230
231
|
- spec/lib/percy/capybara/client/testdata/test-css.html
|
232
|
+
- spec/lib/percy/capybara/client/testdata/test-font.html
|
231
233
|
- spec/lib/percy/capybara/client/testdata/test-iframe.html
|
232
234
|
- spec/lib/percy/capybara/client/testdata/test-images.html
|
233
235
|
- spec/lib/percy/capybara/client/testdata/test-localtest-me-images.html
|
@@ -260,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
262
|
version: '0'
|
261
263
|
requirements: []
|
262
264
|
rubyforge_project:
|
263
|
-
rubygems_version: 2.
|
265
|
+
rubygems_version: 2.4.8
|
264
266
|
signing_key:
|
265
267
|
specification_version: 4
|
266
268
|
summary: Percy::Capybara
|
@@ -271,6 +273,7 @@ test_files:
|
|
271
273
|
- spec/lib/percy/capybara/client/testdata/assets/images/large-file-skipped.png
|
272
274
|
- spec/lib/percy/capybara/client/testdata/css/base.css
|
273
275
|
- spec/lib/percy/capybara/client/testdata/css/digested.css
|
276
|
+
- spec/lib/percy/capybara/client/testdata/css/font.css
|
274
277
|
- spec/lib/percy/capybara/client/testdata/css/imports.css
|
275
278
|
- spec/lib/percy/capybara/client/testdata/css/level0-imports.css
|
276
279
|
- spec/lib/percy/capybara/client/testdata/css/level1-imports.css
|
@@ -292,6 +295,7 @@ test_files:
|
|
292
295
|
- spec/lib/percy/capybara/client/testdata/public/large-file-skipped.png
|
293
296
|
- spec/lib/percy/capybara/client/testdata/public/percy-from-public.svg
|
294
297
|
- spec/lib/percy/capybara/client/testdata/test-css.html
|
298
|
+
- spec/lib/percy/capybara/client/testdata/test-font.html
|
295
299
|
- spec/lib/percy/capybara/client/testdata/test-iframe.html
|
296
300
|
- spec/lib/percy/capybara/client/testdata/test-images.html
|
297
301
|
- spec/lib/percy/capybara/client/testdata/test-localtest-me-images.html
|