Skip to content

Allow injecting custom process implementation for better testability #1247

@EggDice

Description

@EggDice

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

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 👍

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions