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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 081b5260631b9369dc527a54f3645002493bf642
4
- data.tar.gz: 39f8bb11b13526dee9f3b79ab6539434316a4210
3
+ metadata.gz: 4e5d969e6040123759001a610740fe46115eb5c8
4
+ data.tar.gz: 64345632abd3e80a2216bcd5f8b912be6c30718a
5
5
  SHA512:
6
- metadata.gz: 44f8f17998d28fbccf9a738b9902d72e06647d4454e76646d3ace5fe3a482df0edd912d8784cfecf6272226222afbc958682efe845df2da72151a72c79b16ca4
7
- data.tar.gz: 012a9b6fcec664d54893f74fc8dedac59f14723a126cf1b66a5b51aa7f3552b96ede8bbf64bc3483fc8546e69da957999c8e984f38a069899a23e589b914b758
6
+ metadata.gz: 4d876fa8b49fb2f66979cdaac78e7051ba294087f3747cf97cffc94240d48b8e503866d1ee9173cda6d4534cf3c4f6f12c4a1a42ebcfe4f180ae14708926ae73
7
+ data.tar.gz: 60be216d386341d9428a535406ba309116c086a5e1cc18e18b08218133fdcdd8f96f003f39dd4c857e5ffe1e1a1affb7066b9394934932a4b2d49f32f617c915
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.rbc
14
14
  mkmf.log
15
15
  .DS_Store
16
+ Gemfile.lock
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- percy-capybara (2.3.2)
4
+ percy-capybara (2.3.3)
5
5
  percy-client (~> 1.9)
6
6
 
7
7
  GEM
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Capybara
3
- VERSION = '2.3.2'
3
+ VERSION = '2.3.3'
4
4
  end
5
5
  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})
@@ -0,0 +1,8 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <title>Test Percy::Capybara</title>
4
+ <h1>Test images</h1>
5
+
6
+ <h2>img local PNG (relative)</h2>
7
+ <img src="/images/img-relative.png"></img>
8
+ </html>
@@ -1,5 +1,6 @@
1
1
  RSpec.describe Percy::Capybara::Loaders::NativeLoader do
2
- let(:loader) { described_class.new(page: nil) }
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).map do |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
- "http://localhost/css/base.css",
24
- "http://localhost/css/imports.css",
25
- "http://localhost/css/level0-imports.css",
26
- "http://localhost/css/level1-imports.css",
27
- "http://localhost/css/level2-imports.css",
28
- "http://localhost/css/simple-imports.css",
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).map do |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
- "http://localhost/images/img-relative.png",
40
- "http://localhost/images/img-relative-to-root.png",
41
- "http://localhost/images/percy.svg",
42
- "http://localhost/images/srcset-base.png",
43
- "http://localhost/images/srcset-first.png",
44
- "http://localhost/images/srcset-second.png",
45
- "http://localhost/images/bg-relative.png",
46
- "http://localhost/images/bg-relative-to-root.png",
47
- "http://localhost/images/bg-stacked.png"
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).map do |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
- "http://localhost/images/img-relative.png",
212
- "http://localhost/images/img-relative-to-root.png",
213
- "http://localhost/images/percy.svg",
214
- "http://localhost/images/srcset-base.png",
215
- "http://localhost/images/srcset-first.png",
216
- "http://localhost/images/srcset-second.png",
217
- "http://localhost/images/bg-relative.png",
218
- "http://localhost/images/bg-relative-to-root.png",
219
- "http://localhost/images/bg-stacked.png"
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
@@ -7,6 +7,7 @@ require 'percy/capybara'
7
7
 
8
8
  Capybara::Webkit.configure do |config|
9
9
  # config.allow_url("*")
10
+ config.allow_url('localtest.me')
10
11
  config.block_unknown_urls
11
12
  end
12
13
 
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.2
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-01 00:00:00.000000000 Z
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.6.7
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