NickBolles / cypress-nuxt

Cypress plugin to make unit tests with nuxt simple
26 stars 0 forks source link

Cannot visit home page "/" #6

Open Albertbol opened 4 years ago

Albertbol commented 4 years ago

Hey, thanks for developing this package!

Can you please help me out to figure out the problem I'm having?

I did exactly the same steps but I'm getting always this error:

cy.visit() failed trying to load: http://localhost:3000/ The response we received from your web server was:

500: Server Error

Obviously, I can open the homepage, but the test always fails. ( I spin up nuxt before running cypress open )

cypress.json:

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

cypress/integration/test.spec.js:

describe('The Home Page', () => {
  it('should visit the home page', () => {
    cy.visit('/')
  })
})

cypress/plugins/index.js:

const cypressNuxt = require('cypress-nuxt')
module.exports = async (on, config) => {
  on('file:preprocessor', await cypressNuxt.plugin())
  return config
}

Allway getting this as the result: Screenshot 2020-11-14 at 16 03 39

I can open the URL in a different tab and the home page opens correctly.

devDependencies:

    "cypress": "^5.6.0",
    "cypress-nuxt": "^1.3.1",

If I will start without nuxt cypress open, I will get this: Screenshot 2020-11-14 at 16 12 23 Which means that actually, nuxt is running correctly on localhost:3000 on my previous problem, but why it's not reaching the home page 🤔

Albertbol commented 4 years ago

Well its was error in i18n middleware: before:

locale = req.headers['accept-language']
  .split(',')[0]
  .toLocaleLowerCase()
  .substring(0, 2)

after:

 if (req.headers['accept-language']) {
  locale = req.headers['accept-language']
    .split(',')[0]
    .toLocaleLowerCase()
    .substring(0, 2)
}

So basically it means that it's unhandled in cypress and not shown in any logs. Any mistake in code will break cypress from the loading the website.