Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling fastGlob() with a mocked system time runs forever #362

Closed
Haegi opened this issue Jun 3, 2022 · 4 comments
Closed

Calling fastGlob() with a mocked system time runs forever #362

Haegi opened this issue Jun 3, 2022 · 4 comments
Assignees
Milestone

Comments

@Haegi
Copy link

Haegi commented Jun 3, 2022

Environment

  • OS Version: macOS Monterey 12.3.1 (arm64)
  • Node.js Version: v17.4.0

package.json

"@types/jest": "^28.1.0",
"fast-glob": "^3.2.11",
 "jest": "^28.1.0",
"ts-jest": "^28.0.4",
"typescript": "^4.7.2"

Actual behavior

fastGlob() runs forever with a (jest) mocked system time.

Expected behavior

I would expect that fast-glob doesn't care about the system time.

Steps to reproduce

  1. mock system time (using jest)
  2. call fastGlob()
  3. see timeout of the test runner

Code sample

import fastGlob from 'fast-glob';

import {describe, expect, it , beforeAll, afterAll, jest} from '@jest/globals'

// runs into timeout
describe('with changed system time', () => {
  beforeAll(async () => {
    jest.useFakeTimers();
    jest.setSystemTime(new Date(2022, 3, 29));
  });

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

  it('will run forever ', async () => {
    const option = {
      cwd: 'test',
    };
    const response = await fastGlob('**/', option);
	  expect(response).toBeDefined();

  });
});

// passes
describe('without changed system time', () => {
  it('will run forever ', async () => {
    const option = {
      cwd: 'test',
    };

    const response = await fastGlob('**/', option);
	  expect(response).toBeDefined();

  });
});
@mrmlnc mrmlnc self-assigned this Jun 11, 2022
@mrmlnc
Copy link
Owner

mrmlnc commented Jun 11, 2022

Hello, @Haegi,

It's an interesting situation. I'll take a look at it.

Right now I can assume that the current behavior is related to the use of the setImmediate function in one of the dependencies.

https://github.com/nodelib/nodelib/blob/2091d2cbad735701d889a0c4c935bbc9c278ad58/packages/fs/fs.walk/src/readers/async.ts#L38-L40

If that's the case, I can't help here, because I can't refuse to use this function.

@mrmlnc
Copy link
Owner

mrmlnc commented Jul 16, 2022

I think we can remove the problematic method inside the @nodelib/fs.walk dependency.

Will be fixed in the next major version of the @nodelib/fs.walk package that will be used in the next major version of this package.

Now can use the selective faking functionality to work around this problem.

@Haegi
Copy link
Author

Haegi commented Jul 22, 2022

Thanks @mrmlnc for your investigations.
I am looking forward to the next major version.
For now I workaround it by not mocking the whole system time but just the new Date().

Arkham added a commit to Shopify/cli that referenced this issue Oct 20, 2022
If we don't remember to call useRealTimers after useFakeTimers vitest
will keep these date and time functions mocked, which can cause issues
to other libraries which depend on the passing of time. In our case,
fastglob would hang indefinitely: mrmlnc/fast-glob#362
@mrmlnc
Copy link
Owner

mrmlnc commented May 5, 2023

Fixed in nodelib/nodelib@f588299. Will be shipped with v4 (#371).

@mrmlnc mrmlnc closed this as completed May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants