You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have configured jest-puppeteer to start up my React application (which runs using react-scripts / CRA) using the server config, together with usedPortAction: 'ignore'.
When running Jest, if the React application was not already running, jest-dev-server starts it up and then my tests are run correctly.
But, if my React app was already running, jest-dev-server fails to detect (and ignore) it, tries to run it again, and ends up failing with the following error; and my tests are not run.
[jest-dev-server] Something is already running on port 3000.
1- Start CRA app with npm start, wait for app to be ready (listening on port 3000).
2- Run tests with npm test
Expected behavior
As I'm using the config usedPortAction: 'ignore' config, when my app is already running on the specified port (3000), jest-dev-server should detect it that it's already running and don't try to start it up; then proceed to run my tests.
Since in my environment seems to occur that IPv6 is available, the default host used is ::, so when calling .listen(config.port) (without specifying the host in a next parameter), this server ends up listening (instead of resulting in EADDRINUSE), and on http://:::3000 address.
I have been able to validate this by editing the above snippet and running it on my machine:
When my React application is up in port 3000, running this snippet with node, results in the output:
Server listening: http://:::3000
port busy?false
On the other hand, react-scripts startscript, runs the React application server by default on host '0.0.0.0', therefore ends up listening in 'http://0.0.0.0:3000' address.
Proposal
I think the easiest way to solve this, is to allow specifying the host as a config option for the Node server used to check if the port is busy, just like we already do for the port property.
This way, we could specify the exact host: '0.0.0.0', and checkIsPortBusy() would work fine for this case.
🐛 Bug Report
I have configured jest-puppeteer to start up my React application (which runs using react-scripts / CRA) using the
server
config, together withusedPortAction: 'ignore'
.When running Jest, if the React application was not already running, jest-dev-server starts it up and then my tests are run correctly.
But, if my React app was already running, jest-dev-server fails to detect (and ignore) it, tries to run it again, and ends up failing with the following error; and my tests are not run.
To Reproduce
jest-puppeteer.config.js file:
jest.config.js
package.json:
Steps:
1- Start CRA app with
npm start
, wait for app to be ready (listening on port 3000).2- Run tests with
npm test
Expected behavior
As I'm using the config
usedPortAction: 'ignore'
config, when my app is already running on the specified port (3000), jest-dev-server should detect it that it's already running and don't try to start it up; then proceed to run my tests.System:
Binaries:
npmPackages:
Issue Analysis
I've been reviewing the code responsible for detecting if the port is being used:
jest-puppeteer/packages/jest-dev-server/src/index.ts
Lines 155 to 170 in 7becfaf
The problem with this code, is that the
host
config property is not being specified. When this happens, as of Node v16, per the Node docs:Since in my environment seems to occur that IPv6 is available, the default
host
used is::
, so when calling.listen(config.port)
(without specifying the host in a next parameter), this server ends up listening (instead of resulting in EADDRINUSE), and onhttp://:::3000
address.I have been able to validate this by editing the above snippet and running it on my machine:
When my React application is up in port 3000, running this snippet with
node
, results in the output:On the other hand, react-scripts
start
script, runs the React application server by default on host'0.0.0.0'
, therefore ends up listening in'http://0.0.0.0:3000'
address.Proposal
I think the easiest way to solve this, is to allow specifying the
host
as a config option for the Node server used to check if the port is busy, just like we already do for theport
property.This way, we could specify the exact
host: '0.0.0.0'
, andcheckIsPortBusy()
would work fine for this case.The following code is working properly
Output:
Also, with this change in my node_modules folder, when I update my jest-puppeteer.config.js file like so:
Everything works smoothly, my test runs and doesn't try to spin up my React app again. Running
npm test
outputs:The text was updated successfully, but these errors were encountered: