start-server-and-test: Unable to run tests with Vite dev server

I have a Vite dev server running on port 3000 with a functioning application. Running the e2e tests in a separate thread works fine. But together run by start-server-and-test it stucks after starting the Vite server.

  • version 1.11.7
  • platform MacOS
  • expected behavior: Runs the tests after the dev server started.
  • actual behavior: start-server-and-test hangs when Vite start the webserver. The server is up and running and the tests can be run in a separate terminal.

My package json setup:

  "scripts": {
    "start": "vite",
    "test:e2e:javascript": "start-server-and-test start http://localhost:3000 e2e:javascript",
    "e2e:javascript": "jest --config=jest.e2e.config.js e2e/javascript"
  }

Reproduction: In my https://github.com/blacksonic/vue-3-playground repository run: npm run test:e2e:javascript

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 21 (4 by maintainers)

Most upvoted comments

Is it correct that this still needs to use http-get to work? It doesn’t seem to work otherwise for me using Vite 2.0.5 and start-server-and-test 1.12.0.

I would gladly add a mention in addition to webpack-dev-server in the README if that’s the case.

I just had a similar issue after upgrading to vite 5.0.0 (it previously worked fine with v4.5.0).

My fix (after a lot of trial and error was to add --expect 404 to the start-server-and-test command

This is now my scripts:

  "scripts": {
    "start": "chmod +x ./build-env.sh && ./build-env.sh && vite",
    "build": "vite build",
    "serve": "vite preview",
    "cypress:open": "cypress open",
    "cypress:run": "cypress run --browser chrome",
    "ci": "CI=true start-server-and-test --expect 404 start http://localhost:3000 cypress:run"
  },

edit: fwiw this seems to be fixed in 5.0.2 (see https://github.com/vitejs/vite/pull/15059 and https://github.com/vitejs/vite/pull/15025 for fixes, and related issues https://github.com/vitejs/vite/issues/9520 and https://github.com/vitejs/vite/issues/15022 for why --expect 404 was necessary in v5 before these fixes)


After upgrading to vite 5.0.0, I have got the same problem. (it worked fine with v4.5.0). @edant92’s suggestion work for me.

same here.

huge thanks to @edant92 for their --expect 404 workaround 🙌🏻 .

My mistake, I had deleted my index.html since typically, our entry point is a .tsx file.

🤦

I’ll edit my previous comment!

I can also confirm this is fixed in 5.0.2 and the --expect 404 workaround is no longer needed 😃

@gottfired

Did you try starting vite with vite --host?

See https://vitejs.dev/config/server-options.html#server-host

We have Vite 3.2.2 and start-server-and-test 1.14 and the exact same issue. Tests start too early. Any tips how to solve this?