fast-glob icon indicating copy to clipboard operation
fast-glob copied to clipboard

Calling `fastGlob()` with a mocked system time runs forever

Open Haegi opened this issue 2 years ago • 3 comments

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();

  });
});

Haegi avatar Jun 03 '22 10:06 Haegi

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 avatar Jun 11 '22 11:06 mrmlnc

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.

mrmlnc avatar Jul 16 '22 17:07 mrmlnc

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().

Haegi avatar Jul 22 '22 07:07 Haegi

Fixed in https://github.com/nodelib/nodelib/commit/f588299716f944ba646ac45b92f518d061c07dc3. Will be shipped with v4 (#371).

mrmlnc avatar May 05 '23 06:05 mrmlnc