percy-capybara 2.3.2 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/percy/capybara/client/snapshots.rb +8 -0
- data/lib/percy/capybara/loaders/native_loader.rb +21 -1
- data/lib/percy/capybara/version.rb +1 -1
- data/spec/lib/percy/capybara/client/snapshots_spec.rb +4 -0
- data/spec/lib/percy/capybara/client/testdata/test-localtest-me-images.html +8 -0
- data/spec/lib/percy/capybara/loaders/native_loader_spec.rb +65 -34
- data/spec/spec_helper.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5d969e6040123759001a610740fe46115eb5c8
|
4
|
+
data.tar.gz: 64345632abd3e80a2216bcd5f8b912be6c30718a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d876fa8b49fb2f66979cdaac78e7051ba294087f3747cf97cffc94240d48b8e503866d1ee9173cda6d4534cf3c4f6f12c4a1a42ebcfe4f180ae14708926ae73
|
7
|
+
data.tar.gz: 60be216d386341d9428a535406ba309116c086a5e1cc18e18b08218133fdcdd8f96f003f39dd4c857e5ffe1e1a1affb7066b9394934932a4b2d49f32f617c915
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -14,6 +14,14 @@ module Percy
|
|
14
14
|
def snapshot(page, options = {})
|
15
15
|
return if !enabled? # Silently skip if the client is disabled.
|
16
16
|
|
17
|
+
if current_build.nil?
|
18
|
+
raise RuntimeError.new(
|
19
|
+
'Whoops! Percy is enabled, but Percy::Capybara.initialize_build was never called. ' +
|
20
|
+
'Did you forget to setup Percy in your spec_helper.rb? ' +
|
21
|
+
'See: https://percy.io/docs/clients/ruby/capybara'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
17
25
|
loader = initialize_loader(page: page)
|
18
26
|
|
19
27
|
Percy.logger.debug { "Snapshot started (name: #{options[:name].inspect})" }
|
@@ -75,6 +75,7 @@ module Percy
|
|
75
75
|
resource_urls.each do |url|
|
76
76
|
next if !_should_include_url?(url)
|
77
77
|
response = _fetch_resource_url(url)
|
78
|
+
_absolute_url_to_relative!(url, _current_host_port)
|
78
79
|
next if !response
|
79
80
|
sha = Digest::SHA256.hexdigest(response.body)
|
80
81
|
resources << Percy::Client::Resource.new(
|
@@ -160,6 +161,7 @@ module Percy
|
|
160
161
|
# browser's cache. However, often these images are probably local resources served by a
|
161
162
|
# development server, so it may not be so bad. Re-evaluate if this becomes an issue.
|
162
163
|
response = _fetch_resource_url(resource_url)
|
164
|
+
_absolute_url_to_relative!(resource_url, _current_host_port)
|
163
165
|
next if !response
|
164
166
|
|
165
167
|
sha = Digest::SHA256.hexdigest(response.body)
|
@@ -202,11 +204,29 @@ module Percy
|
|
202
204
|
# Is not a remote URL.
|
203
205
|
if url_match && !data_url_match
|
204
206
|
host = url_match[2]
|
205
|
-
result = LOCAL_HOSTNAMES.include?(host)
|
207
|
+
result = LOCAL_HOSTNAMES.include?(host) || _same_server?(url, _current_host_port)
|
206
208
|
end
|
207
209
|
|
208
210
|
!!result
|
209
211
|
end
|
212
|
+
|
213
|
+
# @priivate
|
214
|
+
def _current_host_port
|
215
|
+
url_match = URL_REGEX.match(page.current_url)
|
216
|
+
host_port = url_match[1] + url_match[2] + (url_match[3] || '')
|
217
|
+
end
|
218
|
+
|
219
|
+
# @private
|
220
|
+
def _same_server?(url, host_port)
|
221
|
+
url.start_with?(host_port + "/") || url == host_port
|
222
|
+
end
|
223
|
+
|
224
|
+
# @private
|
225
|
+
def _absolute_url_to_relative!(url, host_port)
|
226
|
+
url.gsub!(host_port + '/','/') if url.start_with?(host_port + "/")
|
227
|
+
end
|
228
|
+
private :_absolute_url_to_relative!
|
229
|
+
|
210
230
|
end
|
211
231
|
end
|
212
232
|
end
|
@@ -65,6 +65,10 @@ RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
|
|
65
65
|
.and_call_original
|
66
66
|
expect(capybara_client.snapshot(page)).to eq(true)
|
67
67
|
end
|
68
|
+
it 'errors if build is not created' do
|
69
|
+
capybara_client = Percy::Capybara::Client.new(enabled: true)
|
70
|
+
expect { capybara_client.snapshot(page) }.to raise_error(RuntimeError)
|
71
|
+
end
|
68
72
|
it 'passes through options to the percy client if given' do
|
69
73
|
expect(capybara_client.client).to receive(:create_snapshot)
|
70
74
|
.with(anything, anything, {name: 'foo', widths: [320, 1024], enable_javascript: true})
|
@@ -1,5 +1,6 @@
|
|
1
1
|
RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
2
|
-
let(:
|
2
|
+
let(:fake_page) { OpenStruct.new(current_url: "http://localhost/foo")}
|
3
|
+
let(:loader) { described_class.new(page: fake_page) }
|
3
4
|
|
4
5
|
describe '#build_resources' do
|
5
6
|
it 'returns an empty list' do
|
@@ -15,37 +16,52 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
15
16
|
it 'returns the root HTML and CSS resources' do
|
16
17
|
visit '/test-css.html'
|
17
18
|
loader = described_class.new(page: page)
|
18
|
-
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
19
|
-
url.gsub(/localhost:\d+/, 'localhost')
|
20
|
-
end
|
19
|
+
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
21
20
|
expect(resource_urls).to match_array([
|
22
21
|
"/test-css.html",
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
22
|
+
"/css/base.css",
|
23
|
+
"/css/imports.css",
|
24
|
+
"/css/level0-imports.css",
|
25
|
+
"/css/level1-imports.css",
|
26
|
+
"/css/level2-imports.css",
|
27
|
+
"/css/simple-imports.css",
|
29
28
|
])
|
30
29
|
end
|
31
30
|
it 'returns the root HTML and image resources' do
|
32
31
|
visit '/test-images.html'
|
33
32
|
loader = described_class.new(page: page)
|
34
|
-
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
35
|
-
url.gsub(/localhost:\d+/, 'localhost')
|
36
|
-
end
|
33
|
+
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
37
34
|
expect(resource_urls).to match_array([
|
38
35
|
"/test-images.html",
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
36
|
+
"/images/img-relative.png",
|
37
|
+
"/images/img-relative-to-root.png",
|
38
|
+
"/images/percy.svg",
|
39
|
+
"/images/srcset-base.png",
|
40
|
+
"/images/srcset-first.png",
|
41
|
+
"/images/srcset-second.png",
|
42
|
+
"/images/bg-relative.png",
|
43
|
+
"/images/bg-relative-to-root.png",
|
44
|
+
"/images/bg-stacked.png"
|
45
|
+
])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
describe "nonlocal.me", type: :feature, js: true do
|
49
|
+
before :each do
|
50
|
+
@orig_app_host = Capybara.app_host
|
51
|
+
Capybara.app_host = Capybara.app_host.gsub('http://localhost:', 'http://localtest.me:')
|
52
|
+
end
|
53
|
+
after :each do
|
54
|
+
Capybara.app_host = @orig_app_host
|
55
|
+
end
|
56
|
+
it 'returns the root HTML and image resources' do
|
57
|
+
visit '/test-localtest-me-images.html'
|
58
|
+
loader = described_class.new(page: page)
|
59
|
+
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
60
|
+
expect(resource_urls).to eq([
|
61
|
+
"/test-localtest-me-images.html",
|
62
|
+
"/images/img-relative.png"
|
48
63
|
])
|
64
|
+
expect(loader.snapshot_resources.collect(&:is_root)).to eq([true,nil])
|
49
65
|
end
|
50
66
|
end
|
51
67
|
describe '#_should_include_url?' do
|
@@ -81,6 +97,23 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
81
97
|
expect(loader._should_include_url?('http://example.com/foo')).to eq(false)
|
82
98
|
expect(loader._should_include_url?('https://example.com/foo')).to eq(false)
|
83
99
|
end
|
100
|
+
context "for nonlocal hosts" do
|
101
|
+
let(:fake_page) { OpenStruct.new(current_url: "http://foo:123/") }
|
102
|
+
it "returns true for the same host port" do
|
103
|
+
expect(loader._should_include_url?('http://foo:123/')).to eq(true)
|
104
|
+
expect(loader._should_include_url?('http://foo:123/bar')).to eq(true)
|
105
|
+
end
|
106
|
+
it "returns false for different port" do
|
107
|
+
expect(loader._should_include_url?('http://foo/')).to eq(false)
|
108
|
+
expect(loader._should_include_url?('http://foo/bar')).to eq(false)
|
109
|
+
expect(loader._should_include_url?('http://foo:1234/')).to eq(false)
|
110
|
+
expect(loader._should_include_url?('http://foo:1234/bar')).to eq(false)
|
111
|
+
end
|
112
|
+
it "returns false for different host" do
|
113
|
+
expect(loader._should_include_url?('http://afoo:123/')).to eq(false)
|
114
|
+
expect(loader._should_include_url?('http://afoo:123/bar')).to eq(false)
|
115
|
+
end
|
116
|
+
end
|
84
117
|
end
|
85
118
|
describe '#_get_css_resources', type: :feature, js: true do
|
86
119
|
it 'includes all linked and imported stylesheets' do
|
@@ -204,19 +237,17 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
204
237
|
expect(Digest::SHA256.hexdigest(resource.content)).to eq(expected_sha)
|
205
238
|
expect(resource.sha).to eq(expected_sha)
|
206
239
|
|
207
|
-
resource_urls = resources.collect(&:resource_url)
|
208
|
-
url.gsub(/localhost:\d+/, 'localhost')
|
209
|
-
end
|
240
|
+
resource_urls = resources.collect(&:resource_url)
|
210
241
|
expect(resource_urls).to match_array([
|
211
|
-
"
|
212
|
-
"
|
213
|
-
"
|
214
|
-
"
|
215
|
-
"
|
216
|
-
"
|
217
|
-
"
|
218
|
-
"
|
219
|
-
"
|
242
|
+
"/images/img-relative.png",
|
243
|
+
"/images/img-relative-to-root.png",
|
244
|
+
"/images/percy.svg",
|
245
|
+
"/images/srcset-base.png",
|
246
|
+
"/images/srcset-first.png",
|
247
|
+
"/images/srcset-second.png",
|
248
|
+
"/images/bg-relative.png",
|
249
|
+
"/images/bg-relative-to-root.png",
|
250
|
+
"/images/bg-stacked.png"
|
220
251
|
])
|
221
252
|
expect(resources.collect(&:is_root).uniq).to match_array([nil])
|
222
253
|
end
|
data/spec/spec_helper.rb
CHANGED
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.3.
|
4
|
+
version: 2.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: percy-client
|
@@ -221,6 +221,7 @@ files:
|
|
221
221
|
- spec/lib/percy/capybara/client/testdata/test-css.html
|
222
222
|
- spec/lib/percy/capybara/client/testdata/test-iframe.html
|
223
223
|
- spec/lib/percy/capybara/client/testdata/test-images.html
|
224
|
+
- spec/lib/percy/capybara/client/testdata/test-localtest-me-images.html
|
224
225
|
- spec/lib/percy/capybara/client_spec.rb
|
225
226
|
- spec/lib/percy/capybara/httpfetcher_spec.rb
|
226
227
|
- spec/lib/percy/capybara/loaders/base_loader_spec.rb
|
@@ -249,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
250
|
version: '0'
|
250
251
|
requirements: []
|
251
252
|
rubyforge_project:
|
252
|
-
rubygems_version: 2.
|
253
|
+
rubygems_version: 2.4.8
|
253
254
|
signing_key:
|
254
255
|
specification_version: 4
|
255
256
|
summary: Percy::Capybara
|
@@ -283,6 +284,7 @@ test_files:
|
|
283
284
|
- spec/lib/percy/capybara/client/testdata/test-css.html
|
284
285
|
- spec/lib/percy/capybara/client/testdata/test-iframe.html
|
285
286
|
- spec/lib/percy/capybara/client/testdata/test-images.html
|
287
|
+
- spec/lib/percy/capybara/client/testdata/test-localtest-me-images.html
|
286
288
|
- spec/lib/percy/capybara/client_spec.rb
|
287
289
|
- spec/lib/percy/capybara/httpfetcher_spec.rb
|
288
290
|
- spec/lib/percy/capybara/loaders/base_loader_spec.rb
|