jest-puppeteer
jest-puppeteer copied to clipboard
[jest-dev-server] fake timers prevent waitOn to check for liveliness
🐛 Bug Report
When using jest's timers: 'fake', waitOn cannot check for the server to be alive because the underlying rxjs timers cannot run properly. When setting timers: 'real', it works perfectly.
To Reproduce
Set timers to 'fake' in your jest config and watch it timing out every time.
Expected behavior
I don't know if there's anything against using fake timers with jest dev server, but that's a thing I heavily rely on in my tests because I deal with a lot of setTimeouts, so I thought this should be considered as a bug.
Link to repl or repo (highly encouraged)
https://replit.com/@dackmin/jest-dev-server-timers
repl cannot run spawnd due to missing ps, but download the project as a zip and just run yarn && yarn test inside.
Run npx envinfo --system --binaries --npmPackages expect-puppeteer,jest-dev-server,jest-environment-puppeteer,jest-puppeteer,spawnd --markdown --clipboard
Paste the results here:
## System:
- OS: macOS 11.5
- CPU: (12) x64 Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz
- Memory: 4.69 GB / 32.00 GB
- Shell: 5.8 - /bin/zsh
## Binaries:
- Node: 16.6.0 - ~/.nvm/versions/node/v16.6.0/bin/node
- Yarn: 1.22.5 - ~/.yarn/bin/yarn
- npm: 7.19.1 - ~/.nvm/versions/node/v16.6.0/bin/npm
- Watchman: 4.9.0 - /usr/local/bin/watchman
## npmPackages:
- jest-dev-server: 5.0.3 => 5.0.3
For anyone passing by, toggling fake/real timers before and after server setup works:
jest.useRealTimers();
await devServer.setup(...);
jest.useFakeTimers();
But I don't know if it's not flex tape on a dam more than a real solution 😄
The solution provided by @dackmin makes sense.