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

test_runner: support mock file system #55902

Open
axetroy opened this issue Nov 18, 2024 · 0 comments
Open

test_runner: support mock file system #55902

axetroy opened this issue Nov 18, 2024 · 0 comments
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. test_runner Issues and PRs related to the test runner subsystem.

Comments

@axetroy
Copy link

axetroy commented Nov 18, 2024

What is the problem this feature will solve?

The current test requires writing files to a real disk when reading and writing files related to the file system, which is very unsafe.

After all, the file may remain due to test case failure and other reasons.

What is the feature you are proposing to solve the problem?

Under the mock namespace, APIs are exposed to provide a mock file system.

mock.fileSystem.enable({ });

And provide some options

e.g.

Override the file that defined by defaults

mock.fileSystem.enable({
  files: {
    '/path/to/file': new Uint8Array([0])
  }
});

// it will read the virtual file system first if it does exist
// if not found, then read the read the real file system
fs.readFileSync('/path/to/file')

Override the whole file system

mock.fileSystem.enable({
  files: {
    '/path/to/file': new Uint8Array([0])
  },
  override: true // override the whole file system
});

// This file is exists in the real file system
// But not define in the vitual file system, so it should throw an error
fs.readFileSync('/etc/proc')

What alternatives have you considered?

mock-fs

@axetroy axetroy added the feature request Issues that request new features to be added to Node.js. label Nov 18, 2024
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Nov 18, 2024
@RedYetiDev RedYetiDev added fs Issues and PRs related to the fs subsystem / file system. test_runner Issues and PRs related to the test runner subsystem. labels Nov 18, 2024
@RedYetiDev RedYetiDev moved this from Awaiting Triage to Triaged in Node.js feature requests Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. test_runner Issues and PRs related to the test runner subsystem.
Projects
Development

No branches or pull requests

2 participants