Repository navigation
Expose internalBinding fs_dir #37746
Copy link
Copy link
Closed
Description
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.
node/lib/internal/bootstrap/loaders.js
Lines 73 to 107 in 7296bcb
| // 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
cjihrig commentedon 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 commentedon Mar 14, 2021
Thx for the information.
theoludwig commentedon Sep 11, 2022
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:fstoday, supporting all the methods offs?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_runnermodule.3cp commentedon 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).