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() failing with 404 Not Found in postBuild for a NextJS application #480

Open
manhente opened this issue Nov 26, 2024 · 0 comments

Comments

@manhente
Copy link

Hello!

We have a NextJS v14 application running on Node v20 on Netlify. We're trying to add Cypress tests to it, but we're having trouble running the tests using he netlify-plugin-cypress at postBuild to test the built application and fail the build before deploying it in case one of the tests fail.

Our tests, however, are failing when ran in Netlify due to 404 Not Found errors in cy.visit() calls. We couldn't find any reference on what could be the cause or if there was any configuration needed to test NextJS applications this way that we might have missed.

Does anyone here knows what could be causing this issue?

Here's our netlify.toml file:

[build]
  command = "npm run build"
  publish = ".next"

[[plugins]]
  package = "@netlify/plugin-nextjs"

[[plugins]]
  package = "netlify-plugin-cypress"
  [plugins.inputs.postBuild]
    enable = true
    spa = true

Here's the output of the Netlify build with DEBUG=netlify-plugin-cypress set:

2024-11-26T11:20:45.514Z netlify-plugin-cypress cypress plugin postBuild inputs { enable: true, spa: true }
2024-11-26T11:20:45.514Z netlify-plugin-cypress folder to publish is ".next"
2024-11-26T11:20:45.515Z netlify-plugin-cypress serving local folder { directory: '.next', port: 8080, spa: 'index.html' } from working directory /opt/build/repo
2024-11-26T11:20:45.719Z netlify-plugin-cypress local server listening on port 8080
2024-11-26T11:20:45.872Z netlify-plugin-cypress local Chromium revisions [ '1045629' ]
2024-11-26T11:20:45.873Z netlify-plugin-cypress found Chromium { revision: '1045629', executablePath: '/opt/build/repo/node_modules/puppeteer/.local-chromium/linux-1045629/chrome-linux/chrome', folderPath: '/opt/build/repo/node_modules/puppeteer/.local-chromium/linux-1045629', local: true, url: 'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1045629/chrome-linux.zip', product: 'chrome' }
2024-11-26T11:20:45.873Z netlify-plugin-cypress run cypress params { baseUrl: 'http://localhost:8080', record: false, spec: undefined, group: undefined, tag: undefined, ciBuildId: undefined, browser: '/opt/build/repo/node_modules/puppeteer/.local-chromium/linux-1045629/chrome-linux/chrome' }
DevTools listening on ws://127.0.0.1:35699/devtools/browser/53669729-bc32-4b69-aca8-aa34e960adf6
tput: No value for $TERM and no -T specified
====================================================================================================
  (Run Starting)
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        13.16.0                                                                        │
  │ Browser:        Custom Chromium 107 (headless)                                                 │
  │ Node Version:   v20.18.1 (/opt/buildhome/.nvm/versions/node/v20.18.1/bin/node)                 │
  │ Specs:          2 found (login.cy.js, register.cy.js)                                          │
  │ Searched:       **/e2e/*.cy.{js,jsx,ts,tsx}                                                    │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
  Running:  login.cy.js                                                                     (1 of 2)
Failed during stage 'building site': Build script returned non-zero exit code: 2

  Login and Logout
    1) "before each" hook for "should not login - invalid user email"
  0 passing (485ms)
  1 failing
  1) Login and Logout
       "before each" hook for "should not login - invalid user email":
     CypressError: `cy.visit()` failed trying to load:
http://localhost:8080/session/login
The response we received from your web server was:
  > 404: Not Found
This was considered a failure because the status code was not `2xx`.
If you do not want status codes to cause failures pass the option: `failOnStatusCode: false`
Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `Login and Logout`
      at <unknown> (http://localhost:8080/__cypress/runner/cypress_runner.js:131461:76)
      at visitFailedByErr (http://localhost:8080/__cypress/runner/cypress_runner.js:130876:12)
      at <unknown> (http://localhost:8080/__cypress/runner/cypress_runner.js:131444:13)
      at tryCatcher (http://localhost:8080/__cypress/runner/cypress_runner.js:1830:23)
      at Promise._settlePromiseFromHandler (http://localhost:8080/__cypress/runner/cypress_runner.js:1542:31)
      at Promise._settlePromise (http://localhost:8080/__cypress/runner/cypress_runner.js:1599:18)
      at Promise._settlePromise0 (http://localhost:8080/__cypress/runner/cypress_runner.js:1644:10)
      at Promise._settlePromises (http://localhost:8080/__cypress/runner/cypress_runner.js:1720:18)
      at _drainQueueStep (http://localhost:8080/__cypress/runner/cypress_runner.js:2430:12)
      at _drainQueue (http://localhost:8080/__cypress/runner/cypress_runner.js:2423:9)
      at Async._drainQueues (http://localhost:8080/__cypress/runner/cypress_runner.js:2439:5)
      at Async.drainQueues (http://localhost:8080/__cypress/runner/cypress_runner.js:2309:14)
  From Your Spec Code:
      at Context.eval (webpack://miia-portal/./cypress/e2e/login.cy.js:35:7)

Thank you in advance for your help!

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

1 participant