-
-
Notifications
You must be signed in to change notification settings - Fork 479
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
Regression with memfs #515
Comments
It's failing because you're giving it a cwd that doesn't exist, according to the fs it has to work with. Either give it an explicit cwd in the glob options like this: const expandedFiles = await glob('/**/*', { nodir: true, cwd: '/' }); Or add the I think this is a bug, though, tbh. It shouldn't require that the cwd exist unless you have a pattern that mounts on the cwd. |
Fixed in v9.3.1 |
Hi @isaacs Thanks for the fast response. Unfortunately, I tested with 9.3.1 and I still got the same behaviour, even when ensuring import { fs as memfs, vol } from 'memfs';
jest.doMock('fs', () => memfs);
jest.spyOn(process, 'cwd').mockReturnValue('/');
import { glob } from 'glob';
describe('glob', () => {
beforeEach(() => {
vol.fromJSON({ '/x': 'abc' }, '/');
});
it('should match single file with pattern', async () => {
const expandedFiles = await glob('/*', {
nodir: true,
cwd: '/',
});
expect(expandedFiles).toStrictEqual(['/x']); //PASS
});
it('should match single file without pattern', async () => {
const expandedFiles = await glob('/x', {
nodir: true,
cwd: '/',
});
expect(expandedFiles).toStrictEqual(['/x']); //FAIL
});
}); It's somehow memfs-related but I can't put the finger on it. Works OK with the real The tests above are just for reporting the current bug. However we are using I'm not 100% sure it's not my fault. Maybe I'm not mocking |
Huh, that's weird. I did add a test using memfs, but I'm not using jest. It's possible it's mocking differently, but also possible I just missed an edge case in there. I'll see if I can reproduce, should be an easy fix if so. |
In your test, you added It may be that we are hitting a |
So I can reproduce it in Jest, but only in Jest. If I just run the program, and mock the fs with the mockfs, then it works. My only guess is that somehow Jest is not mocking the fs reliably? Or not everywhere? I really don't know how Jest works, it took some doing just to figure out where I had to put the test file to get jest to run it, and then when I did, apparently they cripple Idk, whatever is going on here, it really seems like Glob is doing the right thing, and Jest is not mocking the environment like you think it is. |
Oh!! Derp, it's because it needs to mock Change this line: jest.doMock('fs', () => memfs); to this:
And it'll work. |
Not needed at the moment, but just to future proof it, probably should also add: jest.doMock('node:fs', () => memfs);
jest.doMock('node:fs/promises', () => memfs.promises); in case TypeScript ever decides to start putting the |
Many thanks! Great job. |
I guess I should probably make path-scurry just load fs and get stuff from the promises object rather than loading fs/promises. I don't remember why I did it that way, there might be a good reason 😅 |
This was working in 8.1.0
The second test case fails with 9.3.0.
Test re-written for 9.3.0:
The text was updated successfully, but these errors were encountered: