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

Add configurability for external Cypress project through additional environment variable #159

Merged

Conversation

dmanliclic715
Copy link
Contributor

Hi!

Big cypress-rails fan and first time open source contributor here, so please excuse any open source contribution etiquette I'm missing!

Anyways, my team has a specific use-case that isn't quite covered(I think) by the current functionality of this gem, so I went about attempting to add that in and have found that it's working as expected. I'm not sure if others would benefit from the same functionality, but I wanted to put a PR out there to get some feelers.

Essentially, our Rails application serves as the API for a React/Cypress project that exists outside of our Rails directory. So, I needed a way for our external cypress project to be launched via the cypress-rails commands. With how the main CYPRESS_RAILS_DIR env var is configured, it seems like there's an assumption that the Cypress project also exists within the same directory. So I figured it'd be best to spin up another configurable environment variable that specifies where our Cypress project is located called: CYPRESS_DIR.

We'd then use that specific variable to manage the launching of Cypress in the LaunchesCypress service. Let me know if this makes sense or if there's anything else I can change!

@@ -4,8 +4,8 @@ module CypressRails
class FindsBin
LOCAL_PATH = "node_modules/.bin/cypress"

def call(dir = Dir.pwd)
local_path = Pathname.new(dir).join(LOCAL_PATH)
def call(cy_dir = Dir.pwd)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not entirely sure these variable name changes are necessary, but I just wanted it to be more clear that we're looking for a bin path within a directory with Cypress.

Copy link
Member

@searls searls left a comment

Choose a reason for hiding this comment

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

Thanks for submitting! I don't use cypress-rails anymore but this seems like a good idea.

@@ -2,17 +2,19 @@

module CypressRails
class Config
attr_accessor :dir, :host, :port, :base_path, :transactional_server, :cypress_cli_opts
attr_accessor :dir, :cy_dir, :host, :port, :base_path, :transactional_server, :cypress_cli_opts
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd rather spell these out as :rails_dir and :cypress_dir for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! Will add!

README.md Outdated
@@ -156,6 +156,7 @@ preferred environment variables project-wide using a tool like


* **CYPRESS_RAILS_DIR** (default: `Dir.pwd`) the directory of your project
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* **CYPRESS_RAILS_DIR** (default: `Dir.pwd`) the directory of your project
* **CYPRESS_RAILS_DIR** (default: `Dir.pwd`) the directory of your Rails project

@dmanliclic715 dmanliclic715 force-pushed the add-cypress-dir-environment-variable branch from aa22a9b to 3a4a99d Compare February 8, 2024 22:25
@@ -19,8 +19,8 @@ class Init
})
JS

def call(dir = Dir.pwd)
config_path = File.join(dir, "cypress.config.js")
def call(cypress_dir = Config.new.cypress_dir)
Copy link
Contributor Author

@dmanliclic715 dmanliclic715 Feb 8, 2024

Choose a reason for hiding this comment

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

@searls
Needed to also include this here, to make sure we're looking to write the "cypress.config.js" to the cypress dir. Let me know if that checks out!

@searls
Copy link
Member

searls commented Feb 9, 2024

Is this ready for merge or is there more to do?

@dmanliclic715
Copy link
Contributor Author

@searls All good on my end! Thanks again for taking a look!

@searls
Copy link
Member

searls commented Feb 9, 2024

Ok. Two things:

  1. All other env vars start with CYPRESS_RAILS so the new property should, too
  2. Significantly, this looks like it would be a breaking change to anyone currently setting CYPRESS_RAILS_DIR because they wouldn't be setting CYPRESS_DIR. That means if I currently have both in foo/, after merging this PR it would change to Dir.pwd. The cypress dir should default to whatever rails_dir is, not Dir.pwd, to avoid this
  3. Possible to write a test for this? The fact I caught this visually worries me because I don't use the library

…S_RAILS_CYPRESS_DIR to be same value as rails_dir attribute
@dmanliclic715 dmanliclic715 force-pushed the add-cypress-dir-environment-variable branch from 66bb871 to ae2a607 Compare February 12, 2024 16:59
@dmanliclic715
Copy link
Contributor Author

  1. Just tacked on the CYPRESS_RAILS prefix to the env var and it now reads CYPRESS_RAILS_CYPRESS_DIR
  2. Made the default value for the Env.fetch("CYPRESS_RAILS_CYPRESS_DIR", default: rails_dir) rails_dir to default to whatever the set value of CYPRESS_RAILS
  3. Added some test to test that CYPRESS_RAILS_CYPRESS_DIR defaults to the same value as CYPRESS_RAILS_DIR.

Thank you!

@searls searls merged commit 6090721 into testdouble:main Feb 13, 2024
2 checks passed
@searls
Copy link
Member

searls commented Feb 13, 2024

Thanks @dmanliclic715 -- released as 0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants