jest
jest copied to clipboard
[Bug]: Imports from React.lazy calls may cause random test timeouts
Version
29.7.0
Steps to reproduce
Steps to reproduce:
- Extract the attached tar file
- Run
npm install - Run
npm test-- note: you may need to modify the timeout inindex.test.jsxdepending upon the speed of your storage device. - Comment out the import in
slowImport.jsx; alternatively, add the import to the test file.
Expected behavior
One of the following:
- All
React.lazycalls should be run once (hard, probably won't happen --React.lazydoesn't have to be at the top level, and I don't think they get hoisted to the top level). - A message indicating that delayed imports such as those that may occur with
React.lazymay cause seemingly random test timeouts. - A note for
React.lazyindicating that the lazy components should be imported prior to the test (in this case, this bug should be over in the react repo) - Log
importcalls and print to console when they occur inside a test instead of during initial import loading
Actual behavior
A generic timeout error is given. In my experience, this can cause tests to fail inconsistently unless the test was previously close to the timeout limit in a consistent environment (like CI).
Additional context
On my machine, importing date-fns in the index.test.js file took the slow import test from >400ms to <50ms. I believe that the same amount of time was spent overall in the test, but we weren't waiting on the filesystem during the bit that needed to complete within the timeout limit.
Environment
System:
OS: macOS 13.6.4
CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
Binaries:
Node: 20.11.0 - ~/.asdf/installs/nodejs/20.11.0/bin/node
npm: 10.2.4 - ~/.asdf/plugins/nodejs/shims/npm
npmPackages:
jest: ^29.7.0 => 29.7.0