nicolo-ribaudo / jest-light-runner

A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment.
MIT License
227 stars 24 forks source link

Using jest's fake timers completely freezes test execution #83

Open alucryd opened 8 months ago

alucryd commented 8 months ago

Using fake timers in multiple tests freezes the execution, with no other option but to kill the process.

import dayjs from "dayjs";

const now = dayjs();

beforeEach(async () => {
  jest.useFakeTimers().setSystemTime(now.toDate());
})

afterEach(async () => {
  jest.useRealTimers();
})

Calling jest.useRealTimers(); in afterEach as suggested here doesn't help unfortunately. Sorry I took so long go get back to creating a dedicated issue.

Zikoat commented 6 months ago

I am investigating a related issue, but i cannot reproduce it with your example. My issue was that some of my code was running which was depending on the time, and the promise never resolved. Could you debug your code to figure out on which line it is stopping? Or even better, create a minimal reproducible example, so we can reproduce it locally, see https://stackoverflow.com/help/minimal-reproducible-example . We would need a whole git repository with configuration and all the files, and the commands to reproduce the freeze.

Zikoat commented 6 months ago

You could also try running this with normal jest (not with jest-light-runner) to see if the problem is still present with normal jest.