How to run Next.js and Jest concurrently, with an instance of Next.js already running?
Unanswered
Isaac posted this in #help-forum
IsaacOP
I have this script in my Next.js project, where I start a Next.js server (because the tests need it) and run Jest tests using [concurrently](https://www.npmjs.com/package/concurrently):
It was working fine until i updated Next.js to version 16. In previous versions, it was possible to have multiple Next.js instances running on the same project, but in Next.js 16 it isn't anymore.
Because of this, when I have my development server running and run this test command above, Next.js exits with code 1 because it can't start a second instance, and because of the
If I don't use the
I would need one of this solutions, or others:
1. Start the Next.js instance only if one ins't already running,
2. Be able to run two Next.js instances at the same time,
3. Inform
4. Inform
However, I don't know how to do any of those solutions, or if there would be a better one.
"test": "npm run services:up &&
npm run services:wait:database &&
concurrently --names next,jest
--kill-others --success command-jest
'next dev' 'jest --runInBand --verbose'"It was working fine until i updated Next.js to version 16. In previous versions, it was possible to have multiple Next.js instances running on the same project, but in Next.js 16 it isn't anymore.
Because of this, when I have my development server running and run this test command above, Next.js exits with code 1 because it can't start a second instance, and because of the
--kill-others flag, concurrently will kill the Jest process and the tests will not finish.If I don't use the
--kill-others flag, and Next.js successfully starts because there is no other instance running, it will stay running forever.I would need one of this solutions, or others:
1. Start the Next.js instance only if one ins't already running,
2. Be able to run two Next.js instances at the same time,
3. Inform
concurrently that if Next.js fails specifically because another instance already exist, it's fine and other processes should continue, or4. Inform
concurrently that upon succeeding on the jest command, all other commands and its processes should be terminated - then I would remove --kill-others flag and depend solely upon Jest return.However, I don't know how to do any of those solutions, or if there would be a better one.