Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise error if baseUrl is set and not supported #26

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/cypress-rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,28 @@ def determine_new_config(config_path)
end

def merge_existing_with_defaults(json_path)
Hash[JSON.parse(File.read(json_path)).merge(DEFAULT_CONFIG).sort]
existing = JSON.parse(File.read(json_path))
base_url = existing["baseUrl"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a lot more things to be checked here, but I figured I'd stop at path and scheme just to demonstrate the idea

if base_url
base_uri = URI(base_url)
has_path = base_uri.path != "" && base_uri.path != "/"
not_using_http = base_uri.scheme != "http"

if has_path || not_using_http
path_message = if has_path
"contains a path ('#{base_uri.path}')"
else
nil
end
scheme_message = if not_using_http
"not using http:// (using '#{base_uri.scheme}')"
else
nil
end
raise "Your baseUrl '#{base_url}' is not supported: it #{[path_message,scheme_message].join('.')}. You will need to modify your baseUrl to 'http://#{base_uri.host}:#{base_uri.port}' and modify your Cypress tests to assume this baseUrl"
end
end
Hash[existing.merge(DEFAULT_CONFIG).sort]
end
end
end