percy-capybara 4.2.0 → 5.0.0.pre.1
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/.github/dependabot.yml +8 -0
- data/.github/release-drafter.yml +31 -0
- data/.github/workflows/changelog.yml +11 -0
- data/.github/workflows/lint.yml +22 -0
- data/.github/workflows/release.yml +22 -0
- data/.github/workflows/test.yml +26 -0
- data/.rubocop.yml +5 -6
- data/Gemfile +3 -0
- data/LICENSE +1 -1
- data/Makefile +3 -0
- data/README.md +98 -4
- data/lib/percy/capybara.rb +111 -0
- data/lib/percy/version.rb +3 -0
- data/percy-capybara.gemspec +10 -7
- data/spec/fixture/index.html +1 -0
- data/spec/lib/percy/percy_capybara_spec.rb +103 -0
- data/spec/spec_helper.rb +22 -4
- metadata +58 -44
- data/.circleci/config.yml +0 -39
- data/CHANGELOG.md +0 -1
- data/DEVELOPING.md +0 -26
- data/RELEASING.md +0 -23
- data/lib/environment.rb +0 -33
- data/lib/percy.rb +0 -145
- data/lib/version.rb +0 -3
- data/package.json +0 -6
- data/spec/lib/percy/environment_spec.rb +0 -31
- data/spec/lib/percy/percy_spec.rb +0 -72
- data/yarn.lock +0 -1920
@@ -0,0 +1 @@
|
|
1
|
+
<html><head><title>I am a page</title></head><body>Snapshot me</body></html>
|
@@ -0,0 +1,103 @@
|
|
1
|
+
LABEL = PercyCapybara::PERCY_LABEL
|
2
|
+
|
3
|
+
RSpec.describe PercyCapybara, type: :feature do
|
4
|
+
before(:each) do
|
5
|
+
WebMock.disable_net_connect!(allow: '127.0.0.1', disallow: 'localhost')
|
6
|
+
page.__percy_clear_cache!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'snapshot', type: :feature do
|
10
|
+
it 'disables when healthcheck version is incorrect' do
|
11
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
|
12
|
+
.to_return(status: 200, body: '', headers: {'x-percy-core-version': '0.1.0'})
|
13
|
+
|
14
|
+
expect { page.percy_snapshot('Name') }
|
15
|
+
.to output("#{LABEL} Unsupported Percy CLI version, 0.1.0\n").to_stdout
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'disables when healthcheck version is missing' do
|
19
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
|
20
|
+
.to_return(status: 200, body: '', headers: {})
|
21
|
+
|
22
|
+
expect { page.percy_snapshot('Name') }
|
23
|
+
.to output(
|
24
|
+
"#{LABEL} You may be using @percy/agent which" \
|
25
|
+
' is no longer supported by this SDK. Please uninstall' \
|
26
|
+
' @percy/agent and install @percy/cli instead.' \
|
27
|
+
" https://docs.percy.io/docs/migrating-to-percy-cli\n",
|
28
|
+
).to_stdout
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'disables when healthcheck fails' do
|
32
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
|
33
|
+
.to_return(status: 500, body: '', headers: {})
|
34
|
+
|
35
|
+
expect { page.percy_snapshot('Name') }
|
36
|
+
.to output("#{LABEL} Percy is not running, disabling snapshots\n").to_stdout
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'disables when healthcheck fails to connect' do
|
40
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
|
41
|
+
.to_raise(StandardError)
|
42
|
+
|
43
|
+
expect { page.percy_snapshot('Name') }
|
44
|
+
.to output("#{LABEL} Percy is not running, disabling snapshots\n").to_stdout
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'throws an error when name is not provided' do
|
48
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
|
49
|
+
.to_return(status: 500, body: '', headers: {})
|
50
|
+
|
51
|
+
expect { page.percy_snapshot }.to raise_error(ArgumentError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'logs an error when sending a snapshot fails' do
|
55
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
|
56
|
+
.to_return(status: 200, body: '', headers: {'x-percy-core-version': '1.0.0'})
|
57
|
+
|
58
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/dom.js")
|
59
|
+
.to_return(
|
60
|
+
status: 200,
|
61
|
+
body: 'window.PercyDOM = { serialize: () => document.documentElement.outerHTML };',
|
62
|
+
headers: {},
|
63
|
+
)
|
64
|
+
|
65
|
+
stub_request(:post, 'http://localhost:5338/percy/snapshot')
|
66
|
+
.to_return(status: 200, body: '', headers: {})
|
67
|
+
|
68
|
+
expect { page.percy_snapshot('Name') }
|
69
|
+
.to output("#{LABEL} Could not take DOM snapshot 'Name'\n").to_stdout
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'sends snapshots to the local server' do
|
73
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
|
74
|
+
.to_return(status: 200, body: '', headers: {'x-percy-core-version': '1.0.0'})
|
75
|
+
|
76
|
+
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/dom.js")
|
77
|
+
.to_return(
|
78
|
+
status: 200,
|
79
|
+
body: 'window.PercyDOM = { serialize: () => document.documentElement.outerHTML };',
|
80
|
+
headers: {},
|
81
|
+
)
|
82
|
+
|
83
|
+
stub_request(:post, 'http://localhost:5338/percy/snapshot')
|
84
|
+
.to_return(status: 200, body: '{"success": "true" }', headers: {})
|
85
|
+
|
86
|
+
visit 'index.html'
|
87
|
+
page.percy_snapshot('Name')
|
88
|
+
|
89
|
+
expect(WebMock)
|
90
|
+
.to have_requested(:post, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/snapshot")
|
91
|
+
.with(
|
92
|
+
body: {
|
93
|
+
name: 'Name',
|
94
|
+
url: 'http://127.0.0.1:3003/index.html',
|
95
|
+
dom_snapshot:
|
96
|
+
"<html><head><title>I am a page</title></head><body>Snapshot me\n</body></html>",
|
97
|
+
client_info: "percy-capybara/#{PercyCapybara::VERSION}",
|
98
|
+
environment_info: "capybara/#{Capybara::VERSION} ruby/#{RUBY_VERSION}",
|
99
|
+
}.to_json,
|
100
|
+
).once
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
# This must be required & started before any app code (for proper coverage)
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
SimpleCov.minimum_coverage 100
|
5
|
+
|
1
6
|
require 'capybara/rspec'
|
2
|
-
require '
|
3
|
-
require 'percy'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'percy/capybara'
|
4
9
|
|
5
10
|
RSpec.configure do |config|
|
6
11
|
config.expect_with :rspec do |expectations|
|
@@ -28,6 +33,19 @@ RSpec.configure do |config|
|
|
28
33
|
Kernel.srand config.seed
|
29
34
|
|
30
35
|
# See https://github.com/teamcapybara/capybara#selecting-the-driver for other options
|
31
|
-
Capybara.default_driver = :
|
32
|
-
Capybara.javascript_driver = :
|
36
|
+
Capybara.default_driver = :selenium_headless
|
37
|
+
Capybara.javascript_driver = :selenium_headless
|
38
|
+
|
39
|
+
# Setup for Capybara to test static files served by Rack
|
40
|
+
Capybara.server_port = 3003
|
41
|
+
Capybara.server = :puma, { Silent: true }
|
42
|
+
Capybara.app = Rack::File.new(File.join(File.dirname(__FILE__), 'fixture'))
|
33
43
|
end
|
44
|
+
|
45
|
+
## Add cache clearing methods for tests
|
46
|
+
Capybara::Session.class_eval {
|
47
|
+
def __percy_clear_cache!
|
48
|
+
@percy_dom = nil
|
49
|
+
@percy_enabled = nil
|
50
|
+
end
|
51
|
+
}
|
metadata
CHANGED
@@ -1,99 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: capybara
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: selenium-webdriver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0.beta1
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - "
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
40
|
+
version: 4.0.0.beta1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '2.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '2.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '13.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '13.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '3.5'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '3.5'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: capybara
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '3.31'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
96
|
+
version: '3.31'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: percy-style
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 0.7.0
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
110
|
+
version: 0.7.0
|
97
111
|
description: ''
|
98
112
|
email:
|
99
113
|
- team@percy.io
|
@@ -101,28 +115,28 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
|
-
- ".
|
118
|
+
- ".github/dependabot.yml"
|
119
|
+
- ".github/release-drafter.yml"
|
120
|
+
- ".github/workflows/changelog.yml"
|
121
|
+
- ".github/workflows/lint.yml"
|
122
|
+
- ".github/workflows/release.yml"
|
123
|
+
- ".github/workflows/test.yml"
|
105
124
|
- ".gitignore"
|
106
125
|
- ".rspec"
|
107
126
|
- ".rubocop.yml"
|
108
127
|
- ".yardopts"
|
109
|
-
- CHANGELOG.md
|
110
|
-
- DEVELOPING.md
|
111
128
|
- Gemfile
|
112
129
|
- Guardfile
|
113
130
|
- LICENSE
|
131
|
+
- Makefile
|
114
132
|
- README.md
|
115
|
-
- RELEASING.md
|
116
133
|
- Rakefile
|
117
|
-
- lib/
|
118
|
-
- lib/percy.rb
|
119
|
-
- lib/version.rb
|
120
|
-
- package.json
|
134
|
+
- lib/percy/capybara.rb
|
135
|
+
- lib/percy/version.rb
|
121
136
|
- percy-capybara.gemspec
|
122
|
-
- spec/
|
123
|
-
- spec/lib/percy/
|
137
|
+
- spec/fixture/index.html
|
138
|
+
- spec/lib/percy/percy_capybara_spec.rb
|
124
139
|
- spec/spec_helper.rb
|
125
|
-
- yarn.lock
|
126
140
|
homepage: ''
|
127
141
|
licenses:
|
128
142
|
- MIT
|
@@ -137,18 +151,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
151
|
requirements:
|
138
152
|
- - ">="
|
139
153
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
154
|
+
version: 2.3.0
|
141
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- - "
|
157
|
+
- - ">"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
159
|
+
version: 1.3.1
|
146
160
|
requirements: []
|
147
|
-
rubygems_version: 3.0.
|
161
|
+
rubygems_version: 3.0.3
|
148
162
|
signing_key:
|
149
163
|
specification_version: 4
|
150
164
|
summary: Percy
|
151
165
|
test_files:
|
152
|
-
- spec/
|
153
|
-
- spec/lib/percy/
|
166
|
+
- spec/fixture/index.html
|
167
|
+
- spec/lib/percy/percy_capybara_spec.rb
|
154
168
|
- spec/spec_helper.rb
|
data/.circleci/config.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
version: 2.1
|
2
|
-
|
3
|
-
default_steps: &default_steps
|
4
|
-
steps:
|
5
|
-
- checkout
|
6
|
-
- run: gem update --system
|
7
|
-
# We need this specific version of bundler for our Gemfile. (v2 doesn't work)
|
8
|
-
- run: gem install bundler --version '1.7'
|
9
|
-
- run: yarn
|
10
|
-
- run: bundle install
|
11
|
-
- run: yarn percy exec -- bundle exec rspec
|
12
|
-
- run: bundle exec rubocop -D
|
13
|
-
|
14
|
-
jobs:
|
15
|
-
ruby_latest_with_percy:
|
16
|
-
# This is the one environment where we'll capture and upload snapshots in CI.
|
17
|
-
docker:
|
18
|
-
- image: circleci/ruby:latest-node-browsers
|
19
|
-
<<: *default_steps
|
20
|
-
ruby_25:
|
21
|
-
docker:
|
22
|
-
- image: circleci/ruby:2.5-node-browsers
|
23
|
-
environment:
|
24
|
-
PERCY_ENABLE: 0
|
25
|
-
<<: *default_steps
|
26
|
-
ruby_24:
|
27
|
-
docker:
|
28
|
-
- image: circleci/ruby:2.4-node-browsers
|
29
|
-
environment:
|
30
|
-
PERCY_ENABLE: 0
|
31
|
-
<<: *default_steps
|
32
|
-
|
33
|
-
workflows:
|
34
|
-
version: 2
|
35
|
-
test:
|
36
|
-
jobs:
|
37
|
-
- ruby_latest_with_percy
|
38
|
-
- ruby_25
|
39
|
-
- ruby_24
|
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/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/lib/environment.rb
DELETED
@@ -1,33 +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
|
-
"ember-cli-rails/#{self._ember_cli_rails_version}",
|
13
|
-
].reject do |info|
|
14
|
-
info =~ /\/$/ # reject if version is empty
|
15
|
-
end
|
16
|
-
env_strings.empty? ? 'unknown' : env_strings.join('; ')
|
17
|
-
end
|
18
|
-
|
19
|
-
def self._ember_cli_rails_version
|
20
|
-
return unless defined? EmberCli
|
21
|
-
|
22
|
-
require 'ember_cli/version'
|
23
|
-
EmberCli::VERSION
|
24
|
-
end
|
25
|
-
|
26
|
-
def self._rails_version
|
27
|
-
Rails.version if defined? Rails
|
28
|
-
end
|
29
|
-
|
30
|
-
def self._sinatra_version
|
31
|
-
Sinatra::VERSION if defined? Sinatra
|
32
|
-
end
|
33
|
-
end
|