percy-capybara 3.2.0 → 4.0.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +39 -0
  3. data/.gitignore +1 -0
  4. data/DEVELOPING.md +26 -0
  5. data/README.md +2 -2
  6. data/lib/environment.rb +31 -0
  7. data/lib/percy.rb +119 -0
  8. data/lib/version.rb +3 -0
  9. data/package-lock.json +2155 -0
  10. data/package.json +6 -0
  11. data/percy-capybara.gemspec +3 -12
  12. data/spec/lib/percy/environment_spec.rb +31 -0
  13. data/spec/lib/percy/percy_spec.rb +55 -0
  14. data/spec/spec_helper.rb +4 -44
  15. metadata +17 -233
  16. data/.travis.yml +0 -17
  17. data/lib/percy/capybara.rb +0 -60
  18. data/lib/percy/capybara/anywhere.rb +0 -37
  19. data/lib/percy/capybara/client.rb +0 -127
  20. data/lib/percy/capybara/client/builds.rb +0 -81
  21. data/lib/percy/capybara/client/snapshots.rb +0 -66
  22. data/lib/percy/capybara/client/user_agent.rb +0 -37
  23. data/lib/percy/capybara/httpfetcher.rb +0 -36
  24. data/lib/percy/capybara/loaders/base_loader.rb +0 -161
  25. data/lib/percy/capybara/loaders/ember_cli_rails_loader.rb +0 -52
  26. data/lib/percy/capybara/loaders/filesystem_loader.rb +0 -37
  27. data/lib/percy/capybara/loaders/native_loader.rb +0 -287
  28. data/lib/percy/capybara/loaders/sprockets_loader.rb +0 -99
  29. data/lib/percy/capybara/rspec.rb +0 -8
  30. data/lib/percy/capybara/version.rb +0 -5
  31. data/spec/lib/percy/capybara/client/builds_spec.rb +0 -171
  32. data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/admin/assets/percy-admin.svg +0 -34
  33. data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/admin/index.html +0 -1
  34. data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/admin/percy-admin-public.svg +0 -34
  35. data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/assets/percy-frontend.svg +0 -34
  36. data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/index.html +0 -1
  37. data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/percy-frontend-public.svg +0 -34
  38. data/spec/lib/percy/capybara/client/rails_public_test_data/large-file-skipped.png +0 -0
  39. data/spec/lib/percy/capybara/client/rails_public_test_data/percy-from-public.svg +0 -34
  40. data/spec/lib/percy/capybara/client/rails_public_test_data/symlink_to_images +0 -1
  41. data/spec/lib/percy/capybara/client/snapshots_spec.rb +0 -97
  42. data/spec/lib/percy/capybara/client/symlink_test_data/test.png +0 -0
  43. data/spec/lib/percy/capybara/client/test_data/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37d898f4db242e20656a1579e.css +0 -1
  44. data/spec/lib/percy/capybara/client/test_data/assets/images/large-file-skipped.png +0 -0
  45. data/spec/lib/percy/capybara/client/test_data/css/base.css +0 -1
  46. data/spec/lib/percy/capybara/client/test_data/css/digested.css +0 -1
  47. data/spec/lib/percy/capybara/client/test_data/css/font.css +0 -8
  48. data/spec/lib/percy/capybara/client/test_data/css/imports.css +0 -1
  49. data/spec/lib/percy/capybara/client/test_data/css/level0-imports.css +0 -2
  50. data/spec/lib/percy/capybara/client/test_data/css/level1-imports.css +0 -2
  51. data/spec/lib/percy/capybara/client/test_data/css/level2-imports.css +0 -1
  52. data/spec/lib/percy/capybara/client/test_data/css/simple-imports.css +0 -1
  53. data/spec/lib/percy/capybara/client/test_data/css/source.css.map +0 -2
  54. data/spec/lib/percy/capybara/client/test_data/iframe.html +0 -7
  55. data/spec/lib/percy/capybara/client/test_data/images/bg-relative-to-root.png +0 -0
  56. data/spec/lib/percy/capybara/client/test_data/images/bg-relative.png +0 -0
  57. data/spec/lib/percy/capybara/client/test_data/images/bg-stacked.png +0 -0
  58. data/spec/lib/percy/capybara/client/test_data/images/img-relative-to-root.png +0 -0
  59. data/spec/lib/percy/capybara/client/test_data/images/img-relative.png +0 -0
  60. data/spec/lib/percy/capybara/client/test_data/images/percy.svg +0 -34
  61. data/spec/lib/percy/capybara/client/test_data/images/srcset-base.png +0 -0
  62. data/spec/lib/percy/capybara/client/test_data/images/srcset-first.png +0 -0
  63. data/spec/lib/percy/capybara/client/test_data/images/srcset-second.png +0 -0
  64. data/spec/lib/percy/capybara/client/test_data/index.html +0 -1
  65. data/spec/lib/percy/capybara/client/test_data/js/base.js +0 -1
  66. data/spec/lib/percy/capybara/client/test_data/test-css.html +0 -20
  67. data/spec/lib/percy/capybara/client/test_data/test-font.html +0 -9
  68. data/spec/lib/percy/capybara/client/test_data/test-iframe.html +0 -8
  69. data/spec/lib/percy/capybara/client/test_data/test-images.html +0 -51
  70. data/spec/lib/percy/capybara/client/test_data/test-localtest-me-images.html +0 -8
  71. data/spec/lib/percy/capybara/client/user_agent_spec.rb +0 -45
  72. data/spec/lib/percy/capybara/client_spec.rb +0 -232
  73. data/spec/lib/percy/capybara/http_fetcher_spec.rb +0 -17
  74. data/spec/lib/percy/capybara/loaders/base_loader_spec.rb +0 -122
  75. data/spec/lib/percy/capybara/loaders/ember_cli_rails_loader_spec.rb +0 -86
  76. data/spec/lib/percy/capybara/loaders/filesystem_loader_spec.rb +0 -166
  77. data/spec/lib/percy/capybara/loaders/native_loader_spec.rb +0 -300
  78. data/spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb +0 -119
  79. data/spec/lib/percy/capybara_spec.rb +0 -101
  80. data/spec/support/test_helpers.rb +0 -60
@@ -1,119 +0,0 @@
1
- require 'sprockets'
2
-
3
- class SimpleRackApp
4
- def self.call(_env)
5
- [200, {}, 'Hello World']
6
- end
7
- end
8
-
9
- RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
10
- let(:test_data_path) do
11
- File.expand_path('../../client/test_data', __FILE__)
12
- end
13
- let(:rails_public_test_data_path) do
14
- File.expand_path('../../client/rails_public_test_data', __FILE__)
15
- end
16
- let(:loader) do
17
- Percy::Capybara::Loaders::SprocketsLoader.new(
18
- page: page,
19
- sprockets_environment: environment,
20
- sprockets_options: sprockets_options,
21
- )
22
- end
23
- let(:environment) do
24
- environment = Sprockets::Environment.new(test_data_path)
25
- environment.append_path '.'
26
- environment
27
- end
28
- let(:digest_enabled) { false }
29
- let(:sprockets_options) do
30
- options = double('options')
31
- # Set specific files we want to compile. In normal use, this would be all asset files.
32
- precompile_list = [/(?:\/|\\|\A)(base|digested)\.(css|js)$|\.map|\.png/]
33
- allow(options).to receive(:precompile).and_return(precompile_list)
34
- allow(options).to receive(:digest).and_return(digest_enabled)
35
- options
36
- end
37
-
38
- describe '#snapshot_resources' do
39
- context 'Rack::Test', type: :feature do
40
- before(:each) { Capybara.app = SimpleRackApp }
41
-
42
- it 'returns the root HTML resource' do
43
- visit '/'
44
- resources = loader.snapshot_resources
45
- expect(resources.map(&:resource_url)).to eq(['/'])
46
- expect(resources.first.is_root).to eq(true)
47
- expect(resources.first.content).to include('Hello World')
48
- end
49
- end
50
- context 'Capybara::Poltergeist', type: :feature, js: true do
51
- it 'returns the root HTML resource' do
52
- visit '/'
53
- resources = loader.snapshot_resources
54
- expect(resources.map(&:resource_url)).to eq(['/'])
55
- expect(resources.first.is_root).to eq(true)
56
- expect(resources.first.content).to include('Hello World!</body></html>')
57
- end
58
- end
59
- end
60
- describe '#build_resources', type: :feature do
61
- it 'returns "build resources" from filtered sprockets paths' do
62
- resources = loader.build_resources
63
- expected_resources = [
64
- '/assets/css/base.css',
65
- '/assets/css/digested.css',
66
- '/assets/images/bg-relative-to-root.png',
67
- '/assets/images/bg-relative.png',
68
- '/assets/images/bg-stacked.png',
69
- '/assets/images/img-relative-to-root.png',
70
- '/assets/images/img-relative.png',
71
- # '/assets/images/large-file-skipped.png', # Note: intentionally missing.
72
- '/assets/images/srcset-base.png',
73
- '/assets/images/srcset-first.png',
74
- '/assets/images/srcset-second.png',
75
- '/assets/js/base.js',
76
- ]
77
- expect(resources.map(&:resource_url)).to eq(expected_resources)
78
- expect(resources.first.content).to include('.colored-by-base')
79
- end
80
- context 'Rails app' do
81
- def setup_rails_double
82
- # Pretend like we're in a Rails app right now, all we care about is Rails.public_path.
83
- rails_double = double('Rails')
84
- # Pretend like the entire test_data directory is the public/ folder.
85
- expect(rails_double).to receive(:application).and_return(nil)
86
- expect(rails_double).to receive(:public_path).and_return(rails_public_test_data_path)
87
- expect(loader).to receive(:_rails).at_least(:once).and_return(rails_double)
88
- end
89
- it 'includes files from the public folder (non-asset-pipeline)' do
90
- setup_rails_double
91
- resources = loader.build_resources
92
- # Weak test that more things are in this list, because it merges asset pipeline with public.
93
- expect(resources.length).to be > 5
94
-
95
- resource_urls = resources.map(&:resource_url)
96
- expect(resource_urls).to include('/assets/images/bg-relative.png') # From asset pipeline.
97
- expect(resource_urls).to include('/percy-from-public.svg') # Public merged into root.
98
- expect(resource_urls).to include('/symlink_to_images/test.png') # Symlink in public dir.
99
- expect(resource_urls).to_not include('/large-file-skipped.png') # Public merged into root.
100
- end
101
- context 'digest enabled' do
102
- let(:digest_enabled) { true }
103
-
104
- it 'only includes pre-compiled, digested files once' do
105
- # This makes sure that we correctly merge already-compiled files in the assets directory
106
- # with ones from the asset pipeline. This means that Rails users who have
107
- # `config.assets.digest = true` set can safely run "rake assets:precompile" before tests.
108
- setup_rails_double
109
- resources = loader.build_resources
110
- expected_digest_url = \
111
- '/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37' \
112
- 'd898f4db242e20656a1579e.css'
113
- digested_resources = resources.select { |r| r.resource_url == expected_digest_url }
114
- expect(digested_resources.length).to eq(1)
115
- end
116
- end
117
- end
118
- end
119
- end
@@ -1,101 +0,0 @@
1
- RSpec.describe Percy::Capybara do
2
- before(:each) do
3
- Percy::Capybara.reset!
4
- @original_env = ENV['TRAVIS_BUILD_ID']
5
- ENV['TRAVIS_BUILD_ID'] = nil
6
- end
7
- after(:each) do
8
- ENV['TRAVIS_BUILD_ID'] = @original_env
9
- ENV.delete('PERCY_ENABLE')
10
- end
11
-
12
- describe '#capybara_client' do
13
- it 'returns the current client or creates a new one' do
14
- capybara_client = Percy::Capybara.capybara_client
15
- expect(capybara_client).to be
16
- # Verify that it memoizes the current object by calling it again:
17
- expect(Percy::Capybara.capybara_client).to eq(capybara_client)
18
- end
19
- end
20
- describe '#snapshot' do
21
- it 'passes all arguments through to the current capybara_client' do
22
- mock_page = double('page')
23
- capybara_client = Percy::Capybara.capybara_client
24
- expect(capybara_client).to receive(:snapshot).with(mock_page, {}).once
25
- Percy::Capybara.snapshot(mock_page)
26
- expect(capybara_client).to receive(:snapshot).with(mock_page, name: '/foo.html (modal)').once
27
- Percy::Capybara.snapshot(mock_page, name: '/foo.html (modal)')
28
- end
29
- it 'silently skips if disabled' do
30
- ENV['PERCY_ENABLE'] = '0'
31
- mock_page = double('page')
32
- Percy::Capybara.snapshot(mock_page)
33
- end
34
- end
35
- describe '#initialize_build' do
36
- it 'delegates to Percy::Capybara::Client' do
37
- capybara_client = Percy::Capybara.capybara_client
38
- expect(capybara_client).to receive(:initialize_build).once
39
- Percy::Capybara.initialize_build
40
- end
41
- end
42
- describe '#finalize_build' do
43
- it 'returns silently if no build is initialized' do
44
- expect { Percy::Capybara.finalize_build }.to_not raise_error
45
- end
46
- it 'delegates to Percy::Capybara::Client' do
47
- capybara_client = Percy::Capybara.capybara_client
48
- expect(capybara_client).to receive(:enabled?).and_return(true)
49
- build_data = {'data' => {'id' => 123}}
50
- expect(capybara_client.client).to receive(:create_build).and_return(build_data).once
51
- Percy::Capybara.initialize_build
52
- expect(capybara_client).to receive(:finalize_current_build).once
53
- Percy::Capybara.finalize_build
54
- end
55
- it 'silently skips if disabled' do
56
- ENV['PERCY_ENABLE'] = '0'
57
- capybara_client = Percy::Capybara.capybara_client
58
- expect(capybara_client.client).to_not receive(:create_build)
59
- Percy::Capybara.initialize_build
60
- expect(capybara_client).to_not receive(:finalize_current_build)
61
- Percy::Capybara.finalize_build
62
- end
63
- end
64
- describe '#reset!' do
65
- it 'clears the current capybara_client' do
66
- capybara_client = Percy::Capybara.capybara_client
67
- Percy::Capybara.reset!
68
- expect(Percy::Capybara.capybara_client).to_not eq(capybara_client)
69
- end
70
- end
71
- describe '#disable!' do
72
- it 'sets the current capybara_client to disabled' do
73
- capybara_client = Percy::Capybara::Client.new(enabled: true)
74
- expect(Percy::Capybara).to receive(:capybara_client)
75
- .and_return(capybara_client).exactly(3).times
76
- expect(Percy::Capybara.capybara_client.enabled?).to eq(true)
77
- Percy::Capybara.disable!
78
- expect(Percy::Capybara.capybara_client.enabled?).to eq(false)
79
- end
80
- end
81
- describe '#use_loader' do
82
- class DummyLoader < Percy::Capybara::Loaders::NativeLoader; end
83
-
84
- it 'sets the current capybara client\'s loader' do
85
- expect(Percy::Capybara.capybara_client.loader).to_not be
86
- Percy::Capybara.reset!
87
-
88
- Percy::Capybara.use_loader(DummyLoader)
89
- expect(Percy::Capybara.capybara_client.loader).to be
90
- end
91
-
92
- it 'sets the current capybara client\'s loader options' do
93
- expect(Percy::Capybara.capybara_client.loader_options).to eq({})
94
- Percy::Capybara.reset!
95
-
96
- Percy::Capybara.use_loader(DummyLoader, test_option: 3)
97
- expect(Percy::Capybara.capybara_client.loader_options).to be
98
- expect(Percy::Capybara.capybara_client.loader_options[:test_option]).to eq(3)
99
- end
100
- end
101
- end
@@ -1,60 +0,0 @@
1
- require 'socket'
2
- require 'timeout'
3
- require 'sprockets'
4
-
5
- module TestHelpers
6
- class ServerDown < RuntimeError; end
7
-
8
- def random_open_port
9
- # Using a port of "0" relies on the system to pick an open port.
10
- server = TCPServer.new('127.0.0.1', 0)
11
- port = server.addr[1]
12
- server.close
13
- port
14
- end
15
-
16
- def verify_server_up(host)
17
- http = HTTPClient.new
18
- 4.times do
19
- begin
20
- http.get(host)
21
- return true
22
- rescue Errno::ECONNREFUSED
23
- sleep 0.5
24
- end
25
- end
26
- raise ServerDown, "Server failed to start: #{host}"
27
- end
28
-
29
- def find_resource(resources, regex)
30
- begin
31
- resources.select { |resource| resource.resource_url.match(regex) }.fetch(0)
32
- rescue IndexError
33
- raise "Missing expected image with resource_url that matches: #{regex}"
34
- end
35
- end
36
-
37
- def setup_sprockets(capybara_client)
38
- root = File.expand_path('../../lib/percy/capybara/client/test_data', __FILE__)
39
- environment = Sprockets::Environment.new(root)
40
- environment.append_path '.'
41
-
42
- sprockets_options = double('sprockets_options')
43
- allow(sprockets_options).to receive(:precompile).and_return([/(?:\/|\\|\A)base\.(css|js)$/])
44
- allow(sprockets_options).to receive(:digest).and_return(false)
45
-
46
- capybara_client.sprockets_environment = environment
47
- capybara_client.sprockets_options = sprockets_options
48
- end
49
-
50
- # Set the environment variables required by Percy::Client
51
- def set_required_env_variables
52
- ENV['PERCY_TOKEN'] = 'aa'
53
- end
54
-
55
- # Clear the environment variables required by Percy::Client
56
- def clear_percy_env_variables
57
- ENV.delete('PERCY_TOKEN')
58
- ENV.delete('PERCY_ENABLE')
59
- end
60
- end