fast-glob
fast-glob copied to clipboard
Calling `fastGlob()` with a mocked system time runs forever
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
- mock system time (using jest)
- call
fastGlob()
- 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();
});
});
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.
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.
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()
.
Fixed in https://github.com/nodelib/nodelib/commit/f588299716f944ba646ac45b92f518d061c07dc3. Will be shipped with v4 (#371).