jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: Imports from React.lazy calls may cause random test timeouts

Open tsmock opened this issue 1 year ago • 0 comments

Version

29.7.0

Steps to reproduce

jestTimeout.tar.gz

Steps to reproduce:

  1. Extract the attached tar file
  2. Run npm install
  3. Run npm test -- note: you may need to modify the timeout in index.test.jsx depending upon the speed of your storage device.
  4. Comment out the import in slowImport.jsx; alternatively, add the import to the test file.

Expected behavior

One of the following:

  1. All React.lazy calls should be run once (hard, probably won't happen -- React.lazy doesn't have to be at the top level, and I don't think they get hoisted to the top level).
  2. A message indicating that delayed imports such as those that may occur with React.lazy may cause seemingly random test timeouts.
  3. A note for React.lazy indicating that the lazy components should be imported prior to the test (in this case, this bug should be over in the react repo)
  4. Log import calls 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

tsmock avatar Feb 08 '24 20:02 tsmock