Skip to content
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

Expose internalBinding fs_dir #37746

Closed
3cp opened this issue Mar 13, 2021 · 4 comments
Closed

Expose internalBinding fs_dir #37746

3cp opened this issue Mar 13, 2021 · 4 comments

Comments

@3cp
Copy link

3cp commented Mar 13, 2021

Is your feature request related to a problem? Please describe.
tschaub/mock-fs#319
mock-fs works through replacing Nodejs internal binding for fs.
We encountered a technical blocker when implementing fs.opendir in mock-fs because the new internalBinding fs_dir is not exposed in process.binding('fs_dir').

Describe the solution you'd like
We would like to suggest to expose fs_dir binding here, so that we could replace it at runtime in mock-fs.

// internalBindingAllowlist contains the name of internalBinding modules
// that are allowed for access via process.binding()... This is used
// to provide a transition path for modules that are being moved over to
// internalBinding.
const internalBindingAllowlist = new SafeSet([
'async_wrap',
'buffer',
'cares_wrap',
'config',
'constants',
'contextify',
'crypto',
'fs',
'fs_event_wrap',
'http_parser',
'icu',
'inspector',
'js_stream',
'natives',
'os',
'pipe_wrap',
'process_wrap',
'signal_wrap',
'spawn_sync',
'stream_wrap',
'tcp_wrap',
'tls_wrap',
'tty_wrap',
'udp_wrap',
'url',
'util',
'uv',
'v8',
'zlib',
]);

Describe alternatives you've considered
N/A

@cjihrig
Copy link
Contributor

cjihrig commented Mar 14, 2021

Just FYI - there is an initiative already underway to deprecate userland access to process.binding(). It seems unlikely that a new binding would be intentionally exposed.

@3cp
Copy link
Author

3cp commented Mar 14, 2021

Thx for the information.

@theoludwig
Copy link
Contributor

Could this issue be reconsidered, please? @3cp @cjihrig

If not, can someone tell me, how is tschaub/mock-fs#358 issue will be solved?
More generally, what is the best way to mock node:fs today, supporting all the methods of fs?
Is there a way that Node.js core can introduce a "mock" module, to easily mock such APIs for testing purposes, it might pair well with the new test_runner module.

@3cp
Copy link
Author

3cp commented Sep 11, 2022

The way mock-fs works is too fragile.
It's definitely best if nodejs is designed to facilitate testing (not just the fs module).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants