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

cy.visit() failed trying to load #57

Closed
cop-portal opened this issue Jun 8, 2020 · 3 comments
Closed

cy.visit() failed trying to load #57

cop-portal opened this issue Jun 8, 2020 · 3 comments

Comments

@cop-portal
Copy link

cop-portal commented Jun 8, 2020

Versions

  • What is this plugin's version? 1.3.11
  • What is Cypress version? 4.7.0
  • What Netlify build image are you using? This setting is available under "Deploy settings / Build image selection". Probably either "Ubuntu Trusty 14.04" or "Ubuntu Xenial 16.04" Ubuntu Xenial 16.04
  • What is the Node version if you know it? n/a
  • What is the NPM version if you know it? we use yarn

Describe the bug
Cypess passes all tests locally. However, it failed in Netlify CI. Specifically, I'm getting this error below when the plugin runs in Netlify:

CypressError: `cy.visit()` failed trying to load:
12:33:54 PM: http://localhost:8080/home
12:33:54 PM: The response we received from your web server was:
12:33:54 PM:   > 404: Not Found

I've got this setup "baseUrl": "http://localhost:3000" in cypress.json. Even if I tried updating basUrl port to 8080, I still get the same error.

I've also tried to set up a preBuild for the plugin, there are no loading issues of the prebuild test. However, the second test (postBuild) fails due to the 404 loading issue.

My website is not a static website. It's calling contentful API instead. I wonder if the plug-in only can work for a static website? Or we need to make a tweak somewhere?
Logs and screenshots

Screen Shot 2020-06-08 at 2 21 06 PM

@bahmutov
Copy link
Contributor

bahmutov commented Jun 8, 2020

Hi @cop-portal

Do you have a redirect in the netlify settings for all non-base URLs to /? I believe your issue is described in https://glebbahmutov.com/blog/routing-with-fallback/

  • you have a web app with client-side routing
  • when the browser goes to / and then clicks on a link, client-side routing goes to /home for example
  • if you enter the /home URL directly in the browser though there is no /home.html file, so the visit gets 404
  • to support this, the server has to redirect all unknown links to /index.html where the client-side routing can handle it
  • when you use preBuild, it is running YOUR dev application server, thus it knows about the redirect. When you use regular tests on Netlify, we serve the built side using simple static server https://github.com/cypress-io/netlify-plugin-cypress/blob/master/src/index.js#L9

I have opened issue #59 to add the fallback for unknown URLs as an option

@cop-portal
Copy link
Author

@bahmutov You're correct. Thanks for this. We have a redirect setting on Netlify build file. However, this plugin somehow doesn't pick it up. I will wait until you resolve the issue #59

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

@bahmutov
Copy link
Contributor

Should be resolved by https://github.com/cypress-io/netlify-plugin-cypress/releases/tag/v1.4.0 with spa parameter

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

No branches or pull requests

2 participants