Closed jzecca closed 4 years ago
I had to work around this in one of my projects, and in my case it was tolerable to simply disable "modern mode" by passing stats: true
as an option to fast-glob
, since modern mode is not used when the node version is <10.10, or stats is enabled.
Another option would be to detect if mocha is running and conditionally disable modern mode, so only your tests are affected by the performance hit, not the code your users run. Something like this would help you determine if mocha is running:
// utils.js
export const IS_MOCHA = !!process.env.MOCHA_COLORS;
You could also try detect-mocha, but I haven't used it myself.
Thanks for the heads up, that's what I ended up doing. It's not ideal but it works :)
Native support would be awesome though.
I'm not sure to understand the workaround...
Is fast-glob
a dependency of fs
?
Then how do you pass stats: true
to fast-glob
if you don't have it installed as direct dependency in your project ?
It's indeed only a workaround for usage with fast-glob
.
If your code (or one of your dependencies) make use of the new Node 10.10+ fs.Dirent
class, you'll face the same error that I got, since mock-fs
doesn't support it yet.
@tschaub, maybe it's time to release a new version?
Fix from @mrmlnc published in mock-fs@4.11.0
.
Thanks for the fix and for the nudge, @mrmlnc.
fast-glob uses this option since v3 in its "modern mode" to make fewer calls to file system.
Using it in combination with mock-fs leads to the following error: