Skip to content

No way to fix tests from hanging with fake modern timers #11572

@meskill

Description

@meskill

🐛 Bug Report

Using some nodejs libraries in source code (e.g. fast-glob) and modern timers leads to hanging tests with the error Exceeded timeout of 5000 ms for a test.

I've tried different things to force timers to continue executing (e.g. jest.runAllTimers(), jest.runAllTicks()) but nothing helped.

Also changing timers type on file level (e.g. jest.useRealTimers() and jest.useFakeTimers('legacy')) doesn't prevent test from hanging - only changing timers type in jest.config.js to real or legacy fixes it.

To Reproduce

You can find reproduction steps in repo

I think issue is coming from the usage of setImmediate inside some of the dependencies, but I have no idea why it is not resolvable by any of jest's functions for timers.

Expected behavior

There should be a way to prevent the test from hanging, at least changing timers type at file level should work the same way as it working on config level.

Link to repo

https://github.com/meskill/jest27-fake-timers-hangs

envinfo

  System:
    OS: Linux 4.19 Alpine Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/bin/npm
  npmPackages:
    jest: ^27.0.4 => 27.0.4 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions