percy-capybara 2.4.1 → 2.4.2
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/.rubocop.yml +24 -3
- data/.rubocop_todo.yml +3 -15
- data/lib/percy/capybara/client/builds.rb +2 -2
- data/lib/percy/capybara/loaders/base_loader.rb +3 -3
- data/lib/percy/capybara/loaders/native_loader.rb +16 -3
- data/lib/percy/capybara/version.rb +1 -1
- data/spec/lib/percy/capybara/client/snapshots_spec.rb +1 -1
- data/spec/lib/percy/capybara/http_fetcher_spec.rb +1 -1
- data/spec/lib/percy/capybara/loaders/native_loader_spec.rb +69 -42
- data/spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f2c6b66630a9b989903633853eb47c1d74595a7
|
4
|
+
data.tar.gz: 1a747e278afafb60039383ec401c8d20b1cdb5f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e134b285b13d3fdf24a305a7f79a1701c8a2defa16e0105de781da019484d80e8a8390915fb6b579d4834bd3eddeefde3a254850a649760b23ed225d59f85f8
|
7
|
+
data.tar.gz: 519a72136a56740eaec3c8f7dbd56dbbc10eb0ebae3d5b145cc10025c89306e569b84a11c1da85ac904900d7471d3179cc5411cb7766b8a7ad789eddbb18e504
|
data/.rubocop.yml
CHANGED
@@ -5,9 +5,18 @@ AllCops:
|
|
5
5
|
- Rakefile
|
6
6
|
- lib/**/*.rake
|
7
7
|
|
8
|
+
Lint/EndAlignment:
|
9
|
+
EnforcedStyleAlignWith: variable
|
10
|
+
|
8
11
|
Metrics/LineLength:
|
9
12
|
Max: 100
|
10
13
|
|
14
|
+
Style/CaseIndentation:
|
15
|
+
EnforcedStyle: end
|
16
|
+
|
17
|
+
Style/AlignParameters:
|
18
|
+
EnforcedStyle: with_fixed_indentation
|
19
|
+
|
11
20
|
Style/Documentation:
|
12
21
|
Enabled: false
|
13
22
|
|
@@ -23,20 +32,32 @@ Style/MultilineMethodCallIndentation:
|
|
23
32
|
Style/MultilineOperationIndentation:
|
24
33
|
EnforcedStyle: indented
|
25
34
|
|
35
|
+
# Disable Style/NumericLiterals so numbers don't need underscores
|
36
|
+
Style/NumericLiterals:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Style/NumericPredicate:
|
40
|
+
EnforcedStyle: comparison
|
41
|
+
|
26
42
|
Style/RedundantBegin:
|
27
43
|
Enabled: false
|
28
44
|
|
45
|
+
Style/RegexpLiteral:
|
46
|
+
EnforcedStyle: slashes
|
47
|
+
AllowInnerSlashes: true
|
48
|
+
|
29
49
|
Style/SpaceInsideHashLiteralBraces:
|
30
50
|
EnforcedStyle: no_space
|
31
51
|
|
52
|
+
Style/TrailingCommaInArguments:
|
53
|
+
EnforcedStyleForMultiline: consistent_comma
|
54
|
+
|
32
55
|
Style/TrailingCommaInLiteral:
|
33
|
-
EnforcedStyleForMultiline:
|
56
|
+
EnforcedStyleForMultiline: consistent_comma
|
34
57
|
|
35
58
|
RSpec/MessageSpies:
|
36
59
|
EnforcedStyle: receive
|
37
60
|
|
38
|
-
|
39
|
-
|
40
61
|
# Will be able to do this in >= v1.11
|
41
62
|
# RSpec/DescribedClass:
|
42
63
|
# EnforcedStyle: explicit
|
data/.rubocop_todo.yml
CHANGED
@@ -13,12 +13,12 @@ Metrics/AbcSize:
|
|
13
13
|
# Offense count: 27
|
14
14
|
# Configuration parameters: CountComments, ExcludedMethods.
|
15
15
|
Metrics/BlockLength:
|
16
|
-
Max:
|
16
|
+
Max: 300
|
17
17
|
|
18
18
|
# Offense count: 1
|
19
19
|
# Configuration parameters: CountComments.
|
20
20
|
Metrics/ClassLength:
|
21
|
-
Max:
|
21
|
+
Max: 200
|
22
22
|
|
23
23
|
# Offense count: 5
|
24
24
|
Metrics/CyclomaticComplexity:
|
@@ -67,8 +67,7 @@ RSpec/MultipleExpectations:
|
|
67
67
|
# Offense count: 1
|
68
68
|
# Configuration parameters: Max.
|
69
69
|
RSpec/NestedGroups:
|
70
|
-
|
71
|
-
- 'spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb'
|
70
|
+
Enabled: false
|
72
71
|
|
73
72
|
# Offense count: 10
|
74
73
|
# Configuration parameters: IgnoreSymbolicNames.
|
@@ -81,17 +80,6 @@ RSpec/VerifiedDoubles:
|
|
81
80
|
- 'spec/lib/percy/capybara_spec.rb'
|
82
81
|
- 'spec/support/test_helpers.rb'
|
83
82
|
|
84
|
-
# Offense count: 4
|
85
|
-
# Cop supports --auto-correct.
|
86
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
87
|
-
# SupportedStyles: slashes, percent_r, mixed
|
88
|
-
Style/RegexpLiteral:
|
89
|
-
Exclude:
|
90
|
-
- 'lib/percy/capybara/loaders/native_loader.rb'
|
91
|
-
- 'spec/lib/percy/capybara/loaders/native_loader_spec.rb'
|
92
|
-
- 'spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb'
|
93
|
-
- 'spec/support/test_helpers.rb'
|
94
|
-
|
95
83
|
# Offense count: 1
|
96
84
|
Style/StructInheritance:
|
97
85
|
Exclude:
|
@@ -40,7 +40,7 @@ module Percy
|
|
40
40
|
return unless enabled? # Silently skip if the client is disabled.
|
41
41
|
unless build_initialized?
|
42
42
|
raise Percy::Capybara::Client::BuildNotInitializedError,
|
43
|
-
|
43
|
+
'Failed to finalize build because no build has been initialized.'
|
44
44
|
end
|
45
45
|
result = rescue_connection_failures do
|
46
46
|
client.finalize_build(current_build['data']['id'])
|
@@ -66,7 +66,7 @@ module Percy
|
|
66
66
|
resource = build_resources.find { |r| r.sha == sha }
|
67
67
|
content = resource.content || File.read(resource.path)
|
68
68
|
client.upload_resource(current_build['data']['id'], content)
|
69
|
-
if (i % 10)
|
69
|
+
if (i % 10) == 0
|
70
70
|
puts "[percy] Uploading #{i + 1} of #{new_build_resources.length} new resources..."
|
71
71
|
end
|
72
72
|
end
|
@@ -29,7 +29,7 @@ module Percy
|
|
29
29
|
# port number
|
30
30
|
'(:\\d{2,5})?' +
|
31
31
|
# resource path
|
32
|
-
"(/[^\\s\"']*)?"
|
32
|
+
"(/[^\\s\"']*)?",
|
33
33
|
)
|
34
34
|
|
35
35
|
attr_reader :page
|
@@ -50,7 +50,7 @@ module Percy
|
|
50
50
|
# @private
|
51
51
|
def root_html_resource
|
52
52
|
Percy::Client::Resource.new(
|
53
|
-
current_path, is_root: true, mimetype: 'text/html', content: page.html
|
53
|
+
current_path, is_root: true, mimetype: 'text/html', content: page.html,
|
54
54
|
)
|
55
55
|
end
|
56
56
|
|
@@ -92,7 +92,7 @@ module Percy
|
|
92
92
|
path,
|
93
93
|
content: content,
|
94
94
|
sha: sha,
|
95
|
-
mimetype: 'text/html'
|
95
|
+
mimetype: 'text/html',
|
96
96
|
)
|
97
97
|
end
|
98
98
|
end
|
@@ -17,6 +17,12 @@ module Percy
|
|
17
17
|
'0.0.0.0',
|
18
18
|
].freeze
|
19
19
|
|
20
|
+
def initialize(options = {})
|
21
|
+
super(options)
|
22
|
+
|
23
|
+
@asset_hostnames = options[:asset_hostnames] || []
|
24
|
+
end
|
25
|
+
|
20
26
|
def snapshot_resources
|
21
27
|
resources = []
|
22
28
|
resources << root_html_resource
|
@@ -77,7 +83,7 @@ module Percy
|
|
77
83
|
_absolute_url_to_relative!(url, _current_host_port)
|
78
84
|
next unless response
|
79
85
|
resources << Percy::Client::Resource.new(
|
80
|
-
url, mimetype: 'text/css', content: response.body
|
86
|
+
url, mimetype: 'text/css', content: response.body,
|
81
87
|
)
|
82
88
|
end
|
83
89
|
resources
|
@@ -164,7 +170,7 @@ module Percy
|
|
164
170
|
next unless response
|
165
171
|
|
166
172
|
resources << Percy::Client::Resource.new(
|
167
|
-
resource_url, mimetype: response.content_type, content: response.body
|
173
|
+
resource_url, mimetype: response.content_type, content: response.body,
|
168
174
|
)
|
169
175
|
end
|
170
176
|
resources
|
@@ -204,7 +210,7 @@ module Percy
|
|
204
210
|
# Is not a remote URL.
|
205
211
|
if url_match && !data_url_match
|
206
212
|
host = url_match[2]
|
207
|
-
result =
|
213
|
+
result = asset_hostnames.include?(host) || _same_server?(url, _current_host_port)
|
208
214
|
end
|
209
215
|
|
210
216
|
!!result
|
@@ -215,17 +221,24 @@ module Percy
|
|
215
221
|
url_match = URL_REGEX.match(page.current_url)
|
216
222
|
url_match[1] + url_match[2] + (url_match[3] || '')
|
217
223
|
end
|
224
|
+
private :_current_host_port
|
218
225
|
|
219
226
|
# @private
|
220
227
|
def _same_server?(url, host_port)
|
221
228
|
url.start_with?(host_port + '/') || url == host_port
|
222
229
|
end
|
230
|
+
private :_same_server?
|
223
231
|
|
224
232
|
# @private
|
225
233
|
def _absolute_url_to_relative!(url, host_port)
|
226
234
|
url.gsub!(host_port + '/', '/') if url.start_with?(host_port + '/')
|
227
235
|
end
|
228
236
|
private :_absolute_url_to_relative!
|
237
|
+
|
238
|
+
def asset_hostnames
|
239
|
+
LOCAL_HOSTNAMES + @asset_hostnames
|
240
|
+
end
|
241
|
+
private :asset_hostnames
|
229
242
|
end
|
230
243
|
end
|
231
244
|
end
|
@@ -76,7 +76,7 @@ RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
|
|
76
76
|
.and_call_original
|
77
77
|
|
78
78
|
result = capybara_client.snapshot(
|
79
|
-
page, name: 'foo', widths: [320, 1024], enable_javascript: true
|
79
|
+
page, name: 'foo', widths: [320, 1024], enable_javascript: true,
|
80
80
|
)
|
81
81
|
expect(result).to eq(true)
|
82
82
|
expect(capybara_client.failed?).to eq(false)
|
@@ -4,7 +4,7 @@ RSpec.describe Percy::Capybara::HttpFetcher do
|
|
4
4
|
|
5
5
|
# Slightly magical hash, just a SHA-256 sum of the image above.
|
6
6
|
expect(Digest::SHA256.hexdigest(response.body)).to eq(
|
7
|
-
'4beb51550bef8e9e30d37ea8c13658e99bb01722062f218185e419af5ad93e13'
|
7
|
+
'4beb51550bef8e9e30d37ea8c13658e99bb01722062f218185e419af5ad93e13',
|
8
8
|
)
|
9
9
|
expect(response.content_type).to eq('image/png')
|
10
10
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
2
2
|
let(:fake_page) { OpenStruct.new(current_url: 'http://localhost/foo') }
|
3
|
-
let(:
|
3
|
+
let(:asset_hostnames) { nil }
|
4
|
+
let(:loader) { described_class.new(page: fake_page, asset_hostnames: asset_hostnames) }
|
4
5
|
|
5
6
|
describe '#build_resources' do
|
6
7
|
it 'returns an empty list' do
|
@@ -17,32 +18,36 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
17
18
|
visit '/test-css.html'
|
18
19
|
loader = described_class.new(page: page)
|
19
20
|
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
20
|
-
expect(resource_urls).to match_array(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
expect(resource_urls).to match_array(
|
22
|
+
[
|
23
|
+
'/test-css.html',
|
24
|
+
'/css/base.css',
|
25
|
+
'/css/imports.css',
|
26
|
+
'/css/level0-imports.css',
|
27
|
+
'/css/level1-imports.css',
|
28
|
+
'/css/level2-imports.css',
|
29
|
+
'/css/simple-imports.css',
|
30
|
+
],
|
31
|
+
)
|
29
32
|
end
|
30
33
|
it 'returns the root HTML and image resources' do
|
31
34
|
visit '/test-images.html'
|
32
35
|
loader = described_class.new(page: page)
|
33
36
|
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
34
|
-
expect(resource_urls).to match_array(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
expect(resource_urls).to match_array(
|
38
|
+
[
|
39
|
+
'/test-images.html',
|
40
|
+
'/images/img-relative.png',
|
41
|
+
'/images/img-relative-to-root.png',
|
42
|
+
'/images/percy.svg',
|
43
|
+
'/images/srcset-base.png',
|
44
|
+
'/images/srcset-first.png',
|
45
|
+
'/images/srcset-second.png',
|
46
|
+
'/images/bg-relative.png',
|
47
|
+
'/images/bg-relative-to-root.png',
|
48
|
+
'/images/bg-stacked.png',
|
49
|
+
],
|
50
|
+
)
|
46
51
|
end
|
47
52
|
end
|
48
53
|
describe 'nonlocal.me', type: :feature, js: true do
|
@@ -57,10 +62,12 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
57
62
|
visit '/test-localtest-me-images.html'
|
58
63
|
loader = described_class.new(page: page)
|
59
64
|
resource_urls = loader.snapshot_resources.collect(&:resource_url)
|
60
|
-
expect(resource_urls).to eq(
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
expect(resource_urls).to eq(
|
66
|
+
[
|
67
|
+
'/test-localtest-me-images.html',
|
68
|
+
'/images/img-relative.png',
|
69
|
+
],
|
70
|
+
)
|
64
71
|
expect(loader.snapshot_resources.collect(&:is_root)).to eq([true, nil])
|
65
72
|
end
|
66
73
|
end
|
@@ -91,11 +98,29 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
91
98
|
it 'returns false for data URLs' do
|
92
99
|
expect(loader._should_include_url?('data:image/gif;base64,R0')).to eq(false)
|
93
100
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
|
102
|
+
context 'when loader is initialised with asset hostnames' do
|
103
|
+
let(:asset_hostnames) { ['dev.local'] }
|
104
|
+
context 'with the same port' do
|
105
|
+
it 'returns in accordance with asset_hostnames' do
|
106
|
+
expect(loader._should_include_url?('http://dev.local/')).to eq(true)
|
107
|
+
expect(loader._should_include_url?('http://dev.local/foo')).to eq(true)
|
108
|
+
|
109
|
+
expect(loader._should_include_url?('http://other.local/')).to eq(false)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
context 'with different port' do
|
113
|
+
it 'returns in accordance with asset_hostnames' do
|
114
|
+
expect(loader._should_include_url?('http://dev.local:4321/foo')).to eq(true)
|
115
|
+
expect(loader._should_include_url?('http://other.local:1234/foo')).to eq(false)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
context 'https' do
|
119
|
+
it 'returns in accordance with asset_hostnames' do
|
120
|
+
expect(loader._should_include_url?('https://dev.local/foo')).to eq(true)
|
121
|
+
expect(loader._should_include_url?('https://other.local/foo')).to eq(false)
|
122
|
+
end
|
123
|
+
end
|
99
124
|
end
|
100
125
|
context 'for nonlocal hosts' do
|
101
126
|
let(:fake_page) { OpenStruct.new(current_url: 'http://foo:123/') }
|
@@ -238,17 +263,19 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
|
|
238
263
|
expect(resource.sha).to eq(expected_sha)
|
239
264
|
|
240
265
|
resource_urls = resources.collect(&:resource_url)
|
241
|
-
expect(resource_urls).to match_array(
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
266
|
+
expect(resource_urls).to match_array(
|
267
|
+
[
|
268
|
+
'/images/img-relative.png',
|
269
|
+
'/images/img-relative-to-root.png',
|
270
|
+
'/images/percy.svg',
|
271
|
+
'/images/srcset-base.png',
|
272
|
+
'/images/srcset-first.png',
|
273
|
+
'/images/srcset-second.png',
|
274
|
+
'/images/bg-relative.png',
|
275
|
+
'/images/bg-relative-to-root.png',
|
276
|
+
'/images/bg-stacked.png',
|
277
|
+
],
|
278
|
+
)
|
252
279
|
expect(resources.collect(&:is_root).uniq).to match_array([nil])
|
253
280
|
end
|
254
281
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -62,9 +62,11 @@ RSpec.configure do |config|
|
|
62
62
|
|
63
63
|
# Note: using this form of popen to keep stdout and stderr silent and captured.
|
64
64
|
dir = File.expand_path('../lib/percy/capybara/client/testdata/', __FILE__)
|
65
|
-
@process = IO.popen(
|
66
|
-
|
67
|
-
|
65
|
+
@process = IO.popen(
|
66
|
+
[
|
67
|
+
'ruby', '-run', '-e', 'httpd', dir, '-p', port.to_s, err: [:child, :out],
|
68
|
+
].flatten,
|
69
|
+
)
|
68
70
|
|
69
71
|
# Block until the server is up.
|
70
72
|
WebMock.disable_net_connect!(allow_localhost: true)
|
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.2
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: percy-client
|