percy-capybara 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b9ab13cdb41b837b527594bbe81b6558b62fc5e
|
4
|
+
data.tar.gz: 8a1cb46009774c52c868d8b14ef404b4d3d913a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 054078223dae7d409556cae8f308763e3552c5491e29e443a2411f928a23a5272e182e02c9c72b488eedf8f2b593b0830a2580ce7271ef15c4179a42a3f2a078
|
7
|
+
data.tar.gz: 8145c3640a24875a8c10907194a9839da7c3958f97700d6ab338d20aadb65c9e571a04905b583715da78555b072b0f07e7c39c6b73301c7273c28fc3359c49a9
|
@@ -7,6 +7,40 @@ module Percy
|
|
7
7
|
module Capybara
|
8
8
|
class Client
|
9
9
|
module Snapshots
|
10
|
+
# Modified version of Diego Perini's URL regex. https://gist.github.com/dperini/729294
|
11
|
+
URL_REGEX = Regexp.new(
|
12
|
+
# protocol identifier
|
13
|
+
"(?:(?:https?:)?//)" +
|
14
|
+
"(?:" +
|
15
|
+
# IP address exclusion
|
16
|
+
# private & local networks
|
17
|
+
"(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
|
18
|
+
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
|
19
|
+
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
|
20
|
+
# IP address dotted notation octets
|
21
|
+
# excludes loopback network 0.0.0.0
|
22
|
+
# excludes reserved space >= 224.0.0.0
|
23
|
+
# excludes network & broacast addresses
|
24
|
+
# (first & last IP address of each class)
|
25
|
+
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
26
|
+
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
27
|
+
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
28
|
+
"|" +
|
29
|
+
# host name
|
30
|
+
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
|
31
|
+
# domain name
|
32
|
+
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
|
33
|
+
# TLD identifier
|
34
|
+
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
35
|
+
")" +
|
36
|
+
# port number
|
37
|
+
"(?::\\d{2,5})?" +
|
38
|
+
# resource path
|
39
|
+
"(?:/[^\\s\"']*)?"
|
40
|
+
)
|
41
|
+
PATH_REGEX = /\/[^\\s\"']*/
|
42
|
+
DATA_URL_REGEX = /\Adata:/
|
43
|
+
|
10
44
|
# Takes a snapshot of the given page HTML and its assets.
|
11
45
|
#
|
12
46
|
# @param [Capybara::Session] page The Capybara page to snapshot.
|
@@ -100,12 +134,13 @@ module Percy
|
|
100
134
|
JS
|
101
135
|
resource_urls = _evaluate_script(page, script)
|
102
136
|
|
103
|
-
resource_urls.each do |
|
104
|
-
|
137
|
+
resource_urls.each do |url|
|
138
|
+
next if !_is_valid_url?(url)
|
139
|
+
response = _fetch_resource_url(url)
|
105
140
|
next if !response
|
106
141
|
sha = Digest::SHA256.hexdigest(response.body)
|
107
142
|
resources << Percy::Client::Resource.new(
|
108
|
-
|
143
|
+
url, mimetype: 'text/css', content: response.body)
|
109
144
|
end
|
110
145
|
resources
|
111
146
|
end
|
@@ -127,10 +162,8 @@ module Percy
|
|
127
162
|
srcs << temp_url.split(' ').first
|
128
163
|
end
|
129
164
|
|
130
|
-
srcs.each do |
|
131
|
-
|
132
|
-
next if src.match(/\Adata:/)
|
133
|
-
image_urls << src
|
165
|
+
srcs.each do |url|
|
166
|
+
image_urls << url
|
134
167
|
end
|
135
168
|
end
|
136
169
|
|
@@ -162,13 +195,18 @@ module Percy
|
|
162
195
|
temp_urls = raw_image_url.scan(/url\(["']?(.*?)["']?\)/)
|
163
196
|
# background-image can accept multiple url()s, so temp_urls is an array of URLs.
|
164
197
|
temp_urls.each do |temp_url|
|
165
|
-
|
166
|
-
|
167
|
-
image_urls << temp_url[0]
|
198
|
+
url = temp_url[0]
|
199
|
+
image_urls << url
|
168
200
|
end
|
169
201
|
end
|
170
202
|
|
171
203
|
image_urls.each do |image_url|
|
204
|
+
next if !_is_valid_url?(image_url)
|
205
|
+
|
206
|
+
# If url references are blank, browsers will often fill them with the current page's
|
207
|
+
# URL, which makes no sense and will never be renderable. Strip these.
|
208
|
+
next if image_url == page.current_url
|
209
|
+
|
172
210
|
# Make the resource URL absolute to the current page. If it is already absolute, this
|
173
211
|
# will have no effect.
|
174
212
|
resource_url = URI.join(page.current_url, image_url).to_s
|
@@ -189,6 +227,12 @@ module Percy
|
|
189
227
|
end
|
190
228
|
private :_get_image_resources
|
191
229
|
|
230
|
+
# @private
|
231
|
+
def _is_valid_url?(url)
|
232
|
+
# It is a URL or a path, but not a data URI.
|
233
|
+
(URL_REGEX.match(url) || PATH_REGEX.match(url)) && !DATA_URL_REGEX.match(url)
|
234
|
+
end
|
235
|
+
|
192
236
|
# @private
|
193
237
|
def _fetch_resource_url(url)
|
194
238
|
response = Percy::Capybara::HttpFetcher.fetch(url)
|
data/percy-capybara.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'percy-client', '>= 0.2.
|
21
|
+
spec.add_dependency 'percy-client', '>= 0.2.11'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -36,6 +36,12 @@
|
|
36
36
|
<h2>img srcset</h2>
|
37
37
|
<img width="200" src="/images/srcset-base.png" srcset="/images/srcset-first.png 200w, /images/srcset-second.png 400w">
|
38
38
|
|
39
|
+
<h2>blank image src (not included)</h2>
|
40
|
+
<img src=""></div>
|
41
|
+
|
42
|
+
<h2>empty background-image url (uses current page url, should not be included)</h2>
|
43
|
+
<div style="background: url() 200px 200px no-repeat"></div>
|
44
|
+
|
39
45
|
<h2>Duplicates of some of the above images, to verify they are not duplicated in resources:</h2>
|
40
46
|
<img src="images/img-relative.png">
|
41
47
|
<img src="/images/img-relative-to-root.png">
|
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: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: percy-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
19
|
+
version: 0.2.11
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.
|
26
|
+
version: 0.2.11
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
version: '0'
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.2.2
|
208
208
|
signing_key:
|
209
209
|
specification_version: 4
|
210
210
|
summary: Percy::Capybara
|