Skip to content
New issue

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

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

Already on GitHub? # to your account

Any plan to support readdir "withFileTypes" option? #272

Closed
jzecca opened this issue Jun 27, 2019 · 6 comments
Closed

Any plan to support readdir "withFileTypes" option? #272

jzecca opened this issue Jun 27, 2019 · 6 comments

Comments

@jzecca
Copy link

jzecca commented Jun 27, 2019

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:

Method not implemented

    at notImplemented (node_modules/mock-fs/lib/binding.js:140:9)
    at Object.<anonymous>.Binding.readdir (node_modules/mock-fs/lib/binding.js:890:5)
    at Object.<anonymous> (node_modules/mock-fs/lib/index.js:33:39)
    at readdirWithFileTypes (node_modules/@nodelib/fs.scandir/out/providers/async.js:15:17)
@tannerntannern
Copy link

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.

@jzecca
Copy link
Author

jzecca commented Jul 22, 2019

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.

@bleucitron
Copy link

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 ?

@jzecca
Copy link
Author

jzecca commented Jul 22, 2019

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.

@mrmlnc
Copy link
Contributor

mrmlnc commented Feb 24, 2020

@tschaub, maybe it's time to release a new version?

@tschaub
Copy link
Owner

tschaub commented Feb 24, 2020

Fix from @mrmlnc published in mock-fs@4.11.0.

Thanks for the fix and for the nudge, @mrmlnc.

@tschaub tschaub closed this as completed Feb 24, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants