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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41d7750c08015a049fe7e96a1bef9fa66e63ab4f8d46470745dca33785381938
|
4
|
+
data.tar.gz: 134b1bb862eddc96233205c664ec06e2573a6eff10aa17c8a182ca6740c98510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c136d0dab551741667317aad40b5309d6153bca15add7a12923327340b5810e181b0b6234e6f6c8b522a8ff6bc63f852fac3a1a76661e4b7b2775da985420e01
|
7
|
+
data.tar.gz: 90ff43e7d90292c828703b9220c03e798dfbffbe23f10a71317035605baed181fc4ece0d5720fca27fc41c966069243cd0e7a321afe9b7cd611092b1c62dc70c
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name-template: 'v$RESOLVED_VERSION'
|
2
|
+
tag-template: 'v$RESOLVED_VERSION'
|
3
|
+
categories:
|
4
|
+
- title: '💥 Breaking Changes'
|
5
|
+
labels:
|
6
|
+
- breaking
|
7
|
+
- title: '✨ Enhancements'
|
8
|
+
labels:
|
9
|
+
- feature
|
10
|
+
- enhancement
|
11
|
+
- title: '🐛 Bug Fixes'
|
12
|
+
labels:
|
13
|
+
- fix
|
14
|
+
- bugfix
|
15
|
+
- bug
|
16
|
+
- title: '🏗 Maintenance'
|
17
|
+
labels:
|
18
|
+
- chore
|
19
|
+
- dependencies
|
20
|
+
change-title-escapes: '\<*_&#@'
|
21
|
+
version-resolver:
|
22
|
+
major:
|
23
|
+
labels:
|
24
|
+
- breaking
|
25
|
+
minor:
|
26
|
+
labels:
|
27
|
+
- feature
|
28
|
+
- enhancement
|
29
|
+
default: patch
|
30
|
+
template: '$CHANGES'
|
31
|
+
prerelease: true
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Lint
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [master]
|
5
|
+
pull_request:
|
6
|
+
workflow_dispatch:
|
7
|
+
jobs:
|
8
|
+
lint:
|
9
|
+
name: Lint
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.6
|
16
|
+
bundler-cache: true
|
17
|
+
- uses: actions/cache@v2
|
18
|
+
with:
|
19
|
+
path: "./vendor/bundle"
|
20
|
+
key: v1/${{ runner.os }}/ruby-2.6/${{ hashFiles('**/Gemfile.lock') }}
|
21
|
+
restore-keys: v1/${{ runner.os }}/ruby-2.6/
|
22
|
+
- run: bundle exec rubocop
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Release
|
2
|
+
on:
|
3
|
+
release:
|
4
|
+
types: [published]
|
5
|
+
jobs:
|
6
|
+
publish:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- uses: ruby/setup-ruby@v1
|
11
|
+
with:
|
12
|
+
ruby-version: 2.6
|
13
|
+
bundler-cache: true
|
14
|
+
- uses: actions/cache@v2
|
15
|
+
with:
|
16
|
+
path: "./vendor/bundle"
|
17
|
+
key: v1/${{ runner.os }}/ruby-2.6/${{ hashFiles('**/Gemfile.lock') }}
|
18
|
+
restore-keys: v1/${{ runner.os }}/ruby-2.6/
|
19
|
+
- uses: cadwallion/publish-rubygems-action@master
|
20
|
+
env:
|
21
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
22
|
+
RELEASE_COMMAND: make release
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Test
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [master]
|
5
|
+
pull_request:
|
6
|
+
workflow_dispatch:
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
name: Test
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
os: [ubuntu-latest]
|
13
|
+
ruby: ['2.6', '2.7']
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{matrix.ruby}}
|
20
|
+
bundler-cache: true
|
21
|
+
- uses: actions/cache@v2
|
22
|
+
with:
|
23
|
+
path: "./vendor/bundle"
|
24
|
+
key: v1/${{ runner.os }}/ruby-${{ matrix.ruby }}/${{ hashFiles('**/Gemfile.lock') }}
|
25
|
+
restore-keys: v1/${{ runner.os }}/ruby-${{ matrix.ruby }}/
|
26
|
+
- run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
inherit_gem:
|
2
2
|
percy-style:
|
3
3
|
- default.yml
|
4
|
-
|
5
|
-
|
6
4
|
RSpec/InstanceVariable:
|
7
5
|
Exclude:
|
8
|
-
-
|
9
|
-
|
6
|
+
-
|
10
7
|
RSpec/ContextWording:
|
11
8
|
Enabled: false
|
12
|
-
|
13
9
|
AllCops:
|
14
|
-
TargetRubyVersion: 2.
|
10
|
+
TargetRubyVersion: 2.4
|
11
|
+
Include:
|
12
|
+
- lib/**/*.rb
|
13
|
+
- spec/lib/**/*.rb
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/Makefile
ADDED
data/README.md
CHANGED
@@ -1,6 +1,100 @@
|
|
1
|
-
#
|
1
|
+
# percy-capybara
|
2
|
+
[](https://badge.fury.io/rb/percy-capybara)
|
3
|
+

|
2
4
|
|
3
|
-
[
|
4
|
-
[](http://badge.fury.io/rb/percy-capybara)
|
5
|
+
[Percy](https://percy.io) visual testing for Ruby Selenium.
|
5
6
|
|
6
|
-
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
npm install `@percy/cli`:
|
10
|
+
|
11
|
+
```sh-session
|
12
|
+
$ npm install --save-dev @percy/cli
|
13
|
+
```
|
14
|
+
|
15
|
+
gem install `percy-capybara` package:
|
16
|
+
|
17
|
+
```ssh-session
|
18
|
+
$ gem install percy-capybara
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In your test setup file, require `percy/capybara`. For example if you're using
|
24
|
+
rspec, you would add the following to your `spec_helper.rb` file:
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
require 'percy/capybara'
|
28
|
+
```
|
29
|
+
|
30
|
+
Now you can use `page.percy_snapshot` to capture snapshots.
|
31
|
+
|
32
|
+
> Note: you may need to add `js: true` to your specs, depending on your driver setup
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
describe 'my feature, type: :feature do
|
36
|
+
it 'renders the page' do
|
37
|
+
visit 'https://example.com'
|
38
|
+
page.percy_snapshot('Capybara snapshot')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Running the test above normally will result in the following log:
|
44
|
+
|
45
|
+
```sh-session
|
46
|
+
[percy] Percy is not running, disabling snapshots
|
47
|
+
```
|
48
|
+
|
49
|
+
When running with [`percy
|
50
|
+
exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#percy-exec), and your project's
|
51
|
+
`PERCY_TOKEN`, a new Percy build will be created and snapshots will be uploaded to your project.
|
52
|
+
|
53
|
+
```sh-session
|
54
|
+
$ export PERCY_TOKEN=[your-project-token]
|
55
|
+
$ percy exec -- [test command]
|
56
|
+
[percy] Percy has started!
|
57
|
+
[percy] Created build #1: https://percy.io/[your-project]
|
58
|
+
[percy] Snapshot taken "Capybara example"
|
59
|
+
[percy] Stopping percy...
|
60
|
+
[percy] Finalized build #1: https://percy.io/[your-project]
|
61
|
+
[percy] Done!
|
62
|
+
```
|
63
|
+
|
64
|
+
## Configuration
|
65
|
+
|
66
|
+
`page.snapshot(name[, options])`
|
67
|
+
|
68
|
+
- `name` (**required**) - The snapshot name; must be unique to each snapshot
|
69
|
+
- `options` - [See per-snapshot configuration options](https://docs.percy.io/docs/cli-configuration#per-snapshot-configuration)
|
70
|
+
|
71
|
+
## Upgrading
|
72
|
+
|
73
|
+
### Manually
|
74
|
+
|
75
|
+
#### Require change
|
76
|
+
|
77
|
+
The name of the require has changed from `require 'percy'` to `require
|
78
|
+
'percy/capybara'`. This is to avoid conflict with our [Ruby Selenium SDK's](https://github.com/percy/percy-selenium-ruby)
|
79
|
+
require statement.
|
80
|
+
|
81
|
+
#### Installing `@percy/cli` & removing `@percy/agent`
|
82
|
+
|
83
|
+
If you're coming from a 4.x version of this package, make sure to install `@percy/cli` after
|
84
|
+
upgrading to retain any existing scripts that reference the Percy CLI
|
85
|
+
command. You will also want to uninstall `@percy/agent`, as it's been replaced
|
86
|
+
by `@percy/cli`.
|
87
|
+
|
88
|
+
```sh-session
|
89
|
+
$ npm uninstall @percy/agent
|
90
|
+
$ npm install --save-dev @percy/cli
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Migrating config
|
94
|
+
|
95
|
+
If you have a previous Percy configuration file, migrate it to the newest version with the
|
96
|
+
[`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:
|
97
|
+
|
98
|
+
```sh-session
|
99
|
+
$ percy config:migrate
|
100
|
+
```
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'capybara/dsl'
|
4
|
+
|
5
|
+
module PercyCapybara
|
6
|
+
include Capybara::DSL
|
7
|
+
|
8
|
+
CLIENT_INFO = "percy-capybara/#{VERSION}".freeze
|
9
|
+
ENV_INFO = "capybara/#{Capybara::VERSION} ruby/#{RUBY_VERSION}".freeze
|
10
|
+
|
11
|
+
PERCY_DEBUG = ENV['PERCY_LOGLEVEL'] == 'debug'
|
12
|
+
PERCY_SERVER_ADDRESS = ENV['PERCY_SERVER_ADDRESS'] || 'http://localhost:5338'
|
13
|
+
PERCY_LABEL = "[\u001b[35m" + (PERCY_DEBUG ? 'percy:capybara' : 'percy') + "\u001b[39m]"
|
14
|
+
|
15
|
+
private_constant :CLIENT_INFO
|
16
|
+
private_constant :ENV_INFO
|
17
|
+
|
18
|
+
# Take a DOM snapshot and post it to the snapshot endpoint
|
19
|
+
def percy_snapshot(name, options = {})
|
20
|
+
return unless percy_enabled?
|
21
|
+
|
22
|
+
begin
|
23
|
+
page.evaluate_script(fetch_percy_dom)
|
24
|
+
dom_snapshot =
|
25
|
+
page.evaluate_script("(function() { return PercyDOM.serialize(#{options.to_json}) })()")
|
26
|
+
|
27
|
+
response = fetch('percy/snapshot',
|
28
|
+
name: name,
|
29
|
+
url: page.current_url,
|
30
|
+
dom_snapshot: dom_snapshot,
|
31
|
+
client_info: CLIENT_INFO,
|
32
|
+
environment_info: ENV_INFO,)
|
33
|
+
|
34
|
+
unless response.body.to_json['success']
|
35
|
+
raise StandardError, data['error']
|
36
|
+
end
|
37
|
+
rescue StandardError => e
|
38
|
+
log("Could not take DOM snapshot '#{name}'")
|
39
|
+
|
40
|
+
if PERCY_DEBUG then log(e) end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Determine if the Percy server is running, caching the result so it is only checked once
|
45
|
+
private def percy_enabled?
|
46
|
+
return @percy_enabled unless @percy_enabled.nil?
|
47
|
+
|
48
|
+
begin
|
49
|
+
response = fetch('percy/healthcheck')
|
50
|
+
version = response['x-percy-core-version']
|
51
|
+
|
52
|
+
if version.nil?
|
53
|
+
log('You may be using @percy/agent ' \
|
54
|
+
'which is no longer supported by this SDK. ' \
|
55
|
+
'Please uninstall @percy/agent and install @percy/cli instead. ' \
|
56
|
+
'https://docs.percy.io/docs/migrating-to-percy-cli')
|
57
|
+
@percy_enabled = false
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
|
61
|
+
if version.split('.')[0] != '1'
|
62
|
+
log("Unsupported Percy CLI version, #{version}")
|
63
|
+
@percy_enabled = false
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
|
67
|
+
@percy_enabled = true
|
68
|
+
true
|
69
|
+
rescue StandardError => e
|
70
|
+
log('Percy is not running, disabling snapshots')
|
71
|
+
|
72
|
+
if PERCY_DEBUG then log(e) end
|
73
|
+
@percy_enabled = false
|
74
|
+
false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Fetch the @percy/dom script, caching the result so it is only fetched once
|
79
|
+
private def fetch_percy_dom
|
80
|
+
return @percy_dom unless @percy_dom.nil?
|
81
|
+
|
82
|
+
response = fetch('percy/dom.js')
|
83
|
+
@percy_dom = response.body
|
84
|
+
end
|
85
|
+
|
86
|
+
private def log(msg)
|
87
|
+
puts "#{PERCY_LABEL} #{msg}"
|
88
|
+
end
|
89
|
+
|
90
|
+
# Make an HTTP request (GET,POST) using Ruby's Net::HTTP. If `data` is present,
|
91
|
+
# `fetch` will POST as JSON.
|
92
|
+
private def fetch(url, data = nil)
|
93
|
+
uri = URI("#{PERCY_SERVER_ADDRESS}/#{url}")
|
94
|
+
|
95
|
+
response = if data
|
96
|
+
Net::HTTP.post(uri, data.to_json)
|
97
|
+
else
|
98
|
+
Net::HTTP.get_response(uri)
|
99
|
+
end
|
100
|
+
|
101
|
+
unless response.is_a? Net::HTTPSuccess
|
102
|
+
raise StandardError, "Failed with HTTP error code: #{response.code}"
|
103
|
+
end
|
104
|
+
|
105
|
+
response
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Add the `percy_snapshot` method to the the Capybara session class
|
110
|
+
# `page.percy_snapshot('name', { options })`
|
111
|
+
Capybara::Session.class_eval { include PercyCapybara }
|
data/percy-capybara.gemspec
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'version'
|
4
|
+
require 'percy/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'percy-capybara'
|
8
|
-
spec.version =
|
8
|
+
spec.version = PercyCapybara::VERSION
|
9
9
|
spec.authors = ['Perceptual Inc.']
|
10
10
|
spec.email = ['team@percy.io']
|
11
11
|
spec.summary = %q{Percy}
|
12
12
|
spec.description = %q{}
|
13
13
|
spec.homepage = ''
|
14
14
|
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.3.0'
|
15
16
|
|
16
17
|
spec.metadata = {
|
17
18
|
'bug_tracker_uri' => 'https://github.com/percy/percy-capybara/issues',
|
@@ -23,10 +24,12 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
25
|
spec.require_paths = ['lib']
|
25
26
|
|
26
|
-
spec.
|
27
|
-
|
27
|
+
spec.add_runtime_dependency 'capybara', '>= 3'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'selenium-webdriver', '>= 4.0.0.beta1'
|
30
|
+
spec.add_development_dependency 'bundler', '>= 2.0'
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
28
32
|
spec.add_development_dependency 'rspec', '~> 3.5'
|
29
|
-
spec.add_development_dependency 'capybara', '~>
|
30
|
-
spec.add_development_dependency '
|
31
|
-
spec.add_development_dependency 'percy-style'
|
33
|
+
spec.add_development_dependency 'capybara', '~> 3.31'
|
34
|
+
spec.add_development_dependency 'percy-style', '~> 0.7.0'
|
32
35
|
end
|