cypress-rails icon indicating copy to clipboard operation
cypress-rails copied to clipboard

overwrites baseUrl?

Open davetron5000 opened this issue 4 years ago • 3 comments

Migrating something to use this gem—which I am so thankful exists—and for no good reason, my baseUrl was not /, so my initial cypress.json was like this:

{
  "baseUrl": "http://localhost:3000/foo"
}

bin/rails cypress:init did not change that value, but when I run bin/rails cypress:run, my guess is that the "use some random port to run the rails app" does this by setting baseUrl to http://localhost:«that random port», thus making my tests fail. They use cy.visit("/") and were requesting / and not /foo, which is what the baseUrl should've been sending them to (note the tests worked if I ran rails on its own and did cypress run).

I changed all my cy.visit("/") to cy.visit("/foo"), and everything worked (and I should've done that anyway), but I guess what was surprising was that this gem means I cannot set baseUrl any longer. I think that is fine behavior, but maybe should be documented and/or output in some sort of log?

If agreed, I can fork the README and write what would've made this not surprising to me, but wanted to confirm that behavior first.

davetron5000 avatar May 12 '20 22:05 davetron5000

Sorry for the frustration, Dave! (👋 by the way)

I spent a few minutes trying to make sense of the code, but I can't confirm or deny the root cause at first glance. This server#base_url method would seem to confirm your point, but it's not referenced anywhere in the gem, so maybe it's actually dead code 😱

Would happily accept any PR that would either improve the documentation or the gem for others

searls avatar May 13 '20 02:05 searls

Looks like this is where that happens:

https://github.com/testdouble/cypress-rails/blob/master/lib/cypress-rails/launches_cypress.rb#L31

I guess I could've grep'ed that myself o_O

I will make two PRs, one for docs and one for logging this.

davetron5000 avatar May 13 '20 12:05 davetron5000

Fixed in 0.3.0 (see #26)

searls avatar May 15 '20 05:05 searls