jest-puppeteer
jest-puppeteer copied to clipboard
Server not stopped when jest --watch exits
🐛 Bug Report
When exiting jest --watch (by pressing q), the server doesn't seem to stop.
To Reproduce
// jest-puppeteer.config.js
module.exports = {
server: {
command: 'python -m http.server 8081 --directory src',
port: 8081,
},
}
jest --watch(oryarn test --watchin my case)- run some tests
- press
qto quit jest --watchagain
Determining test suites to run...
✔ Another process is listening on 8081. Should I kill it for you? On linux, this may require you to enter your password. … yes
● Test suite failed to run
TypeError: Cannot read property 'name' of undefined
at logProcDetection (node_modules/jest-dev-server/lib/global.js:70:69)
at ask (node_modules/jest-dev-server/lib/global.js:153:9)
at async setupJestServer (node_modules/jest-dev-server/lib/global.js:174:7)
at async Promise.all (index 0)
at async setup (node_modules/jest-dev-server/lib/global.js:123:3)
at async setup (node_modules/jest-environment-puppeteer/lib/global.js:38:7)
Expected behavior
In step 4. I would expect to have the tests running again without any confirmation to kill a running process.
Link to repl or repo
https://github.com/Volcomix/waane/tree/e4c3631a7424c8fd1cd67f858990de95eb369556
Environment
## System:
- OS: Linux 5.4 Arch Linux
- CPU: (8) x64 Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
- Memory: 9.14 GB / 15.59 GB
- Container: Yes
- Shell: 5.0.11 - /bin/bash
## Binaries:
- Node: 13.5.0 - /usr/bin/node
- Yarn: 1.21.1 - /usr/bin/yarn
- npm: 6.13.4 - /usr/bin/npm
- Watchman: 4.9.0 - /usr/bin/watchman
## npmPackages:
- jest-puppeteer: ^4.4.0 => 4.4.0
The error which appears when asking to kill the existing process seems to be related to find-process module because:
$ npx find-process 32431
Found 1 process
[python]
pid: 32431
cmd: python -m http.server 8081 --directory src
but
$ npx find-process -p 8081
No process found
Issue opened: yibn2008/find-process#31
I think I might be having the same issue. When my test fails the node server isn't shut down and I have to manually kill it before running the tests again.
Workaround using https://www.npmjs.com/package/start-server-and-test:
In your config file something like:
if (!process.env.NO_SERVER) {
config.server = {
command: 'node ./server/start.js',
port: process.env.PORT || 3456,
},
};
then run a task like:
start-server-and-test "NODE_ENV=test make run" http://localhost:3456 "NO_SERVER=true jest test --watch"
The teardown method linked to below is called after each run of the full test suite, it specifically guards against tearing down the servers when in watch mode:
https://github.com/smooth-code/jest-puppeteer/blob/56715a8938e859d994c9ea1520cf44a3c796c98e/packages/jest-environment-puppeteer/src/global.js#L69-L71
Unfortunately if Jest is shut down whilst the test suites are being run or sat idle between runs then this teardown method does not get called... and I can't yet see any way to hook into Jest to do so.
I had thought that adding a handler for SIGINT might work but there is currently an issue with this: https://github.com/facebook/jest/issues/10052
cc https://github.com/facebook/jest/issues/6029
We can't really stop server when jest is closing. To mitigate this, jest-dev-server detects the server running on the port.