From c8f1e13ec948f20d8cdbd7f8a69f626161e88534 Mon Sep 17 00:00:00 2001 From: Dave Copeland Date: Wed, 13 May 2020 08:44:02 -0400 Subject: [PATCH] raise error if baseUrl is set and not supported --- lib/cypress-rails/init.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/cypress-rails/init.rb b/lib/cypress-rails/init.rb index dd208bb..b890c6e 100644 --- a/lib/cypress-rails/init.rb +++ b/lib/cypress-rails/init.rb @@ -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"] + 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