-
-
Notifications
You must be signed in to change notification settings - Fork 144
Description
Problem
memfs reads directly from the global Node process object (e.g., cwd(), platform, getuid()), which makes it difficult to test code in a controlled environment without mutating globals.
Mocking process globally can be brittle and may leak between tests. There are also related issues caused by process-dependent behavior (e.g. #809).
This seems related to the broader effort to reduce dependency on Node process (#953), but currently there is no way to provide a custom implementation.
Proposal
Allow passing a custom process-like object to memfs, for example when creating an fs instance:
const { fs } = memfs(json, {
process: {
cwd: () => "/app",
platform: "win32",
getuid: () => 1000,
},
});or:
const fs = createFsFromVolume(vol, {
process: fakeProcess,
});Benefits
- avoids mutating global
process - improves test isolation and determinism
- allows simulating different platforms/environments
- aligns with Remove dependency on Node "process" module #953 (reducing direct dependency on Node globals)
Notes
This does not need to expose the full process API—only the parts memfs actually uses (e.g. cwd, platform, getuid) would be sufficient.
Happy to help with a PR if this direction makes sense 👍