start-server-and-test icon indicating copy to clipboard operation
start-server-and-test copied to clipboard

Allow to specify the http code we shoud have before starting action

Open SirMishaa opened this issue 4 years ago • 1 comments

Hello,

I have a problem, I develop with NuxtJS and Cypress.

When I start the NuxtJS server, even during its initialization, it always responds with http 200 code, even on a page that doesn't exist.

So I have no way to detect that the server has finished initializing because it responds directly after it is launched.

The only way to get around this problem is to call an url that doesn't exist in order to get a 404 error because if the server answers with a 404 error, it's the Nuxt router that handles the request and so the server is completely initialized and I can launch my e2e tests afterwards without risking having any problem.

Is it therefore possible to specify the http return code you want before launching the second command?

Thank you very much

SirMishaa avatar Nov 28 '20 08:11 SirMishaa

Hello,

When using the development mode with Nuxt, the page is available directly without even loading all the modules. You therefore have to wait a few moments before calling the e2e tests.

If you want your server fully initialized without waiting manually and call your e2e tests, you need to use production mode. It will build all your files and start the page directly after all modules have been loaded.

In your package json :

{
  ...
  "scripts": {
    "start": "nuxt start",
    "cy:run": "cypress run",
    "tests:e2e": "nuxt build && start-server-and-test start http://localhost:3000 cy:run"
  }
}

Usage with npm :

  • npm run tests:e2e

Usage with yarn :

  • yarn tests:e2e

vanfrancoisle avatar Nov 03 '23 10:11 vanfrancoisle

Just a note for whoever ends up here, you can also state the whole url in the start-test command and prepend http-get://

like so start-test dev http-get://localhost:3000 cy:run

"scripts": {
    "dev": "nuxt dev -p 3000", // note i pass the port here just to be sure
    "test": "start-test dev http-get://localhost:3000 cy:run"
  },

maxmckenzie avatar Mar 18 '24 10:03 maxmckenzie