-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><head><title>I am a page</title></head><body>Snapshot me</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
RSpec.describe PercyCapybara, type: :feature do | ||
before(:each) do | ||
WebMock.disable_net_connect!(allow: '127.0.0.1', disallow: 'localhost') | ||
## @TODO hm | ||
page.__percy_clear_cache! | ||
end | ||
|
||
describe 'snapshot', type: :feature, js: true do | ||
it 'disables when healthcheck version is incorrect' do | ||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck") | ||
.to_return(status: 200, body: '', headers: {'x-percy-core-version': '0.1.0'}) | ||
|
||
expect { page.percy_snapshot('Name') } | ||
.to output("#{PercyCapybara::LABEL} Unsupported Percy CLI version, 0.1.0\n").to_stdout | ||
end | ||
|
||
it 'disables when healthcheck version is missing' do | ||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck") | ||
.to_return(status: 200, body: '', headers: {}) | ||
|
||
expect { page.percy_snapshot('Name') } | ||
.to output( | ||
"#{PercyCapybara::LABEL} You may be using @percy/agent which" \ | ||
' is no longer supported by this SDK. Please uninstall' \ | ||
' @percy/agent and install @percy/cli instead.' \ | ||
" https://docs.percy.io/docs/migrating-to-percy-cli\n", | ||
).to_stdout | ||
end | ||
|
||
it 'disables when healthcheck fails' do | ||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck") | ||
.to_return(status: 500, body: '', headers: {}) | ||
|
||
expect { page.percy_snapshot('Name') } | ||
.to output("#{PercyCapybara::LABEL} Percy is not running, disabling snapshots\n").to_stdout | ||
end | ||
|
||
it 'disables when healthcheck fails to connect' do | ||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck") | ||
.to_raise(StandardError) | ||
|
||
expect { page.percy_snapshot('Name') } | ||
.to output("#{PercyCapybara::LABEL} Percy is not running, disabling snapshots\n").to_stdout | ||
end | ||
|
||
it 'throws an error when name is not provided' do | ||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck") | ||
.to_return(status: 500, body: '', headers: {}) | ||
|
||
expect { page.percy_snapshot }.to raise_error(ArgumentError) | ||
end | ||
|
||
it 'logs an error when sending a snapshot fails' do | ||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck") | ||
.to_return(status: 200, body: '', headers: {'x-percy-core-version': '1.0.0'}) | ||
|
||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/dom.js") | ||
.to_return( | ||
status: 200, | ||
body: 'window.PercyDOM = { serialize: () => document.documentElement.outerHTML };', | ||
headers: {}, | ||
) | ||
|
||
stub_request(:post, 'http://localhost:5338/percy/snapshot') | ||
.to_return(status: 200, body: '', headers: {}) | ||
|
||
expect { page.percy_snapshot('Name') } | ||
.to output("#{PercyCapybara::LABEL} Could not take DOM snapshot 'Name'\n").to_stdout | ||
end | ||
|
||
it 'sends snapshots to the local server' do | ||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck") | ||
.to_return(status: 200, body: '', headers: {'x-percy-core-version': '1.0.0'}) | ||
|
||
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/dom.js") | ||
.to_return( | ||
status: 200, | ||
body: 'window.PercyDOM = { serialize: () => document.documentElement.outerHTML };', | ||
headers: {}, | ||
) | ||
|
||
stub_request(:post, 'http://localhost:5338/percy/snapshot') | ||
.to_return(status: 200, body: '{"success": "true" }', headers: {}) | ||
|
||
visit 'index.html' | ||
page.percy_snapshot('Name') | ||
|
||
expect(WebMock) | ||
.to have_requested(:post, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/snapshot") | ||
.with( | ||
body: { | ||
name: 'Name', | ||
url: 'http://127.0.0.1:3003/index.html', | ||
dom_snapshot: | ||
"<html><head><title>I am a page</title></head><body>Snapshot me\n</body></html>", | ||
client_info: "percy-capybara/#{PercyCapybara::VERSION}", | ||
environment_info: "capybara/#{Capybara::VERSION} ruby/#{RUBY_VERSION}", | ||
}.to_json, | ||
).once | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters