percy-capybara 4.3.2 → 5.0.0.pre.4

Sign up to get free protection for your applications and to get access to all the features.
data/.rubocop.yml DELETED
@@ -1,14 +0,0 @@
1
- inherit_gem:
2
- percy-style:
3
- - default.yml
4
-
5
-
6
- RSpec/InstanceVariable:
7
- Exclude:
8
- - spec/lib/percy/capybara_spec.rb
9
-
10
- RSpec/ContextWording:
11
- Enabled: false
12
-
13
- AllCops:
14
- TargetRubyVersion: 2.4
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- --protected
2
- --no-private
data/CHANGELOG.md DELETED
@@ -1 +0,0 @@
1
- See [releases](https://github.com/percy/percy-capybara/releases).
data/DEVELOPING.md DELETED
@@ -1,26 +0,0 @@
1
- # Developing percy-capybara
2
-
3
- You'll need:
4
- * [Ruby](https://www.ruby-lang.org)
5
- * [Bundler](https://bundler.io/)
6
- * [npm](https://www.npmjs.com/), to manage our dependency on [`@percy/agent`](https://www.npmjs.com/package/@percy/agent)
7
-
8
- To install dependencies:
9
- ```bash
10
- $ bundle install
11
- $ npm install
12
- ```
13
-
14
- To run our test suite and create snapshots:
15
- ```bash
16
- $ bundle exec rake snapshots
17
- ```
18
- (You'll need a `PERCY_TOKEN` in your environment for snapshots to be uploaded to Percy for diffing.)
19
-
20
- If you want to run the test suite without uploading snapshots, you can run:
21
- ```bash
22
- $ bundle exec rspec
23
- ```
24
-
25
- For instructions on releasing, and on updating the vendored version of `percy-agent.js` in this repository, please refer to the [RELEASING](RELEASING.md) doc.
26
-
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in percy-capybara.gemspec
4
- gemspec
5
-
6
- gem 'guard-rspec', require: false
7
-
8
- # (for development)
9
- # gem 'percy-client', path: '~/src/percy-client'
10
-
11
- group :test, :development do
12
- gem 'pry'
13
- end
data/Guardfile DELETED
@@ -1,14 +0,0 @@
1
- guard :rspec, cmd: 'bundle exec rspec' do
2
- require 'guard/rspec/dsl'
3
- dsl = Guard::RSpec::Dsl.new(self)
4
-
5
- # RSpec files
6
- rspec = dsl.rspec
7
- watch(rspec.spec_helper) { rspec.spec_dir }
8
- watch(rspec.spec_support) { rspec.spec_dir }
9
- watch(rspec.spec_files)
10
-
11
- # Ruby files
12
- ruby = dsl.ruby
13
- dsl.watch_spec_files_for(ruby.lib_files)
14
- end
data/RELEASING.md DELETED
@@ -1,23 +0,0 @@
1
- # Releasing
2
-
3
- 1. `git checkout master`
4
- 1. `git pull origin master`
5
- 1. `git checkout -b X.X.X`
6
- 1. Update version.rb file accordingly.
7
- 1. Commit and push the version update
8
- 1. Tag the release: `git tag vX.X.X`
9
- 1. Push changes: `git push --tags`
10
- 1. Ensure tests have passed on that tag
11
- 1. Open up a pull request titled with the new version number
12
- 1. Merge approved pull request
13
- 1. Draft and publish a [new release on github](https://github.com/percy/percy-capybara/releases)
14
- 1. Build and publish:
15
-
16
- ```bash
17
- bundle exec rake build
18
- gem push pkg/percy-capybara-X.XX.XX.gem
19
- ```
20
-
21
- * Announce the new release,
22
- making sure to say "thank you" to the contributors
23
- who helped shape this version!
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require 'bundler/gem_tasks'
data/lib/environment.rb DELETED
@@ -1,38 +0,0 @@
1
- require_relative './version'
2
-
3
- module Percy
4
- def self.client_info
5
- "percy-capybara/#{VERSION}"
6
- end
7
-
8
- def self.environment_info
9
- env_strings = [
10
- "rails/#{self._rails_version}",
11
- "sinatra/#{self._sinatra_version}",
12
- "capybara/#{self.capybara_version}",
13
- "ember-cli-rails/#{self._ember_cli_rails_version}",
14
- ].reject do |info|
15
- info =~ /\/$/ # reject if version is empty
16
- end
17
- env_strings.empty? ? 'unknown' : env_strings.join('; ')
18
- end
19
-
20
- def self.capybara_version
21
- Capybara::VERSION if defined? Capybara
22
- end
23
-
24
- def self._ember_cli_rails_version
25
- return unless defined? EmberCli
26
-
27
- require 'ember_cli/version'
28
- EmberCli::VERSION
29
- end
30
-
31
- def self._rails_version
32
- Rails.version if defined? Rails
33
- end
34
-
35
- def self._sinatra_version
36
- Sinatra::VERSION if defined? Sinatra
37
- end
38
- end
data/lib/percy.rb DELETED
@@ -1,142 +0,0 @@
1
- require 'logger'
2
- require 'net/http'
3
- require 'uri'
4
- require 'json'
5
- require 'environment'
6
-
7
- module Percy
8
- # Takes a snapshot of the given page HTML and its assets.
9
- #
10
- # See https://docs.percy.io/v1/docs/configuration for detailed documentation on
11
- # snapshot options.
12
- #
13
- # @param [Capybara::Session] page The Capybara page to snapshot.
14
- # @param [Hash] options
15
- # @option options [String] :name A unique name for the current page that identifies
16
- # it across builds. By default this is the URL of the page, but can be customized if the
17
- # URL does not entirely identify the current state.
18
- # @option options [Array(Number)] :widths Widths, in pixels, that you'd like to capture for
19
- # this snapshot.
20
- def self.snapshot(page, options = {})
21
- return unless self._is_agent_running?
22
-
23
- if !options.has_key?(:name)
24
- options[:name] = page.current_url
25
- end
26
-
27
- domSnapshot = self._make_dom_snapshot(page, self._keys_to_json(options))
28
- return unless domSnapshot
29
-
30
- body = {
31
- url: page.current_url,
32
- domSnapshot: domSnapshot,
33
- clientInfo: Percy.client_info,
34
- environmentInfo: Percy.environment_info,
35
- }
36
-
37
- body = body.merge(self._keys_to_json(options))
38
-
39
- if self._is_debug?
40
- self._logger.info { "passed snapshot options: #{options}" }
41
- self._logger.info { "snapshot object to POST: #{body}" }
42
- end
43
-
44
- self._post_snapshot_to_agent(body)
45
- end
46
-
47
- private
48
-
49
- AGENT_HOST = 'localhost'
50
- # Technically, the port is configurable when you run the agent. One day we might want
51
- # to make the port configurable in this SDK as well.
52
- AGENT_PORT = 5338
53
- AGENT_JS_PATH= '/percy-agent.js'
54
-
55
- def self._logger
56
- unless defined?(@logger)
57
- @logger = Logger.new(STDOUT)
58
- @logger.formatter = proc do |_severity, _datetime, _progname, msg|
59
- "[percy] #{msg} \n"
60
- end
61
- end
62
- return @logger
63
- end
64
-
65
- def self._get_agent_js
66
- begin
67
- return Net::HTTP.get(AGENT_HOST, AGENT_JS_PATH, AGENT_PORT)
68
- rescue => e
69
- self._logger.error { "Could not load #{AGENT_JS_PATH}. Error: #{e}" }
70
- return nil
71
- end
72
- end
73
-
74
- def self._make_dom_snapshot(page, options)
75
- agent_js = self._get_agent_js
76
- return unless agent_js
77
-
78
- begin
79
- page.execute_script(agent_js)
80
- domsnapshot_js = "(function() { return new window.PercyAgent({ handleAgentCommunication: false }).domSnapshot(document, #{options.to_json}) })()"
81
-
82
- # If we can use evalaute, use it (generally for capybara drivers)
83
- # `execute_script` should work, but some Capybara drivers specifically return nil from this method
84
- if page.respond_to?('evaluate_script')
85
- dom_snapshot = page.evaluate_script(domsnapshot_js)
86
- else
87
- # if the driver doesn't have evaluate, it's probably a selenium driver
88
- dom_snapshot = page.execute_script(domsnapshot_js)
89
- end
90
-
91
- return dom_snapshot
92
- rescue => e
93
- self._logger.error { "DOM snapshotting failed. Error: #{e}" }
94
- return nil
95
- end
96
- end
97
-
98
- def self._post_snapshot_to_agent(body)
99
- http = Net::HTTP.new(AGENT_HOST, AGENT_PORT)
100
- request = Net::HTTP::Post.new('/percy/snapshot', { 'Content-Type': 'application/json' })
101
- request.body = body.to_json
102
-
103
- begin
104
- response = http.request(request)
105
- rescue => e
106
- self._logger.error { "Percy rejected snapshot request. Error: #{e}" }
107
- end
108
- end
109
-
110
- def self._is_agent_running?
111
- begin
112
- Net::HTTP.get(AGENT_HOST, '/percy/healthcheck', AGENT_PORT)
113
- return true
114
- rescue => e
115
- if self._is_debug?
116
- self._logger.error { "Healthcheck failed, Percy is not running: #{e}" }
117
- end
118
-
119
- return false
120
- end
121
- end
122
-
123
- # For Ruby style, require snake_case args but transform them into camelCase for percy-agent.
124
- def self._keys_to_json(options)
125
- {
126
- enable_javascript: :enableJavaScript,
127
- min_height: :minHeight,
128
- percy_css: :percyCSS,
129
- request_headers: :requestHeaders,
130
- }.each do |ruby_key, json_key|
131
- if options.has_key? ruby_key
132
- options[json_key] = options[ruby_key]
133
- options.delete(ruby_key)
134
- end
135
- end
136
- return options
137
- end
138
-
139
- def self._is_debug?
140
- ENV['LOG_LEVEL'] == 'debug'
141
- end
142
- end
data/lib/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Percy
2
- VERSION = '4.3.2'.freeze
3
- end
data/package.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "private": true,
3
- "devDependencies": {
4
- "@percy/agent": "~0"
5
- }
6
- }
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'percy-capybara'
8
- spec.version = Percy::VERSION
9
- spec.authors = ['Perceptual Inc.']
10
- spec.email = ['team@percy.io']
11
- spec.summary = %q{Percy}
12
- spec.description = %q{}
13
- spec.homepage = ''
14
- spec.license = 'MIT'
15
-
16
- spec.metadata = {
17
- 'bug_tracker_uri' => 'https://github.com/percy/percy-capybara/issues',
18
- 'source_code_uri' => 'https://github.com/percy/percy-capybara',
19
- }
20
-
21
- spec.files = `git ls-files -z`.split("\x0")
22
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
- spec.require_paths = ['lib']
25
-
26
- spec.add_development_dependency 'bundler', '>= 2.0'
27
- spec.add_development_dependency 'rake', '~> 13.0'
28
- spec.add_development_dependency 'rspec', '~> 3.5'
29
- spec.add_development_dependency 'capybara', '~> 3.31'
30
- spec.add_development_dependency 'selenium-webdriver'
31
- spec.add_development_dependency 'percy-style', '~> 0.7.0'
32
- end
@@ -1,26 +0,0 @@
1
- RSpec.describe Percy do
2
- subject(:our_module) { Percy }
3
-
4
- describe '#environment_info' do
5
- subject(:environment_info) { Percy.environment_info }
6
-
7
- context 'an app with Rails, Sinatra and Ember Cli Rails' do
8
- it 'returns full environment information' do
9
- expect(our_module).to receive(:_rails_version).at_least(:once).times.and_return('4.2')
10
- expect(our_module).to receive(:_sinatra_version).at_least(:once).and_return('2.0.0')
11
- expect(our_module).to receive(:capybara_version).at_least(:once).and_return(Capybara::VERSION)
12
- expect(our_module).to receive(:_ember_cli_rails_version).at_least(:once).and_return('0.9')
13
-
14
- expect(environment_info).to eq("rails/4.2; sinatra/2.0.0; capybara/#{Capybara::VERSION}; ember-cli-rails/0.9")
15
- end
16
- end
17
- end
18
-
19
- describe '#client_info' do
20
- subject(:client_info) { Percy.client_info }
21
-
22
- it 'includes client information' do
23
- expect(client_info).to eq("percy-capybara/#{Percy::VERSION}")
24
- end
25
- end
26
- end
@@ -1,72 +0,0 @@
1
- # coding: utf-8
2
- RSpec.describe Percy, type: :feature do
3
- TEST_CASE_GLOB = File.join(File.dirname(__FILE__), "./capybara/client/test_data/test-*.html")
4
-
5
- describe '#snapshot', type: :feature, js: true do
6
- context 'with live sites' do
7
- it 'snapshots simple HTTPS site' do
8
- visit 'https://example.com'
9
- Percy.snapshot(page)
10
- end
11
- it 'snapshots complex HTTPS site' do
12
- visit 'https://polaris.shopify.com/'
13
- Percy.snapshot(page)
14
- end
15
- it 'snapshots site with strict CSP' do
16
- visit 'https://buildkite.com/'
17
- Percy.snapshot(page)
18
- end
19
- end
20
- context 'with different options' do
21
- it 'can get a default name' do
22
- visit 'http://example.com'
23
- Percy.snapshot(page)
24
- end
25
- it 'uses query params and fragment for default name' do
26
- visit 'http://example.com/?with_query'
27
- Percy.snapshot(page)
28
- visit 'http://example.com/?with_query_params#and-fragment'
29
- Percy.snapshot(page)
30
- end
31
- it 'uses provided name' do
32
- visit 'http://example.com'
33
- Percy.snapshot(page, name: 'My very special snapshot 🌟')
34
- end
35
- it 'recognizes requested widths' do
36
- visit 'http://example.com'
37
- Percy.snapshot(page, { name: 'widths', widths: [768, 992, 1200] })
38
- end
39
- it 'recognizes minHeight' do
40
- visit 'http://example.com'
41
- Percy.snapshot(page, { name: 'minHeight', minHeight: 2000 })
42
- end
43
- it 'recognizes enable_javascript' do
44
- visit 'http://example.com'
45
- Percy.snapshot(page, { name: 'enableJavaScript', enable_javascript: true })
46
- end
47
- it 'recognizes percy_css' do
48
- visit 'http://example.com'
49
- Percy.snapshot(page, { name: 'percyCSS', percy_css: "body {background-color: purple }" })
50
- end
51
- end
52
- end
53
-
54
- describe '_keys_to_json' do
55
- it 'transforms keys from snake_case to JSON-style' do
56
- original = {
57
- enable_javascript: true,
58
- min_height: 2000,
59
- percy_css: "iframe { display: none; }",
60
- request_headers: { Authorization: "Basic abc123=" },
61
- }
62
- transformed = Percy._keys_to_json(original)
63
- expect(transformed.has_key? 'enableJavaScript')
64
- expect(transformed.has_key? 'percyCSS')
65
- expect(transformed.has_key? 'minHeight')
66
- expect(transformed['enableJavaScript']).to eq(original[:enable_javascript])
67
- expect(transformed['minHeight']).to eq(original[:min_height])
68
- expect(transformed['percyCSS']).to eq(original[:percy_css])
69
- expect(transformed['requestHeaders']).to eq(original[:request_headers])
70
- end
71
- end
72
- end
data/spec/spec_helper.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'capybara/rspec'
2
- require 'selenium-webdriver'
3
- require 'percy'
4
-
5
- RSpec.configure do |config|
6
- config.expect_with :rspec do |expectations|
7
- # This option will default to `true` in RSpec 4.
8
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
- end
10
-
11
- config.mock_with :rspec do |mocks|
12
- mocks.verify_partial_doubles = true
13
- end
14
-
15
- config.disable_monkey_patching!
16
- # config.warnings = true
17
-
18
- # Run specs in random order to surface order dependencies. If you find an
19
- # order dependency and want to debug it, you can fix the order by providing
20
- # the seed, which is printed after each run.
21
- # --seed 1234
22
- config.order = :random
23
-
24
- # Seed global randomization in this process using the `--seed` CLI option.
25
- # Setting this allows you to use `--seed` to deterministically reproduce
26
- # test failures related to randomization by passing the same `--seed` value
27
- # as the one that triggered the failure.
28
- Kernel.srand config.seed
29
-
30
- # See https://github.com/teamcapybara/capybara#selecting-the-driver for other options
31
- Capybara.default_driver = :selenium_headless
32
- Capybara.javascript_driver = :selenium_headless
33
- end